diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-30 16:48:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-30 16:48:20 -0700 |
commit | 74abdb1eab2dffea6247af7653b994c1f1bfe2ef (patch) | |
tree | 7fcbead76e4d42dad7485a2b41fda9237ac7d9a1 /activerecord/test/cases | |
parent | 1b84df430c324ff90b0a180039de0a345184ec94 (diff) | |
download | rails-74abdb1eab2dffea6247af7653b994c1f1bfe2ef.tar.gz rails-74abdb1eab2dffea6247af7653b994c1f1bfe2ef.tar.bz2 rails-74abdb1eab2dffea6247af7653b994c1f1bfe2ef.zip |
move the cache to the AR models and populate it on inherited
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index f99801c437..a695087426 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -9,6 +9,10 @@ module ActiveRecord fixtures :posts, :comments, :authors class FakeKlass < Struct.new(:table_name, :name) + extend ActiveRecord::Delegation::DelegateCache + + inherited self + def self.connection Post.connection end @@ -76,8 +80,8 @@ module ActiveRecord end def test_table_name_delegates_to_klass - relation = Relation.new FakeKlass.new('foo'), :b - assert_equal 'foo', relation.table_name + relation = Relation.new FakeKlass.new('posts'), :b + assert_equal 'posts', relation.table_name end def test_scope_for_create @@ -177,8 +181,12 @@ module ActiveRecord end test 'merging a hash interpolates conditions' do - klass = stub_everything - klass.stubs(:sanitize_sql).with(['foo = ?', 'bar']).returns('foo = bar') + klass = Class.new(FakeKlass) do + def self.sanitize_sql(args) + raise unless args == ['foo = ?', 'bar'] + 'foo = bar' + end + end relation = Relation.new(klass, :b) relation.merge!(where: ['foo = ?', 'bar']) @@ -210,6 +218,9 @@ module ActiveRecord class RelationMutationTest < ActiveSupport::TestCase class FakeKlass < Struct.new(:table_name, :name) + extend ActiveRecord::Delegation::DelegateCache + inherited self + def arel_table Post.arel_table end @@ -217,6 +228,10 @@ module ActiveRecord def connection Post.connection end + + def relation_delegate_class(klass) + self.class.relation_delegate_class(klass) + end end def relation |