aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-06 18:00:41 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-10 00:01:40 -0300
commit3d8fcdd3bf21482e3e297a78bfdf3d02ec71eda4 (patch)
tree81b36773b2fa3caefff2474abbe274ba30b29c6c /railties
parentb4b8c26b6e3568525b974889e60bfd2a025f0114 (diff)
downloadrails-3d8fcdd3bf21482e3e297a78bfdf3d02ec71eda4.tar.gz
rails-3d8fcdd3bf21482e3e297a78bfdf3d02ec71eda4.tar.bz2
rails-3d8fcdd3bf21482e3e297a78bfdf3d02ec71eda4.zip
Put the reference and belongs_to attributes in the scaffold tests.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb9
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb6
-rw-r--r--railties/test/generators/scaffold_generator_test.rb6
3 files changed, 9 insertions, 12 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 3b4fec2e83..8939813304 100644
--- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
@@ -18,17 +18,14 @@ module TestUnit # :nodoc:
private
def attributes_hash
- return if accessible_attributes.empty?
+ return if attributes.empty?
- accessible_attributes.map do |a|
+ attributes.map do |a|
name = a.name
+ name = "#{name}_id" if a.reference?
"#{name}: @#{singular_table_name}.#{name}"
end.sort.join(', ')
end
-
- def accessible_attributes
- attributes.reject(&:reference?)
- end
end
end
end
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index f467043cd0..0b80e54969 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -86,13 +86,13 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
end
def test_functional_tests
- run_generator
+ run_generator ["User", "name:string", "age:integer", "organization:references"]
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 \}/, content)
+ assert_match(/put :update, id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id \}/, 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"