Permalink
Browse files

Fixed bug which made impossible to clone search object without scope …

…(see specs)

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
  • Loading branch information...
1 parent eba965e commit 7cd3283c28d8fadd9ee587fc9db904b558a598e4 kazjote committed with Jul 28, 2009
Showing with 13 additions and 3 deletions.
  1. +2 −2 lib/searchlogic/search.rb
  2. +11 −1 spec/search_spec.rb
View
4 lib/searchlogic/search.rb
@@ -51,7 +51,7 @@ def initialize(klass, current_scope, conditions = {})
end
def clone
- self.class.new(klass, current_scope.clone, conditions.clone)
+ self.class.new(klass, current_scope && current_scope.clone, conditions.clone)
end
# Returns a hash of the current conditions set.
@@ -148,4 +148,4 @@ def type_cast(value, type)
end
end
end
-end
+end
View
12 spec/search_spec.rb
@@ -40,6 +40,16 @@
search1.all.should == [user2]
end
+ it "should clone properly without scope" do
+ user1 = User.create(:age => 5)
+ user2 = User.create(:age => 25)
+ search1 = User.search(:age_gt => 10)
+ search2 = search1.clone
+ search2.age_gt = 1
+ search2.all.should == User.all
+ search1.all.should == [user2]
+ end
+
it "should delete the condition" do
search = User.search(:username_like => "bjohnson")
search.delete("username_like")
@@ -292,4 +302,4 @@
User.search(:order => "ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
end
end
-end
+end

0 comments on commit 7cd3283

Please sign in to comment.