<commit_before>require File.join(File.dirname(__FILE__), "..", "spec_helper.rb")

describe 'queries', :queries => true do
  before :all do
    Redis.new.flushall
    Ampere.connect
    
    class Kitty < Ampere::Model
      field :name
      field :breed
      
      index :name
    end
    
    @kitty_paws = {
      name: 'Kit<NAME>',
      breed: 'Domestic shorthair'
    }
    @nate = {
      name:  'Nate',
      breed: 'Domestic shorthair'
    }
    @jinxii = {
      name:  'Jinxii',
      breed: 'Chartreux'
    }
    @italics = {
      name:  'Italics',
      breed: 'Siberian'
    }
    @serif = {
      name:  'Serif',
      breed: 'Siberian'
    }
    [@kitty_paws, @nate, @jinxii, @italics, @serif]. each {|hash| Kitty.create hash}
  end
  
  ### 
  
  it 'should pass a basic sanity check' do
    Kitty.count.should == 5
  end
  
  it 'should be able to select all kitties' do
    Kitty.all.map(&:name).should include('Kitty Paws')
    Kitty.all.map(&:name).should include('Nate')
    Kitty.all.map(&:name).should include('Jinxii')
    Kitty.all.map(&:name).should include('Italics')
    Kitty.all.map(&:name).should include('Serif')
  end
  
  context 'with one field' do
    it 'should be able to find by an indexed field using where()' do
      Kitty.where(:name => 'Nate').map(&:name).should include('Nate')
    end
  
    it 'should be able to find by a non-indexed field using where()' do
      Kitty.where(:breed => 'Siberian').map(&:name).should include('Italics')
      Kitty.where(:breed => 'Siberian').map(&:name).should include('Serif')
    end
  end
  
  it 'should be able to find by two indexed fields at once' do
    pending
  end
  
  it 'should be able to find by two non-indexed fields at once' do
    pending
  end
  
  it 'should be able to find by a mix of indexed and non-indexed fields' do
    pending
  end
  
  ###
  
  after :all do
    Redis.new.flushall
    Ampere.connect
  end
end
<commit_msg>Still working on queries.<commit_after>require File.join(File.dirname(__FILE__), "..", "spec_helper.rb")

describe 'queries', :queries => true do
  before :all do
    Redis.new.flushall
    Ampere.connect
    
    class Kitty < Ampere::Model
      field :name
      field :breed
      field :age
      field :color
      
      index :name
      index :color
    end
    
    @kitty_paws = {
      name:  '<NAME>',
      breed: 'Domestic shorthair',
      age:   19,
      color: 'orange'
    }
    @nate = {
      name:  'Nate',
      breed: 'Domestic shorthair',
      age:   17,
      color: 'black'
    }
    @jinxii = {
      name:  'Jinxii',
      breed: 'Chartreux',
      age:   3,
      color: 'grey'
    }
    @italics = {
      name:  'Italics',
      breed: 'Siberian',
      age:   7,
      color: 'orange'
    }
    @serif = {
      name:  'Serif',
      breed: 'Siberian',
      age:   5,
      color: 'grey'
    }
    [@kitty_paws, @nate, @jinxii, @italics, @serif]. each {|hash| Kitty.create hash}
  end
  
  ### 
  
  it 'should pass a basic sanity check' do
    Kitty.count.should == 5
  end
  
  it 'should be able to select all kitties' do
    Kitty.all.map(&:name).should include('Kitty Paws')
    Kitty.all.map(&:name).should include('Nate')
    Kitty.all.map(&:name).should include('Jinxii')
    Kitty.all.map(&:name).should include('Italics')
    Kitty.all.map(&:name).should include('Serif')
  end
  
  context 'with no fields' do
    it 'should return the empty set with no conditions given' do
      Kitty.where().should be_empty
    end
  end
  
  context 'with one field' do
    it 'should be able to find by an indexed field using where()' do
      Kitty.where(:name => 'Nate').map(&:name).should include('Nate')
    end
  
    it 'should be able to find by a non-indexed field using where()' do
      Kitty.where(:breed => 'Siberian').map(&:name).should include('Italics')
      Kitty.where(:breed => 'Siberian').map(&:name).should include('Serif')
    end
  end
  
  it 'should be able to find by two indexed fields at once' do
    pending
  end
  
  it 'should be able to find by two non-indexed fields at once' do
    pending
  end
  
  it 'should be able to find by a mix of indexed and non-indexed fields' do
    pending
  end
  
  ###
  
  after :all do
    Redis.new.flushall
    Ampere.connect
  end
end

{'fraction_non_alphanumeric': 0.12841466261965911, 'fraction_numerical': 0.002101330842867149, 'mean_word_length': 2.339049103663289, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '940402', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1509, 'n_words': 427}