require 'helper' class AxleAttributes::ConversionsTest < ActiveSupport::TestCase class TestModel include AxleAttributes::HasAttributes has_attribute :color, type: :string end include AxleAttributes::Conversions use_target_class TestModel test 'definitions' do expected = TestModel.attributes['color'] assert_equal expected, to_definition(expected) end test 'string converted to definition' do expected = TestModel.attributes['color'] assert_equal expected, to_definition('color') end test 'null definitions' do expected = AxleAttributes::NullDefinition.new(TestModel, 'abc') assert_equal expected, to_definition(expected) end test 'string converted to null definition' do expected = AxleAttributes::NullDefinition.new(TestModel, 'contacts') assert_equal expected, to_definition('contacts') end test 'unknown conversion' do assert_raises ConversionError do to_definition(123) end end end