Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a define_attr_method test

  • Loading branch information...
commit fda45f4fc493f5596375199fefe854df24b1ffbf 1 parent 5232077
@spastorino spastorino authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 activemodel/test/cases/attribute_methods_test.rb
View
13 activemodel/test/cases/attribute_methods_test.rb
@@ -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')
Please sign in to comment.
Something went wrong with that request. Please try again.