<commit_before>require 'spec_helper'

class User < ActiveRecord::Base
  hstore_flags :fighter, :lover
end

class UserNoScopes < ActiveRecord::Base
  self.table_name = "users"
  hstore_flags :fighter, :lover, :referee, scopes: false
end

class UserMultiFlags < ActiveRecord::Base
  self.table_name = "users"
  hstore_flags :fighter, :lover, :referee
  hstore_flags :drinker, :smoker, :bartender, field: "more_flags"
end

describe HStoreFlags do
  it "creates accessors for flags" do
    u = User.new(fighter: true)
    u.fighter.should  == true
    u.fighter?.should == true
    u.lover.should    == false
    u.lover?.should   == false
  end

  it "creates scopes without scopes: false" do
    User.should respond_to(:fighter)
    User.should respond_to(:not_fighter)
    User.should respond_to(:lover)
    User.should respond_to(:not_lover)
  end

  it "does not create scopes with scopes: false" do
    UserNoScopes.should_not respond_to(:fighter)
    UserNoScopes.should_not respond_to(:not_fighter)
    UserNoScopes.should_not respond_to(:lover)
    UserNoScopes.should_not respond_to(:not_lover)
  end

  it "creates proper scopes when no field is defined" do
    User.fighter.to_sql.should =~ /defined\(flags, 'fighter'\) IS TRUE/
    User.not_fighter.to_sql.should =~ /defined\(flags, 'fighter'\) IS NOT TRUE/
  end

  it "creates proper scopes when field is defined" do
    UserMultiFlags.drinker.to_sql.should =~ /defined\(more_flags, 'drinker'\) IS TRUE/
    UserMultiFlags.not_drinker.to_sql.should =~ /defined\(more_flags, 'drinker'\) IS NOT TRUE/
  end

  it "updates changes with new bit values" do
    u = User.new
    u.changes[:fighter].should be_nil
    u.fighter = true
    u.changes[:fighter].should == [false, true]
    u.fighter = false
    u.changes[:fighter].should == [true, false] # this is wrong, it should disappear
  end
end<commit_msg>update specs to use new expect syntax<commit_after>require 'spec_helper'

class User < ActiveRecord::Base
  hstore_flags :fighter, :lover
end

class UserNoScopes < ActiveRecord::Base
  self.table_name = "users"
  hstore_flags :fighter, :lover, :referee, scopes: false
end

class UserMultiFlags < ActiveRecord::Base
  self.table_name = "users"
  hstore_flags :fighter, :lover, :referee
  hstore_flags :drinker, :smoker, :bartender, field: "more_flags"
end

describe HStoreFlags do
  it "creates accessors for flags" do
    u = User.new(fighter: true)
    expect(u.fighter).to eq(true)
    expect(u.fighter?).to eq(true)
    expect(u.lover).to eq(false)
    expect(u.lover?).to eq(false)
  end

  it "creates scopes without scopes: false" do
    expect(User).to respond_to(:fighter)
    expect(User).to respond_to(:not_fighter)
    expect(User).to respond_to(:lover)
    expect(User).to respond_to(:not_lover)
  end

  it "does not create scopes with scopes: false" do
    expect(UserNoScopes).not_to respond_to(:fighter)
    expect(UserNoScopes).not_to respond_to(:not_fighter)
    expect(UserNoScopes).not_to respond_to(:lover)
    expect(UserNoScopes).not_to respond_to(:not_lover)
  end

  it "creates proper scopes when no field is defined" do
    expect(User.fighter.to_sql).to match(/defined\(flags, 'fighter'\) IS TRUE/)
    expect(User.not_fighter.to_sql).to match(/defined\(flags, 'fighter'\) IS NOT TRUE/)
  end

  it "creates proper scopes when field is defined" do
    expect(UserMultiFlags.drinker.to_sql).to match(/defined\(more_flags, 'drinker'\) IS TRUE/)
    expect(UserMultiFlags.not_drinker.to_sql).to match(/defined\(more_flags, 'drinker'\) IS NOT TRUE/)
  end

  it "updates changes with new bit values" do
    u = User.new
    expect(u.changes[:fighter]).to eq(nil)
    u.fighter = true
    expect(u.changes[:fighter]).to eq([false, true])
    u.fighter = false
    expect(u.changes[:fighter]).to eq([true, false]) # this is wrong, it should disappear
  end
end
{'fraction_non_alphanumeric': 0.116454380036392, 'fraction_numerical': 0.0, 'mean_word_length': 4.083223249669749, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1429774', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1336, 'n_words': 335}