diff options
author | Akira Matsuda <ronnie@dio.jp> | 2012-05-31 16:31:35 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2012-06-01 14:46:13 +0900 |
commit | 212a74d8b7b4a4010b32cd26bb06e843ec9aacb7 (patch) | |
tree | adc100a4b7214d794ec0805bfa76734a3528e13d | |
parent | c1a0c7782eba29db5877d6b02e5e84cee15ae069 (diff) | |
download | rails-212a74d8b7b4a4010b32cd26bb06e843ec9aacb7.tar.gz rails-212a74d8b7b4a4010b32cd26bb06e843ec9aacb7.tar.bz2 rails-212a74d8b7b4a4010b32cd26bb06e843ec9aacb7.zip |
modulize AR::NullRelation
now we can invoke previously added scope extension methods
-rw-r--r-- | activerecord/lib/active_record/null_relation.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 7 |
3 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/null_relation.rb b/activerecord/lib/active_record/null_relation.rb index c2d3eeb8ce..ff79f1d398 100644 --- a/activerecord/lib/active_record/null_relation.rb +++ b/activerecord/lib/active_record/null_relation.rb @@ -2,7 +2,7 @@ module ActiveRecord # = Active Record Null Relation - class NullRelation < Relation + module NullRelation def exec_queries @records = [] end @@ -60,4 +60,4 @@ module ActiveRecord end end -end
\ No newline at end of file +end diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 19fe8155d9..a89d0f3ebf 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -279,7 +279,7 @@ module ActiveRecord # end # def none - NullRelation.new(@klass, @table) + scoped.extending(NullRelation) end def readonly(value = true) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 2dc8f0053b..90367df5ee 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -226,7 +226,6 @@ class RelationTest < ActiveRecord::TestCase assert_no_queries do assert_equal [], Developer.none assert_equal [], Developer.scoped.none - assert Developer.none.is_a?(ActiveRecord::NullRelation) end end @@ -236,6 +235,12 @@ class RelationTest < ActiveRecord::TestCase end end + def test_none_chainable_to_existing_scope_extension_method + assert_no_queries do + assert_equal 1, Topic.anonymous_extension.none.one + end + end + def test_none_chained_to_methods_firing_queries_straight_to_db assert_no_queries do assert_equal [], Developer.none.pluck(:id) # => uses select_all |