aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-13 07:38:23 -0700
committerJosé Valim <jose.valim@gmail.com>2012-03-13 07:38:23 -0700
commit21b69b233bda5870274c84ef8178c9ad9a47c390 (patch)
tree099b7bbf48a1f72442d9952159ba1d396d62f90d /railties/lib
parente7d55f734aae204115d0a04a2db774ac364c1312 (diff)
parent08db3d5af3ac6a36036083e80f7bb33e65cc9dd3 (diff)
downloadrails-21b69b233bda5870274c84ef8178c9ad9a47c390.tar.gz
rails-21b69b233bda5870274c84ef8178c9ad9a47c390.tar.bz2
rails-21b69b233bda5870274c84ef8178c9ad9a47c390.zip
Merge pull request #5397 from rafaelfranca/fix-scaffold
Do not use the attributes hash in the scaffold functional tests
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb21
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb4
2 files changed, 23 insertions, 2 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..4c07baae36 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,31 @@ 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 resource_attributes
+ key_value singular_table_name, "{ #{attributes_hash} }"
+ end
+
+ def attributes_hash
+ return if accessible_attributes.empty?
+
+ accessible_attributes.map do |a|
+ name = a.name
+ "#{name}: @#{singular_table_name}.#{name}"
+ end.sort.join(', ')
+ end
+
+ def accessible_attributes
+ attributes.reject(&:reference?)
+ 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..19894443d5 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
@@ -19,7 +19,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, <%= resource_attributes %>
end
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
@@ -36,7 +36,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}" %>, <%= resource_attributes %>
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end