diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-09 15:20:32 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-10 00:01:41 -0300 |
commit | b05b77be9caf2617f35d93786d9b40c17e07bf64 (patch) | |
tree | fa5239f88c3f008c0a35ec649e8d2925038fd679 /railties/lib/rails/generators/test_unit | |
parent | 4a487f94b9812964e644716f301ab287dea8cddc (diff) | |
download | rails-b05b77be9caf2617f35d93786d9b40c17e07bf64.tar.gz rails-b05b77be9caf2617f35d93786d9b40c17e07bf64.tar.bz2 rails-b05b77be9caf2617f35d93786d9b40c17e07bf64.zip |
Deal with polymorphic attributes correctly in the generators
Diffstat (limited to 'railties/lib/rails/generators/test_unit')
-rw-r--r-- | railties/lib/rails/generators/test_unit/model/templates/fixtures.yml | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb | 16 |
2 files changed, 13 insertions, 5 deletions
diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index 71f4f99d02..7f29932ceb 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -4,11 +4,13 @@ one: <% attributes.each do |attribute| -%> <%= attribute.reference? ? "#{attribute.name}_id" : attribute.name %>: <%= attribute.default %> + <%= "#{attribute.name}_type: #{attribute.human_name}" if attribute.polymorphic? %> <% end -%> two: <% attributes.each do |attribute| -%> <%= attribute.reference? ? "#{attribute.name}_id" : attribute.name %>: <%= attribute.default %> + <%= "#{attribute.name}_type: #{attribute.human_name}" if attribute.polymorphic? %> <% end -%> <% else -%> # This model initially had no columns defined. If you add columns to the 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 8939813304..08bf50dfe2 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -20,11 +20,17 @@ module TestUnit # :nodoc: def attributes_hash return if attributes.empty? - attributes.map do |a| - name = a.name - name = "#{name}_id" if a.reference? - "#{name}: @#{singular_table_name}.#{name}" - end.sort.join(', ') + hash_values = [] + attributes.each do |a| + hash_values << hash_value(a.reference? ? "#{a.name}_id" : a.name) + hash_values << hash_value("#{a.name}_type") if a.polymorphic? + end + + hash_values.sort.join(', ') + end + + def hash_value(name) + "#{name}: @#{singular_table_name}.#{name}" end end end |