aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorayaya <ayaya@ayaya.tw>2012-01-31 18:43:54 +0800
committerayaya <ayaya@ayaya.tw>2012-05-14 00:57:29 +0800
commitc140a27fc55e294a130b874f075748c5cd03de1e (patch)
treee88ebb59e4f12c3e129c8452cb61bac9e0e32eab /activemodel/test/cases/attribute_methods_test.rb
parentd98bbdee14384ff2e99e2f1716a8dff681521dea (diff)
downloadrails-c140a27fc55e294a130b874f075748c5cd03de1e.tar.gz
rails-c140a27fc55e294a130b874f075748c5cd03de1e.tar.bz2
rails-c140a27fc55e294a130b874f075748c5cd03de1e.zip
fix `alias_attribute` will raise a syntax error if make an alias on a
column that named as a ruby keyword
Diffstat (limited to 'activemodel/test/cases/attribute_methods_test.rb')
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
index 34298d31c2..efbf2db1eb 100644
--- a/activemodel/test/cases/attribute_methods_test.rb
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -76,6 +76,19 @@ private
end
end
+class ModelWithRubyKeywordNamedAttributes
+ include ActiveModel::AttributeMethods
+
+ def attributes
+ { :begin => 'value of begin', :end => 'value of end' }
+ end
+
+private
+ def attribute(name)
+ attributes[name.to_sym]
+ end
+end
+
class ModelWithoutAttributesMethod
include ActiveModel::AttributeMethods
end
@@ -148,6 +161,15 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.foo_bar
end
+ test '#alias_attribute works with attributes named as a ruby keyword' do
+ ModelWithRubyKeywordNamedAttributes.define_attribute_methods([:begin, :end])
+ ModelWithRubyKeywordNamedAttributes.alias_attribute(:from, :begin)
+ ModelWithRubyKeywordNamedAttributes.alias_attribute(:to, :end)
+
+ assert_equal "value of begin", ModelWithRubyKeywordNamedAttributes.new.from
+ assert_equal "value of end", ModelWithRubyKeywordNamedAttributes.new.to
+ end
+
test '#undefine_attribute_methods removes attribute methods' do
ModelWithAttributes.define_attribute_methods([:foo])
ModelWithAttributes.undefine_attribute_methods