diff options
author | Yves Senn <yves.senn@gmail.com> | 2012-12-26 15:16:09 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2012-12-26 16:17:47 +0100 |
commit | edae4777ad6308bb4169c40368a24b62bb542d32 (patch) | |
tree | 1c6e6d08a131629ce931c3b3682fd18db0642b19 /railties/lib/rails/generators | |
parent | 95fa0e69de373e741d3797617950c0e2ed76f950 (diff) | |
download | rails-edae4777ad6308bb4169c40368a24b62bb542d32.tar.gz rails-edae4777ad6308bb4169c40368a24b62bb542d32.tar.bz2 rails-edae4777ad6308bb4169c40368a24b62bb542d32.zip |
quote column names in generated fixture files
Diffstat (limited to 'railties/lib/rails/generators')
-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 | 8 |
2 files changed, 16 insertions, 4 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 2801749ffe..2826a3ffa1 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 # :nodoc: module Generators # :nodoc: class ModelGenerator < Base # :nodoc: + + 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 # :nodoc: 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 7625ff975c..c9d505c84a 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -3,17 +3,17 @@ <% unless attributes.empty? -%> one: <% attributes.each do |attribute| -%> - <%= attribute.column_name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> - <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> two: <% attributes.each do |attribute| -%> - <%= attribute.column_name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> - <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> <% else -%> |