[24568] users/jberry/mpwa
source_changes at macosforge.org
source_changes at macosforge.org
Sat Apr 28 07:59:59 PDT 2007
Revision: 24568
http://trac.macosforge.org/projects/macports/changeset/24568
Author: jberry at macports.org
Date: 2007-04-28 07:59:58 -0700 (Sat, 28 Apr 2007)
Log Message:
-----------
mpwa: add variants to portpkg
Modified Paths:
--------------
users/jberry/mpwa/app/models/port_pkg.rb
users/jberry/mpwa/doc/schema-thoughts.sql
Added Paths:
-----------
users/jberry/mpwa/app/controllers/variant_controller.rb
users/jberry/mpwa/app/helpers/variant_helper.rb
users/jberry/mpwa/app/models/variant.rb
users/jberry/mpwa/app/views/layouts/variant.rhtml
users/jberry/mpwa/app/views/variant/
users/jberry/mpwa/app/views/variant/_form.rhtml
users/jberry/mpwa/app/views/variant/edit.rhtml
users/jberry/mpwa/app/views/variant/list.rhtml
users/jberry/mpwa/app/views/variant/new.rhtml
users/jberry/mpwa/app/views/variant/show.rhtml
users/jberry/mpwa/test/fixtures/variants.yml
users/jberry/mpwa/test/functional/variant_controller_test.rb
users/jberry/mpwa/test/unit/variant_test.rb
Added: users/jberry/mpwa/app/controllers/variant_controller.rb
===================================================================
--- users/jberry/mpwa/app/controllers/variant_controller.rb (rev 0)
+++ users/jberry/mpwa/app/controllers/variant_controller.rb 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,51 @@
+class VariantController < ApplicationController
+ def index
+ list
+ render :action => 'list'
+ end
+
+ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+ verify :method => :post, :only => [ :destroy, :create, :update ],
+ :redirect_to => { :action => :list }
+
+ def list
+ @variant_pages, @variants = paginate :variants, :per_page => 10
+ end
+
+ def show
+ @variant = Variant.find(params[:id])
+ end
+
+ def new
+ @variant = Variant.new
+ end
+
+ def create
+ @variant = Variant.new(params[:variant])
+ if @variant.save
+ flash[:notice] = 'Variant was successfully created.'
+ redirect_to :action => 'list'
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @variant = Variant.find(params[:id])
+ end
+
+ def update
+ @variant = Variant.find(params[:id])
+ if @variant.update_attributes(params[:variant])
+ flash[:notice] = 'Variant was successfully updated.'
+ redirect_to :action => 'show', :id => @variant
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ Variant.find(params[:id]).destroy
+ redirect_to :action => 'list'
+ end
+end
Added: users/jberry/mpwa/app/helpers/variant_helper.rb
===================================================================
--- users/jberry/mpwa/app/helpers/variant_helper.rb (rev 0)
+++ users/jberry/mpwa/app/helpers/variant_helper.rb 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,2 @@
+module VariantHelper
+end
Modified: users/jberry/mpwa/app/models/port_pkg.rb
===================================================================
--- users/jberry/mpwa/app/models/port_pkg.rb 2007-04-28 14:41:06 UTC (rev 24567)
+++ users/jberry/mpwa/app/models/port_pkg.rb 2007-04-28 14:59:58 UTC (rev 24568)
@@ -1,10 +1,12 @@
require 'time'
require 'temp_directories'
+require 'rexml/document'
+
+require 'mpwa-conf'
require 'port'
require 'port_pkg_file'
require 'person'
-require 'mpwa-conf'
-require 'rexml/document'
+require 'variant'
PortPkgMeta = Struct.new("PortPkgMeta",
:submitter_email, :submitter_name, :submitter_notes,
@@ -16,6 +18,7 @@
belongs_to :port
belongs_to :submitter, :class_name => 'Person', :foreign_key => 'submitter_id'
has_many :files, :class_name => 'PortPkgFile'
+ has_many :variants
has_and_belongs_to_many :tags
def PortPkg.create_from_file(file)
@@ -94,6 +97,9 @@
# Map to, and/or create, a port
self.port = Port.ensure_port(meta.name, meta)
+ # Add the variants
+ meta.variants.each { |v| self.variants << Variant.new(:name => v) }
+
# Tag with categories
meta.categories.each { |c| self.add_tag(c) }
Added: users/jberry/mpwa/app/models/variant.rb
===================================================================
--- users/jberry/mpwa/app/models/variant.rb (rev 0)
+++ users/jberry/mpwa/app/models/variant.rb 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,2 @@
+class Variant < ActiveRecord::Base
+end
Added: users/jberry/mpwa/app/views/layouts/variant.rhtml
===================================================================
--- users/jberry/mpwa/app/views/layouts/variant.rhtml (rev 0)
+++ users/jberry/mpwa/app/views/layouts/variant.rhtml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Variant: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
Added: users/jberry/mpwa/app/views/variant/_form.rhtml
===================================================================
--- users/jberry/mpwa/app/views/variant/_form.rhtml (rev 0)
+++ users/jberry/mpwa/app/views/variant/_form.rhtml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,10 @@
+<%= error_messages_for 'variant' %>
+
+<!--[form:variant]-->
+<p><label for="variant_name">Name</label><br/>
+<%= text_field 'variant', 'name' %></p>
+
+<p><label for="variant_description">Description</label><br/>
+<%= text_area 'variant', 'description' %></p>
+<!--[eoform:variant]-->
+
Added: users/jberry/mpwa/app/views/variant/edit.rhtml
===================================================================
--- users/jberry/mpwa/app/views/variant/edit.rhtml (rev 0)
+++ users/jberry/mpwa/app/views/variant/edit.rhtml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,9 @@
+<h1>Editing variant</h1>
+
+<% form_tag :action => 'update', :id => @variant do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag 'Edit' %>
+<% end %>
+
+<%= link_to 'Show', :action => 'show', :id => @variant %> |
+<%= link_to 'Back', :action => 'list' %>
Added: users/jberry/mpwa/app/views/variant/list.rhtml
===================================================================
--- users/jberry/mpwa/app/views/variant/list.rhtml (rev 0)
+++ users/jberry/mpwa/app/views/variant/list.rhtml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,27 @@
+<h1>Listing variants</h1>
+
+<table>
+ <tr>
+ <% for column in Variant.content_columns %>
+ <th><%= column.human_name %></th>
+ <% end %>
+ </tr>
+
+<% for variant in @variants %>
+ <tr>
+ <% for column in Variant.content_columns %>
+ <td><%=h variant.send(column.name) %></td>
+ <% end %>
+ <td><%= link_to 'Show', :action => 'show', :id => variant %></td>
+ <td><%= link_to 'Edit', :action => 'edit', :id => variant %></td>
+ <td><%= link_to 'Destroy', { :action => 'destroy', :id => variant }, :confirm => 'Are you sure?', :method => :post %></td>
+ </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @variant_pages.current.previous } if @variant_pages.current.previous %>
+<%= link_to 'Next page', { :page => @variant_pages.current.next } if @variant_pages.current.next %>
+
+<br />
+
+<%= link_to 'New variant', :action => 'new' %>
Added: users/jberry/mpwa/app/views/variant/new.rhtml
===================================================================
--- users/jberry/mpwa/app/views/variant/new.rhtml (rev 0)
+++ users/jberry/mpwa/app/views/variant/new.rhtml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,8 @@
+<h1>New variant</h1>
+
+<% form_tag :action => 'create' do %>
+ <%= render :partial => 'form' %>
+ <%= submit_tag "Create" %>
+<% end %>
+
+<%= link_to 'Back', :action => 'list' %>
Added: users/jberry/mpwa/app/views/variant/show.rhtml
===================================================================
--- users/jberry/mpwa/app/views/variant/show.rhtml (rev 0)
+++ users/jberry/mpwa/app/views/variant/show.rhtml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,8 @@
+<% for column in Variant.content_columns %>
+<p>
+ <b><%= column.human_name %>:</b> <%=h @variant.send(column.name) %>
+</p>
+<% end %>
+
+<%= link_to 'Edit', :action => 'edit', :id => @variant %> |
+<%= link_to 'Back', :action => 'list' %>
Modified: users/jberry/mpwa/doc/schema-thoughts.sql
===================================================================
--- users/jberry/mpwa/doc/schema-thoughts.sql 2007-04-28 14:41:06 UTC (rev 24567)
+++ users/jberry/mpwa/doc/schema-thoughts.sql 2007-04-28 14:59:58 UTC (rev 24568)
@@ -96,6 +96,20 @@
tag_id bigint not null
);
+-- Variant available to a PortPkg
+drop table if exists Variants;
+create table Variants (
+ id bigint not null primary key auto_increment,
+ port_pkg_id bigint not null,
+
+ name varchar(63),
+ description text
+
+ -- many-many association for dependencies through Dependencies_Variants
+
+ -- conflicts expr?
+);
+
-- A dependency onto onther port
drop table if exists Dependencies;
create table Dependencies (
@@ -114,20 +128,6 @@
dependency_id bigint not null
);
--- Variant available to a PortPkg
-drop table if exists Variants;
-create table Variants (
- id bigint not null primary key auto_increment,
- port_pkg_id bigint not null,
-
- name varchar(63),
- description text
-
- -- many-many association for dependencies through Dependencies_Variants
-
- -- conflicts expr?
-);
-
-- many-one relationship from Variant to Dependency
drop table if exists Dependencies_Variants;
create table Dependencies_Variants (
Added: users/jberry/mpwa/test/fixtures/variants.yml
===================================================================
--- users/jberry/mpwa/test/fixtures/variants.yml (rev 0)
+++ users/jberry/mpwa/test/fixtures/variants.yml 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
Added: users/jberry/mpwa/test/functional/variant_controller_test.rb
===================================================================
--- users/jberry/mpwa/test/functional/variant_controller_test.rb (rev 0)
+++ users/jberry/mpwa/test/functional/variant_controller_test.rb 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'variant_controller'
+
+# Re-raise errors caught by the controller.
+class VariantController; def rescue_action(e) raise e end; end
+
+class VariantControllerTest < Test::Unit::TestCase
+ fixtures :variants
+
+ def setup
+ @controller = VariantController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @first_id = variants(:first).id
+ end
+
+ def test_index
+ get :index
+ assert_response :success
+ assert_template 'list'
+ end
+
+ def test_list
+ get :list
+
+ assert_response :success
+ assert_template 'list'
+
+ assert_not_nil assigns(:variants)
+ end
+
+ def test_show
+ get :show, :id => @first_id
+
+ assert_response :success
+ assert_template 'show'
+
+ assert_not_nil assigns(:variant)
+ assert assigns(:variant).valid?
+ end
+
+ def test_new
+ get :new
+
+ assert_response :success
+ assert_template 'new'
+
+ assert_not_nil assigns(:variant)
+ end
+
+ def test_create
+ num_variants = Variant.count
+
+ post :create, :variant => {}
+
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_equal num_variants + 1, Variant.count
+ end
+
+ def test_edit
+ get :edit, :id => @first_id
+
+ assert_response :success
+ assert_template 'edit'
+
+ assert_not_nil assigns(:variant)
+ assert assigns(:variant).valid?
+ end
+
+ def test_update
+ post :update, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'show', :id => @first_id
+ end
+
+ def test_destroy
+ assert_nothing_raised {
+ Variant.find(@first_id)
+ }
+
+ post :destroy, :id => @first_id
+ assert_response :redirect
+ assert_redirected_to :action => 'list'
+
+ assert_raise(ActiveRecord::RecordNotFound) {
+ Variant.find(@first_id)
+ }
+ end
+end
Added: users/jberry/mpwa/test/unit/variant_test.rb
===================================================================
--- users/jberry/mpwa/test/unit/variant_test.rb (rev 0)
+++ users/jberry/mpwa/test/unit/variant_test.rb 2007-04-28 14:59:58 UTC (rev 24568)
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class VariantTest < Test::Unit::TestCase
+ fixtures :variants
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070428/b8221400/attachment.html
More information about the macports-changes
mailing list