Permalink
Browse files

Merge pull request #6579 from amatsuda/null_relation_modulize

modulize AR::NullRelation
  • Loading branch information...
2 parents c1a0c77 + c8882c1 commit 47896d22d31ef0639d3b33b323a1f900713e30da @josevalim josevalim committed Jun 1, 2012
@@ -2,24 +2,24 @@
module ActiveRecord
# = Active Record Null Relation
- class NullRelation < Relation
+ module NullRelation
def exec_queries
@records = []
end
- def pluck(column_name)
+ def pluck(_column_name)
[]
end
- def delete_all(conditions = nil)
+ def delete_all(_conditions = nil)
0
end
- def update_all(updates, conditions = nil, options = {})
+ def update_all(_updates, _conditions = nil, _options = {})
0
end
- def delete(id_or_array)
+ def delete(_id_or_array)
0
end
@@ -51,13 +51,12 @@ def count
0
end
- def calculate(operation, column_name, options = {})
+ def calculate(_operation, _column_name, _options = {})
nil
end
- def exists?(id = false)
+ def exists?(_id = false)
false
end
-
end
-end
+end
@@ -279,7 +279,7 @@ def lock!(locks = true)
# end
#
def none
- NullRelation.new(@klass, @table)
+ scoped.extending(NullRelation)
end
def readonly(value = true)
@@ -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 47896d2

Please sign in to comment.