diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-10 00:36:31 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-10 00:36:31 -0300 |
commit | 9e42cd86869dcc158b0321b2d2dfcc185a7d0282 (patch) | |
tree | a8d67fd8202716b35c3552c21db17ecc356f2ffe /railties/test | |
parent | 05e6123653b7ceb98960403ec40788b3f34e3efd (diff) | |
parent | 190f638d398edf70fef0c32a389ed84a449bccb8 (diff) | |
download | rails-9e42cd86869dcc158b0321b2d2dfcc185a7d0282.tar.gz rails-9e42cd86869dcc158b0321b2d2dfcc185a7d0282.tar.bz2 rails-9e42cd86869dcc158b0321b2d2dfcc185a7d0282.zip |
Merge branch 'scaffold_fixes'
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/rake_test.rb | 10 | ||||
-rw-r--r-- | railties/test/generators/generated_attribute_test.rb | 11 | ||||
-rw-r--r-- | railties/test/generators/model_generator_test.rb | 10 | ||||
-rw-r--r-- | railties/test/generators/scaffold_controller_generator_test.rb | 33 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 6 |
5 files changed, 62 insertions, 8 deletions
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index f2234ab111..a8275a2e76 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -195,6 +195,16 @@ module ApplicationTests assert_no_match(/Errors running/, output) end + def test_scaffold_with_references_columns_tests_pass_by_default + output = Dir.chdir(app_path) do + `rails generate scaffold LineItems product:references cart:belongs_to; + bundle exec rake db:migrate db:test:clone test` + end + + assert_match(/7 tests, 13 assertions, 0 failures, 0 errors/, output) + assert_no_match(/Errors running/, output) + end + def test_db_test_clone_when_using_sql_format add_to_config "config.active_record.schema_format = :sql" output = Dir.chdir(app_path) do diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index 6ab1cd58c7..d08e650b62 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -117,13 +117,13 @@ class GeneratedAttributeTest < Rails::Generators::TestCase assert create_generated_attribute("#{attribute_type}{polymorphic}").polymorphic? end end - + def test_polymorphic_reference_is_false %w(foo bar baz).each do |attribute_type| assert !create_generated_attribute("#{attribute_type}{polymorphic}").polymorphic? end end - + def test_blank_type_defaults_to_string_raises_exception assert_equal :string, create_generated_attribute(nil, 'title').type assert_equal :string, create_generated_attribute("", 'title').type @@ -132,6 +132,13 @@ class GeneratedAttributeTest < Rails::Generators::TestCase def test_handles_index_names_for_references assert_equal "post", create_generated_attribute('string', 'post').index_name assert_equal "post_id", create_generated_attribute('references', 'post').index_name + assert_equal "post_id", create_generated_attribute('belongs_to', 'post').index_name assert_equal ["post_id", "post_type"], create_generated_attribute('references{polymorphic}', 'post').index_name end + + def test_handles_index_names_for_references + assert_equal "post", create_generated_attribute('string', 'post').column_name + assert_equal "post_id", create_generated_attribute('references', 'post').column_name + assert_equal "post_id", create_generated_attribute('belongs_to', 'post').column_name + end end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 0c7ff0ebe7..0fbaf0c9bb 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -273,6 +273,16 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/ end + def test_fixtures_use_the_references_ids + run_generator ["LineItem", "product:references", "cart:belongs_to"] + assert_file "test/fixtures/line_items.yml", /product_id: /, /cart_id: / + end + + def test_fixtures_use_the_references_ids_and_type + run_generator ["LineItem", "product:references{polymorphic}", "cart:belongs_to"] + assert_file "test/fixtures/line_items.yml", /product_id: /, /product_type: Product/, /cart_id: / + end + def test_fixture_is_skipped run_generator ["account", "--skip-fixture"] assert_no_file "test/fixtures/accounts.yml" diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 2a88dac635..57a12d0457 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -52,6 +52,33 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end end + def test_dont_use_require_or_permit_if_there_are_no_attributes + run_generator ["User"] + + assert_file "app/controllers/users_controller.rb" do |content| + assert_match(/def user_params/, content) + assert_match(/params\[:user\]/, content) + end + end + + def test_controller_permit_references_attributes + run_generator ["LineItem", "product:references", "cart:belongs_to"] + + assert_file "app/controllers/line_items_controller.rb" do |content| + assert_match(/def line_item_params/, content) + assert_match(/params\.require\(:line_item\)\.permit\(:product_id, :cart_id\)/, content) + end + end + + def test_controller_permit_polymorphic_references_attributes + run_generator ["LineItem", "product:references{polymorphic}"] + + assert_file "app/controllers/line_items_controller.rb" do |content| + assert_match(/def line_item_params/, content) + assert_match(/params\.require\(:line_item\)\.permit\(:product_id, :product_type\)/, content) + end + end + def test_helper_are_invoked_with_a_pluralized_name run_generator assert_file "app/helpers/users_helper.rb", /module UsersHelper/ @@ -68,13 +95,13 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end def test_functional_tests - run_generator + run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"] assert_file "test/controllers/users_controller_test.rb" do |content| assert_match(/class UsersControllerTest < ActionController::TestCase/, content) assert_match(/test "should get index"/, content) - assert_match(/post :create, user: \{ age: @user.age, name: @user.name \}/, content) - assert_match(/put :update, id: @user, user: \{ age: @user.age, name: @user.name \}/, content) + assert_match(/post :create, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \}/, content) + assert_match(/put :update, id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \}/, content) end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 7fcc0a7409..de62fdb1ea 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -60,8 +60,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/controllers/product_lines_controller_test.rb" do |test| assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test) - assert_match(/post :create, product_line: \{ title: @product_line.title \}/, test) - assert_match(/put :update, id: @product_line, product_line: \{ title: @product_line.title \}/, test) + assert_match(/post :create, product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \}/, test) + assert_match(/put :update, id: @product_line, product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \}/, test) end # Views @@ -199,7 +199,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase run_generator [ "admin/role" ], :behavior => :revoke # Model - assert_file "app/models/admin.rb" # ( should not be remove ) + assert_file "app/models/admin.rb" # ( should not be remove ) assert_no_file "app/models/admin/role.rb" assert_no_file "test/models/admin/role_test.rb" assert_no_file "test/fixtures/admin/roles.yml" |