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/test/generators | |
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/test/generators')
-rw-r--r-- | railties/test/generators/generated_attribute_test.rb | 91 |
1 files changed, 81 insertions, 10 deletions
diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index dacb06fb13..de7e4de2a6 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -5,36 +5,107 @@ class GeneratedAttributeTest < Rails::Generators::TestCase include GeneratorsTestHelper def test_field_type_returns_text_field - %w(integer float decimal string).each do |name| - assert_field_type name, :text_field + %w(integer float decimal string).each do |attribute_type| + assert_field_type attribute_type, :text_field end end def test_field_type_returns_datetime_select - %w(datetime timestamp).each do |name| - assert_field_type name, :datetime_select + %w(datetime timestamp).each do |attribute_type| + assert_field_type attribute_type, :datetime_select end end def test_field_type_returns_time_select - assert_field_type 'time', :time_select + assert_field_type :time, :time_select end def test_field_type_returns_date_select - assert_field_type 'date', :date_select + assert_field_type :date, :date_select end def test_field_type_returns_text_area - assert_field_type 'text', :text_area + assert_field_type :text, :text_area end def test_field_type_returns_check_box - assert_field_type 'boolean', :check_box + assert_field_type :boolean, :check_box end def test_field_type_with_unknown_type_returns_text_field - %w(foo bar baz).each do |name| - assert_field_type name, :text_field + %w(foo bar baz).each do |attribute_type| + assert_field_type attribute_type, :text_field + end + end + + def test_default_value_is_integer + assert_field_default_value :integer, 1 + end + + def test_default_value_is_float + assert_field_default_value :float, 1.5 + end + + def test_default_value_is_decimal + assert_field_default_value :decimal, '9.99' + end + + def test_default_value_is_datetime + %w(datetime timestamp time).each do |attribute_type| + assert_field_default_value attribute_type, Time.now.to_s(:db) + end + end + + def test_default_value_is_date + assert_field_default_value :date, Date.today.to_s(:db) + end + + def test_default_value_is_string + assert_field_default_value :string, 'MyString' + end + + def test_default_value_is_text + assert_field_default_value :text, 'MyText' + end + + def test_default_value_is_boolean + assert_field_default_value :boolean, false + end + + def test_default_value_is_nil + %w(references belongs_to).each do |attribute_type| + assert_field_default_value attribute_type, nil + end + end + + def test_default_value_is_empty_string + %w(foo bar baz).each do |attribute_type| + assert_field_default_value attribute_type, '' + end + end + + def test_human_name + assert_equal( + 'Full name', + create_generated_attribute(:string, 'full_name').human_name + ) + end + + def test_reference_is_true + %w(references belongs_to).each do |attribute_type| + assert_equal( + true, + create_generated_attribute(attribute_type).reference? + ) + end + end + + def test_reference_is_false + %w(foo bar baz).each do |attribute_type| + assert_equal( + false, + create_generated_attribute(attribute_type).reference? + ) end end end |