Browse files

Add specs for OrConditions for coverage

  • Loading branch information...
1 parent 0967c91 commit 0181025c52de47f999101d297269e8064ea50228 @johndouthat johndouthat committed Mar 23, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 spec/searchlogic/named_scopes/or_conditions_spec.rb
View
10 spec/searchlogic/named_scopes/or_conditions_spec.rb
@@ -39,6 +39,12 @@
{:conditions => "((users.username LIKE '%ben') OR (users.name LIKE '%ben')) AND ((users.age IS NOT NULL) AND ((users.id > 10) AND (users.username LIKE 'ben%')))"}
end
+ it "should work with boolean conditions" do
+ User.male_or_name_eq("susan").proxy_options.should == {:conditions => %Q{("users"."male" = 't') OR (users.name = 'susan')}}
+ User.not_male_or_name_eq("susan").proxy_options.should == {:conditions => %Q{("users"."male" = 'f') OR (users.name = 'susan')}}
+ lambda { User.male_or_name_eq("susan").all }.should_not raise_error
+ end
+
it "should play nice with scopes on associations" do
lambda { User.name_or_company_name_like("ben") }.should_not raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
User.name_or_company_name_like("ben").proxy_options.should == {:joins => :company, :conditions => "(users.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
@@ -47,6 +53,10 @@
Cart.user_company_name_or_user_company_name_like("ben").proxy_options.should == {:joins => {:user=>:company}, :conditions => "(companies.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
end
+ it "should raise an error on missing condition" do
+ lambda { User.id_or_age(123) }.should raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
+ end
+
it "should not get confused by the 'or' in find_or_create_by_* methods" do
User.create(:name => "Fred")
User.find_or_create_by_name("Fred").should be_a_kind_of User

0 comments on commit 0181025

Please sign in to comment.