diff options
author | Jeff Kreeftmeijer <jeff@kreeftmeijer.nl> | 2010-05-17 22:43:06 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-10 20:04:49 +0200 |
commit | d93b45e8d32e3c4917c6b16bcea3a694800d2c49 (patch) | |
tree | 2a1a5daa798d838f7c9c34638a6e511a4436dfae /railties/lib/rails | |
parent | 566967eaf3a66ff6a7e31f43894e21a1940ba9e7 (diff) | |
download | rails-d93b45e8d32e3c4917c6b16bcea3a694800d2c49.tar.gz rails-d93b45e8d32e3c4917c6b16bcea3a694800d2c49.tar.bz2 rails-d93b45e8d32e3c4917c6b16bcea3a694800d2c49.zip |
Rails::Generators::GeneratedAttribute: tests, cleanups and a bugfix [#4631 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/generators/test_case.rb | 30 |
2 files changed, 24 insertions, 9 deletions
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index f01934f946..3b9fff2f4a 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -1,3 +1,5 @@ +require 'active_support/time' + module Rails module Generators class GeneratedAttribute @@ -13,7 +15,6 @@ module Rails when :time then :time_select when :datetime, :timestamp then :datetime_select when :date then :date_select - when :string then :text_field when :text then :text_area when :boolean then :check_box else diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 952400e049..0dfb5cd1c9 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -189,18 +189,23 @@ module Rails end alias :assert_method :assert_instance_method - # Asserts the given field name gets translated to an attribute type - # properly. + # Asserts the given attribute type gets translated to a field type + # properly: # # assert_field_type :date, :date_select # - def assert_field_type(name, attribute_type) - assert_equal( - Rails::Generators::GeneratedAttribute.new('test', name.to_s).field_type, - attribute_type - ) + def assert_field_type(attribute_type, field_type) + assert_equal(field_type, create_generated_attribute(attribute_type).field_type) end - + + # Asserts the given attribute type gets a proper default value: + # + # assert_field_type :string, "MyString" + # + def assert_field_default_value(attribute_type, value) + assert_equal(value, create_generated_attribute(attribute_type).default) + end + # Runs the generator configured for this class. The first argument is an array like # command line arguments: # @@ -226,6 +231,15 @@ module Rails @generator ||= self.generator_class.new(args, options, config.reverse_merge(:destination_root => destination_root)) end + # Create a Rails::Generators::GeneratedAttribute by supplying the + # attribute type and, optionally, the attribute name: + # + # create_generated_attribute(:string, 'name') + # + def create_generated_attribute(attribute_type, name = 'test') + Rails::Generators::GeneratedAttribute.new(name, attribute_type.to_s) + end + protected def destination_root_is_set? #:nodoc: |