Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

define_attr_method correctly defines methods with invalid identifiers

  • Loading branch information...
commit c834a751d2acbd55b580cbba2e96dd29c5d9a452 1 parent fda45f4
@spastorino spastorino authored
View
5 activemodel/lib/active_model/attribute_methods.rb
@@ -108,9 +108,8 @@ def define_attr_method(name, value=nil, &block)
else
# use eval instead of a block to work around a memory leak in dev
@dmitry
dmitry added a note

Forgot to cleanup comment?

@spastorino Owner

dmitry, hey thanks for pointing me to this. I saw this yeah I have to try a few more things and do another commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
# mode in fcgi
- sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
- def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end
- eorb
+ value = value.nil? ? 'nil' : value.to_s
+ sing.send(:define_method, name) { value }
end
end
View
6 activemodel/test/cases/attribute_methods_test.rb
@@ -7,7 +7,7 @@ class ModelWithAttributes
class << self
define_method(:bar) do
- 'bar'
+ 'original bar'
end
end
@@ -49,7 +49,7 @@ class ModelWithWeirdNamesAttributes
class << self
define_method(:'c?d') do
- 'c?d'
+ 'original c?d'
end
end
@@ -102,6 +102,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
ModelWithAttributes.define_attr_method(:bar, 'bar')
assert_respond_to ModelWithAttributes, :bar
+ assert_equal "original bar", ModelWithAttributes.original_bar
assert_equal "bar", ModelWithAttributes.bar
end
@@ -109,6 +110,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
ModelWithWeirdNamesAttributes.define_attr_method(:'c?d', 'c?d')
assert_respond_to ModelWithWeirdNamesAttributes, :'c?d'
+ assert_equal "original c?d", ModelWithWeirdNamesAttributes.send('original_c?d')
assert_equal "c?d", ModelWithWeirdNamesAttributes.send('c?d')
end
Please sign in to comment.
Something went wrong with that request. Please try again.