Sha256: 2db5fcceaaf611f2c18a9c6b54d3bc0e4932147b0d985fb7910856a5bd1d495e

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe "Or conditions" do
  it "should match username or name" do
    User.username_or_name_like("ben").proxy_options.should == {:conditions => "(users.name LIKE '%ben%') OR (users.username LIKE '%ben%')"}
  end
  
  it "should use the specified condition" do
    User.username_begins_with_or_name_like("ben").proxy_options.should == {:conditions => "(users.name LIKE '%ben%') OR (users.username LIKE 'ben%')"}
  end
  
  it "should use the last specified condition" do
    User.username_or_name_like_or_id_or_age_lt(10).proxy_options.should == {:conditions => "(users.age < 10) OR (users.id < 10) OR (users.name LIKE '%10%') OR (users.username LIKE '%10%')"}
  end
  
  it "should raise an error on unknown conditions" do
    lambda { User.usernme_begins_with_or_name_like("ben") }.should raise_error(Searchlogic::NamedScopes::OrConditions::UnknownConditionError)
  end
  
  it "should play nice with other scopes" do
    User.username_begins_with("ben").id_gt(10).age_not_nil.username_or_name_ends_with("ben").scope(:find).should ==
      {:conditions => "((users.name LIKE '%ben') OR (users.username LIKE '%ben')) AND ((users.age IS NOT NULL) AND ((users.id > 10) AND (users.username LIKE 'ben%')))"}
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
binarylogic-searchlogic-2.3.0 spec/named_scopes/or_conditions_spec.rb
searchlogic-2.3.0 spec/named_scopes/or_conditions_spec.rb