diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-03-12 19:41:17 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-03-13 11:23:03 -0300 |
commit | 5bed0e5cc0ae85975352808022201cf7431684e5 (patch) | |
tree | 26525b07c000da134cdc19da993a23f211ba0729 /railties | |
parent | d2ac18a822ff75f12a0f716dca6c74b411f9f7c1 (diff) | |
download | rails-5bed0e5cc0ae85975352808022201cf7431684e5.tar.gz rails-5bed0e5cc0ae85975352808022201cf7431684e5.tar.bz2 rails-5bed0e5cc0ae85975352808022201cf7431684e5.zip |
Do not use the attributes hash in the scaffold functional tests
Diffstat (limited to 'railties')
4 files changed, 20 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index f7e907a017..760917896f 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -8,10 +8,18 @@ module TestUnit check_class_collision :suffix => "ControllerTest" + argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + def create_test_files template 'functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb") end + + private + + def accessible_attributes + attributes.reject(&:reference?).map {|a| "\"#{a.name}\"" }.sort.join(', ') + end end end end diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb index 9ec2e34545..e9fe27e504 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb @@ -4,6 +4,7 @@ require 'test_helper' class <%= controller_class_name %>ControllerTest < ActionController::TestCase setup do @<%= singular_table_name %> = <%= table_name %>(:one) + @valid_attributes = @<%= singular_table_name %>.attributes.slice(<%= accessible_attributes %>) end test "should get index" do @@ -19,7 +20,7 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase test "should create <%= singular_table_name %>" do assert_difference('<%= class_name %>.count') do - post :create, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %> + post :create, <%= key_value singular_table_name, "@valid_attributes" %> end assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>)) @@ -36,7 +37,7 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase end test "should update <%= singular_table_name %>" do - put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %> + put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= key_value singular_table_name, "@valid_attributes" %> assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>)) end diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 65b30b9fbd..f2406a149b 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -75,6 +75,9 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_file "test/functional/users_controller_test.rb" do |content| assert_match(/class UsersControllerTest < ActionController::TestCase/, content) assert_match(/test "should get index"/, content) + assert_match(/@valid_attributes = @user\.attributes\.slice\("age", "name"\)/, content) + assert_match(/post :create, user: @valid_attributes/, content) + assert_match(/put :update, id: @user, user: @valid_attributes/, content) end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 2db8090621..d983ae8b49 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -62,8 +62,12 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end - assert_file "test/functional/product_lines_controller_test.rb", - /class ProductLinesControllerTest < ActionController::TestCase/ + assert_file "test/functional/product_lines_controller_test.rb" do |test| + assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test) + assert_match(/@valid_attributes = @product_line\.attributes\.slice\("title"\)/, test) + assert_match(/post :create, product_line: @valid_attributes/, test) + assert_match(/put :update, id: @product_line, product_line: @valid_attributes/, test) + end # Views %w( |