Permalink
Browse files

modulize AR::NullRelation

now we can invoke previously added scope extension methods
  • Loading branch information...
1 parent c1a0c77 commit 212a74d8b7b4a4010b32cd26bb06e843ec9aacb7 @amatsuda amatsuda committed May 31, 2012
View
4 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 @@ def exists?(id = false)
end
end
-end
+end
View
2 activerecord/lib/active_record/relation/query_methods.rb
@@ -279,7 +279,7 @@ def lock!(locks = true)
# end
#
def none
- NullRelation.new(@klass, @table)
+ scoped.extending(NullRelation)
end
def readonly(value = true)
View
7 activerecord/test/cases/relations_test.rb
@@ -226,7 +226,6 @@ def test_none
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 @@ def test_none_chainable
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

0 comments on commit 212a74d

Please sign in to comment.