Skip to content
Browse files

Added assert_attribute_type to clean up GeneratedAttributeTest [#2377

…state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 5d979de commit ec017e158a0f006ac30bee94f81411a4d74a5227 @jeffkreeftmeijer jeffkreeftmeijer committed with josevalim
View
38 railties/test/generators/generated_attribute_test.rb
@@ -0,0 +1,38 @@
+require 'generators/generator_test_helper'
+require 'rails_generator/generated_attribute'
+
+class GeneratedAttributeTest < GeneratorTestCase
+ def test_field_type_returns_text_field
+ %w(integer float decimal string).each do |name|
+ assert_attribute_type name, :text_field
+ end
+ end
+
+ def test_field_type_returns_datetime_select
+ %w(datetime timestamp).each do |name|
+ assert_attribute_type name, :datetime_select
+ end
+ end
+
+ def test_field_type_returns_time_select
+ assert_attribute_type 'time', :time_select
+ end
+
+ def test_field_type_returns_date_select
+ assert_attribute_type 'date', :date_select
+ end
+
+ def test_field_type_returns_text_area
+ assert_attribute_type 'text', :text_area
+ end
+
+ def test_field_type_returns_check_box
+ assert_attribute_type 'boolean', :check_box
+ end
+
+ def test_field_type_with_unknown_type_returns_text_field
+ %w(foo bar baz).each do |name|
+ assert_attribute_type name, :text_field
+ end
+ end
+end
View
12 railties/test/generators/generator_test_helper.rb
@@ -307,4 +307,16 @@ def assert_generated_column(body, name, type)
def assert_generated_table(body, name)
assert_match /create_table :#{name.to_s} do/, body, "should have table #{name.to_s} defined"
end
+
+ # Asserts the given field name gets translated to an attribute type
+ # properly.
+ #
+ # assert_attribute_type 'date', :date_select
+ #
+ def assert_attribute_type(name, attribute_type)
+ assert_equal(
+ Rails::Generator::GeneratedAttribute.new('test', name).field_type,
+ attribute_type
+ )
+ end
end

0 comments on commit ec017e1

Please sign in to comment.
Something went wrong with that request. Please try again.