spec/search_spec.rb in joost-searchlogic-2.1.7.1 vs spec/search_spec.rb in joost-searchlogic-2.2.3.1
- old
+ new
@@ -38,10 +38,20 @@
search2.age_gt = 1
search2.all.should == User.all
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")
search.username_like.should be_nil
end
@@ -97,10 +107,24 @@
search = User.search
search.orders_total_gt = 10
search.orders_total_gt.should == 10
end
+ it "should allow setting pre-existing association conditions" do
+ User.named_scope :uname, lambda { |value| {:conditions => ["users.username = ?", value]} }
+ search = Company.search
+ search.users_uname = "bjohnson"
+ search.users_uname.should == "bjohnson"
+ end
+
+ it "should allow setting pre-existing association alias conditions" do
+ User.alias_scope :username_has, lambda { |value| User.username_like(value) }
+ search = Company.search
+ search.users_username_has = "bjohnson"
+ search.users_username_has.should == "bjohnson"
+ end
+
it "should allow using custom conditions" do
User.named_scope(:four_year_olds, { :conditions => { :age => 4 } })
search = User.search
search.four_year_olds = true
search.four_year_olds.should == true
@@ -134,10 +158,15 @@
it "should not allow setting conditions that are not scopes" do
search = User.search
lambda { search.unknown = true }.should raise_error(Searchlogic::Search::UnknownConditionError)
end
+ it "should not allow setting conditions on sensitive methods" do
+ search = User.search
+ lambda { search.destroy = true }.should raise_error(Searchlogic::Search::UnknownConditionError)
+ end
+
it "should not use the ruby implementation of the id method" do
search = User.search
search.id.should be_nil
end
@@ -290,6 +319,6 @@
it "should recognize the order condition" do
User.search(:order => "ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
end
end
-end
\ No newline at end of file
+end