diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-02 13:23:20 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-02 13:23:20 -0800 |
commit | e5ee5a9d24f897bb8999bc6d3f47edc54917db99 (patch) | |
tree | 707c21d3cce9e0a6250ab8d00bf39428942e841d /railties/lib/rails/generators/test_unit/model | |
parent | 2aa70bd61a5c4a55dffa79fb6da9b8c8d6dd8b69 (diff) | |
parent | 204109eac9708d615bd88d60b0b7e5d265941423 (diff) | |
download | rails-e5ee5a9d24f897bb8999bc6d3f47edc54917db99.tar.gz rails-e5ee5a9d24f897bb8999bc6d3f47edc54917db99.tar.bz2 rails-e5ee5a9d24f897bb8999bc6d3f47edc54917db99.zip |
Merge branch '3-2-stable' into 3-2-secmerge
* 3-2-stable:
fix block.arity raise nil error when not given a block to "content_tag_for"
removes the Ajax on Rails early draft
Revert "Merge pull request #8665 from senny/8661_should_not_append_charset_if_already_present"
backport #8662, charset should not be appended for `head` responses
Revert "Fix `validates_presence_of` with `:allow_nil` or `:allow_blank` options."
Fix `validates_presence_of` with `:allow_nil` or `:allow_blank` options.
backport #8616, quote column names in generated fixture files
Diffstat (limited to 'railties/lib/rails/generators/test_unit/model')
-rw-r--r-- | railties/lib/rails/generators/test_unit/model/model_generator.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/generators/test_unit/model/templates/fixtures.yml | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index c1dd535dd3..9749a6b133 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -3,6 +3,9 @@ require 'rails/generators/test_unit' module TestUnit module Generators class ModelGenerator < Base + + RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null) + argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" class_option :fixture, :type => :boolean @@ -19,6 +22,15 @@ module TestUnit template 'fixtures.yml', File.join('test/fixtures', class_path, "#{plural_file_name}.yml") end end + + private + def yaml_key_value(key, value) + if RESERVED_YAML_KEYWORDS.include?(key.downcase) + "'#{key}': #{value}" + else + "#{key}: #{value}" + end + end end end end 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 5c8780aa64..2c33766418 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -3,12 +3,12 @@ <% unless attributes.empty? -%> one: <% attributes.each do |attribute| -%> - <%= attribute.name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.name, attribute.default) %> <% end -%> two: <% attributes.each do |attribute| -%> - <%= attribute.name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.name, attribute.default) %> <% end -%> <% else -%> # This model initially had no columns defined. If you add columns to the |