<commit_before>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<commit_msg>Add a few more specs for the new OR feature<commit_after>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 work well with _or_equal_to" do
    User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(users.age > 10) OR (users.id <= 10)"}
  end
  
  it "should work well with _or_equal_to_any" do
    User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(users.age > 10) OR (users.id <= 10)"}
  end
  
  it "should work well with _or_equal_to_all" do
    User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(users.age > 10) OR (users.id <= 10)"}
  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
{'fraction_non_alphanumeric': 0.146455223880597, 'fraction_numerical': 0.014303482587064677, 'mean_word_length': 4.859744990892532, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964559', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1071, 'n_words': 273}