<commit_before>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'ace_of_spades' do

  class Poker < ActiveRecord::Base
    ace_of_spades( {:server_address => 'druby://localhost:12345'} )

    searchable do 
      text :suit, :rank, :value
    end
  end

  context "when committing to index by saving and then searching on index" do
    
    it "should find by tag" do
      card1 = Poker.new( suit: "Hearts",   rank: "King",  value: 13 )
      card2 = Poker.new( suit: "Spades",   rank: "Ace",   value: 14 )
      card3 = Poker.new( suit: "Clubs",    rank: "Jack",  value: 11 )
      card4 = Poker.new( suit: "Diamonds", rank: "Three", value:  3 )
      card5 = Poker.new( suit: "Clubs",    rank: "Ace",   value: 14 )

      card1.save
      card2.save
      card3.save
      card4.save
      card5.save

      result = Poker.search(suit: "Spades")
      result.size.should == 1
      result.should include( {:id => "2", :suit => "Spades", :rank => "Ace", :value => 14} )
    end
  end
end  <commit_msg>regression tests for bug discovery in search<commit_after>require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'ace_of_spades' do

  class Poker < ActiveRecord::Base
    ace_of_spades( {:server_address => 'druby://localhost:12345'} )

    searchable do 
      text :suit, :rank, :value
    end
  end

  context "when committing to index by saving and then searching on index" do

    before :all do
      card1 = Poker.new( suit: "Hearts",   rank: "King",  value: 13 )
      card2 = Poker.new( suit: "Spades",   rank: "Ace",   value: 14 )
      card3 = Poker.new( suit: "Clubs",    rank: "Jack",  value: 11 )
      card4 = Poker.new( suit: "Diamonds", rank: "Three", value:  3 )
      card5 = Poker.new( suit: "Clubs",    rank: "Queen", value: 12 )

      card1.save
      card2.save
      card3.save
      card4.save
      card5.save
    end
    
    it "should find by field" do
      result1 = Poker.search(suit: "Spades")
      result2 = Poker.search(rank: "Ace")
      result3 = Poker.search(value: 14)
      result1.size.should == 1
      result2.size.should == 1
      result3.size.should == 1
      result1.should include( {:id => "2", :suit => "Spades", :rank => "Ace", :value => 14} )
      result2.should include( {:id => "2", :suit => "Spades", :rank => "Ace", :value => 14} )
      result3.should include( {:id => "2", :suit => "Spades", :rank => "Ace", :value => 14} )
    end
    
    it "should be empty when field value does not exist" do
      result = Poker.search(suit: "Zpades")
      result.size.should == 0
    end
    
    it "should have fields with correct types" do
      result = Poker.search(suit: "Spades")
      fields = result.first
      fields[:suit].should be_a_kind_of(String)
      fields[:rank].should be_a_kind_of(String)
      fields[:value].should be_a_kind_of(Fixnum)
    end
  end
end  
{'fraction_non_alphanumeric': 0.14191533657182512, 'fraction_numerical': 0.0263705759888966, 'mean_word_length': 2.649367088607595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6299869', 'n_tokens_mistral': 1052, 'n_tokens_neox': 985, 'n_words': 281}