Add a define_attr_method test

This commit is contained in:
Santiago Pastorino 2011-03-16 21:08:02 -03:00
parent 5232077517
commit fda45f4fc4

@ -5,6 +5,12 @@ class ModelWithAttributes
attribute_method_suffix ''
class << self
define_method(:bar) do
'bar'
end
end
def attributes
{ :foo => 'value of foo' }
end
@ -92,6 +98,13 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar')
end
test '#define_attr_method generates attribute method' do
ModelWithAttributes.define_attr_method(:bar, 'bar')
assert_respond_to ModelWithAttributes, :bar
assert_equal "bar", ModelWithAttributes.bar
end
test '#define_attr_method generates attribute method with invalid identifier characters' do
ModelWithWeirdNamesAttributes.define_attr_method(:'c?d', 'c?d')