diff options
Diffstat (limited to 'railties/lib/rails_generator/generators/components/scaffold')
3 files changed, 17 insertions, 32 deletions
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> |