diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-10 08:45:28 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-10 08:45:28 -0700 |
commit | 4da1af7fc15c6508d327d205e3de3f8ef248da8f (patch) | |
tree | acddcdbcb0608e2409ea97f784d188b5c0847c38 /activerecord | |
parent | c2e61aa61540802e5a5d9b54ff04b803d770eff6 (diff) | |
parent | cd1be1acc68221fbdfab0d13211d40bdeae630dc (diff) | |
download | rails-4da1af7fc15c6508d327d205e3de3f8ef248da8f.tar.gz rails-4da1af7fc15c6508d327d205e3de3f8ef248da8f.tar.bz2 rails-4da1af7fc15c6508d327d205e3de3f8ef248da8f.zip |
Merge pull request #6695 from kennyj/fix_6635
Fix #6635. We should call Scoping methods, before calling Array methods.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/delegation.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 9 |
2 files changed, 14 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index f5fdf437bf..64dda4f35a 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -32,12 +32,12 @@ module ActiveRecord protected def method_missing(method, *args, &block) - if Array.method_defined?(method) - ::ActiveRecord::Delegation.delegate method, :to => :to_a - to_a.send(method, *args, &block) - elsif @klass.respond_to?(method) + if @klass.respond_to?(method) ::ActiveRecord::Delegation.delegate_to_scoped_klass(method) scoping { @klass.send(method, *args, &block) } + elsif Array.method_defined?(method) + ::ActiveRecord::Delegation.delegate method, :to => :to_a + to_a.send(method, *args, &block) elsif arel.respond_to?(method) ::ActiveRecord::Delegation.delegate method, :to => :arel arel.send(method, *args, &block) @@ -46,4 +46,4 @@ module ActiveRecord end end end -end
\ No newline at end of file +end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 2762afc921..c886160af3 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -45,6 +45,15 @@ class NamedScopeTest < ActiveRecord::TestCase assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count) end + def test_method_missing_priority_when_delegating + klazz = Class.new(ActiveRecord::Base) do + self.table_name = "topics" + scope :since, Proc.new { where('written_on >= ?', Time.now - 1.day) } + scope :to, Proc.new { where('written_on <= ?', Time.now) } + end + assert_equal klazz.to.since.all, klazz.since.to.all + end + def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy assert Topic.approved.respond_to?(:limit) assert Topic.approved.respond_to?(:count) |