diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:24:55 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:24:55 +0000 |
commit | 88a3343ed57c01ca358da8473d15fc4d2b4a5bff (patch) | |
tree | 3fe773bb113480f68eaea508d241cbaf90eebfde /railties/lib/rails_generator/generators/components | |
parent | 60f7a5cab73fab032fdb73d1a9a8061cf20031d2 (diff) | |
download | rails-88a3343ed57c01ca358da8473d15fc4d2b4a5bff.tar.gz rails-88a3343ed57c01ca358da8473d15fc4d2b4a5bff.tar.bz2 rails-88a3343ed57c01ca358da8473d15fc4d2b4a5bff.zip |
Backed out of routing merge.. investigating missing patches
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@616 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator/generators/components')
9 files changed, 32 insertions, 61 deletions
diff --git a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb index d537031fea..1f7e69d124 100644 --- a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb +++ b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb @@ -4,11 +4,8 @@ class ControllerGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" - # Controller, helper, views, and test directories. - m.directory File.join('app/controllers', class_path) - m.directory File.join('app/helpers', class_path) + # Views directory even if there are no actions. m.directory File.join('app/views', class_path, file_name) - m.directory File.join('test/functional', class_path) # Controller class, functional test, and helper class. m.template 'controller.rb', diff --git a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb index 76e2b33ba5..c975cb3ce3 100644 --- a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb @@ -7,8 +7,7 @@ class <%= class_name %>Controller; def rescue_action(e) raise e end; end class <%= class_name %>ControllerTest < Test::Unit::TestCase def setup @controller = <%= class_name %>Controller.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new end # Replace this with your real tests. diff --git a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb index d8ddb43644..81d4599f7f 100644 --- a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb +++ b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb @@ -4,28 +4,21 @@ class MailerGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions class_name, "#{class_name}Test" - # Mailer, view, test, and fixture directories. - m.directory File.join('app/models', class_path) - m.directory File.join('app/views', class_path, file_name) - m.directory File.join('test/unit', class_path) - m.directory File.join('test/fixtures', class_path, table_name) - # Mailer class and unit test. - m.template "mailer.rb", File.join('app/models', - class_path, - "#{file_name}.rb") - m.template "unit_test.rb", File.join('test/unit', - class_path, - "#{file_name}_test.rb") + m.template "mailer.rb", "app/models/#{file_name}.rb" + m.template "unit_test.rb", "test/unit/#{file_name}_test.rb" + + # Views and fixtures directories. + m.directory "app/views/#{file_name}" + m.directory "test/fixtures/#{table_name}" # View template and fixture for each action. actions.each do |action| m.template "view.rhtml", - File.join('app/views', class_path, file_name, "#{action}.rhtml"), + "app/views/#{file_name}/#{action}.rhtml", :assigns => { :action => action } m.template "fixture.rhtml", "test/fixtures/#{table_name}/#{action}", - File.join('test/fixtures', class_path, table_name, action), :assigns => { :action => action } end end diff --git a/railties/lib/rails_generator/generators/components/model/model_generator.rb b/railties/lib/rails_generator/generators/components/model/model_generator.rb index c3407ca283..32577d08a3 100644 --- a/railties/lib/rails_generator/generators/components/model/model_generator.rb +++ b/railties/lib/rails_generator/generators/components/model/model_generator.rb @@ -4,11 +4,6 @@ class ModelGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions class_name, "#{class_name}Test" - # Model, test, and fixture directories. - m.directory File.join('app/models', class_path) - m.directory File.join('test/unit', class_path) - m.directory File.join('test/fixtures', class_path) - # Model class, unit test, and fixtures. m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") diff --git a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml index 6285727968..fc3185dc46 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml +++ b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml @@ -1,8 +1,10 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html # Set the $base_id variable in the setup method of your tests. # It's used to ensure that ids don't clash in some databases. +<%% $base_id ||= 100000 %> + first_<%= singular_name %>: - id: 1 + id: <%%= $base_id %> another_<%= singular_name %>: - id: 2 + id: <%%= $base_id + 1 %> diff --git a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb index e8714b589a..db0fbf5d33 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb +++ b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb @@ -4,11 +4,11 @@ class <%= class_name %>Test < Test::Unit::TestCase fixtures :<%= table_name %> def setup - @<%= singular_name %> = <%= class_name %>.find(1) + $base_id = 1000001 end # Replace this with your real tests. def test_truth - assert_kind_of <%= class_name %>, @<%= singular_name %> + assert true end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb index abf9d79ffe..4445995b46 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -41,12 +41,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase super @controller_name = args.shift || @name.pluralize base_name, @controller_class_path, @controller_class_nesting = extract_modules(@controller_name) - @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) - if @controller_class_nesting.empty? - @controller_class_name = @controller_class_name_without_nesting - else - @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}" - end + @controller_class_name, @controller_singular_name, @controller_plural_name = inflect_names(base_name) end def manifest @@ -57,12 +52,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase # Check for class naming collisions. m.class_collisions "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper" - # Controller, helper, views, and test directories. - m.directory File.join('app/controllers', controller_class_path) - m.directory File.join('app/helpers', controller_class_path) + # Views directory. m.directory File.join('app/views', controller_class_path, controller_file_name) - m.directory File.join('test/functional', controller_class_path) - # Controller class, functional test, helper, and views. m.template 'controller.rb', @@ -88,8 +79,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase scaffold_views.each do |action| m.template "view_#{action}.rhtml", File.join('app/views', - controller_class_path, - controller_file_name, + controller_class_path, controller_file_name, "#{action}.rhtml"), :assigns => { :action => action } end @@ -113,8 +103,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase unscaffolded_actions.each do |action| m.template "controller:view.rhtml", File.join('app/views', - controller_class_path, - controller_file_name, + controller_class_path, controller_file_name, "#{action}.rhtml"), :assigns => { :action => action } end @@ -164,13 +153,9 @@ class ScaffoldGenerator < Rails::Generator::NamedBase end def model_instance - base = class_nesting.split('::').inject(Object) do |base, nested| - break base.const_get(nested) if base.const_defined?(nested) - base.const_set(nested, Module.new) - end - unless base.const_defined?(@class_name_without_nesting) - base.const_set(@class_name_without_nesting, Class.new(ActiveRecord::Base)) + unless Object.const_defined?(class_name) + Object.const_set(class_name, Class.new(ActiveRecord::Base)) end - class_name.constantize.new + Object.const_get(class_name).new end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb index 32185fb715..ea9c8e4e94 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb @@ -8,9 +8,9 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase fixtures :<%= table_name %> def setup + $base_id = 1000001 @controller = <%= controller_class_name %>Controller.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new end <% for action in unscaffolded_actions -%> @@ -34,7 +34,7 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase end def test_show<%= suffix %> - process :show<%= suffix %>, 'id' => 1 + process :show<%= suffix %>, 'id' => $base_id assert_rendered_file 'show' assert_template_has '<%= singular_name %>' assert_valid_record '<%= singular_name %>' @@ -56,25 +56,25 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase end def test_edit<%= suffix %> - process :edit<%= suffix %>, 'id' => 1 + process :edit<%= suffix %>, 'id' => $base_id assert_rendered_file 'edit<%= suffix %>' assert_template_has '<%= singular_name %>' assert_valid_record '<%= singular_name %>' end def test_update<%= suffix %> - process :update<%= suffix %>, '<%= singular_name %>' => { 'id' => 1 } - assert_redirected_to :action => 'show<%= suffix %>', :id => 1 + process :update<%= suffix %>, '<%= singular_name %>' => { 'id' => $base_id } + assert_redirected_to :action => 'show<%= suffix %>', :id => $base_id end def test_destroy<%= suffix %> - assert_not_nil <%= class_name %>.find(1) + assert_not_nil <%= class_name %>.find($base_id) - process :destroy, 'id' => 1 + process :destroy, 'id' => $base_id assert_redirected_to :action => 'list<%= suffix %>' assert_raise(ActiveRecord::RecordNotFound) { - <%= singular_name %> = <%= class_name %>.find(1) + <%= singular_name %> = <%= class_name %>.find($base_id) } end end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml b/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml index e0d56d1122..068fd67472 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +++ b/railties/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml @@ -10,7 +10,7 @@ <%% for <%= singular_name %> in @<%= plural_name %> %> <tr> <%% for column in <%= class_name %>.content_columns %> - <td><%%=h <%= singular_name %>.send(column.name) %></td> + <td><%%=h <%= singular_name %>[column.name] %></td> <%% end %> <td><%%= link_to 'Show', :action => 'show<%= suffix %>', :id => <%= singular_name %>.id %></td> <td><%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => <%= singular_name %>.id %></td> |