Permalink
Browse files

Add test for define_attr_method using as name an invalid identifier

  • Loading branch information...
1 parent cb44e99 commit 52320775175275379b1b215274dc26bed7f43634 @spastorino spastorino committed Mar 16, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 activemodel/test/cases/attribute_methods_test.rb
@@ -41,6 +41,12 @@ class ModelWithWeirdNamesAttributes
attribute_method_suffix ''
+ class << self
+ define_method(:'c?d') do
+ 'c?d'
+ end
+ end
+
def attributes
{ :'a?b' => 'value of a?b' }
end
@@ -86,6 +92,13 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar')
end
+ test '#define_attr_method generates attribute method with invalid identifier characters' do
+ ModelWithWeirdNamesAttributes.define_attr_method(:'c?d', 'c?d')
+
+ assert_respond_to ModelWithWeirdNamesAttributes, :'c?d'
+ assert_equal "c?d", ModelWithWeirdNamesAttributes.send('c?d')
+ end
+
test '#alias_attribute works with attributes with spaces in their names' do
ModelWithAttributesWithSpaces.define_attribute_methods([:'foo bar'])
ModelWithAttributesWithSpaces.alias_attribute(:'foo_bar', :'foo bar')

0 comments on commit 5232077

Please sign in to comment.