diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-04 11:10:47 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-04 11:10:47 -0200 |
commit | c294055a58d125ff719ae17f03015c71790f0df0 (patch) | |
tree | b7f7d720d28c1a3d04fb35fd101ae76611b1beeb /activerecord/test | |
parent | d261c5cc28d35ae3d493c42edd20d362b61556dc (diff) | |
parent | e9bf87f08e77a457e1b82c2409abcaf4aef5f97c (diff) | |
download | rails-c294055a58d125ff719ae17f03015c71790f0df0.tar.gz rails-c294055a58d125ff719ae17f03015c71790f0df0.tar.bz2 rails-c294055a58d125ff719ae17f03015c71790f0df0.zip |
Merge pull request #12403 from thedarkone/attr-method-missing-fix
Fix AR#method_missing re-dispatching into overwritten attribute methods
Conflicts:
activerecord/lib/active_record/attribute_methods.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 9c66ed354e..6c581a432f 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -767,8 +767,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase # that by defining a 'foo' method in the generated methods module for B. # (That module will be inserted between the two, e.g. [B, <GeneratedAttributes>, A].) def test_inherited_custom_accessors - klass = Class.new(ActiveRecord::Base) do - self.table_name = "topics" + klass = new_topic_like_ar_class do self.abstract_class = true def title; "omg"; end def title=(val); self.author_name = val; end @@ -783,8 +782,40 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_equal "lol", topic.author_name end + def test_on_the_fly_super_invokable_generated_attribute_methods_via_method_missing + klass = new_topic_like_ar_class do + def title + super + '!' + end + end + + real_topic = topics(:first) + assert_equal real_topic.title + '!', klass.find(real_topic.id).title + end + + def test_on_the_fly_super_invokable_generated_predicate_attribute_methods_via_method_missing + klass = new_topic_like_ar_class do + def title? + !super + end + end + + real_topic = topics(:first) + assert_equal !real_topic.title?, klass.find(real_topic.id).title? + end + private + def new_topic_like_ar_class(&block) + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'topics' + class_eval(&block) + end + + assert_empty klass.generated_attribute_methods.instance_methods(false) + klass + end + def cached_columns Topic.columns.map(&:name) - Topic.serialized_attributes.keys end |