Sha256: 2b87a5f277334a18c24028be38dad585012170749d542a950fcc2cb1f0b7230b

Contents?: true

Size: 1.99 KB

Versions: 11

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
  describe "search method" do
    before :each do
      Friendship.stub!(:search => true)
      
      @person = Person.find(:first)
      @index  = Friendship.sphinx_indexes.first
    end
    
    it "should raise an error if the required attribute doesn't exist" do
      @index.stub!(:attributes => [])
      
      lambda { @person.friendships.search "test" }.should raise_error(RuntimeError)
    end
    
    it "should add a filter for the attribute into a normal search call" do
      Friendship.should_receive(:search) do |query, options|
        options[:with][:person_id].should == @person.id
      end
      
      @person.friendships.search "test"
    end
    
    it "should define indexes for the reflection class" do
      Friendship.should_receive(:define_indexes)
      
      @person.friendships.search 'test'
    end
  end
  
  describe "search method for has_many :through" do
    before :each do
      Person.stub!(:search => true)
      
      @person = Person.find(:first)
      @index  = Person.sphinx_indexes.first
    end
    
    it "should raise an error if the required attribute doesn't exist" do
      @index.stub!(:attributes => [])
      
      lambda { @person.friends.search "test" }.should raise_error(RuntimeError)
    end
    
    it "should add a filter for the attribute into a normal search call" do
      Person.should_receive(:search).with do |query, options|
        options[:with][:friendly_ids].should == @person.id
      end
      
      @person.friends.search "test"
    end
  end
  
  describe 'filtering sphinx scopes' do
    before :each do
      Friendship.stub!(:search => Friendship)
      
      @person = Person.find(:first)
    end
    
    it "should add a filter for the attribute in a sphinx scope call" do
      Friendship.should_receive(:search).with do |options|
        options[:with][:person_id].should == @person.id
      end
      
      @person.friendships.reverse
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
thorsson_thinking-sphinx-2.0 spec/thinking_sphinx/active_record/has_many_association_spec.rb
angelf-thinking-sphinx-1.3.18 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-1.3.20 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-1.3.19 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thorsson_thinking-sphinx-1.3.18 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-allen-1.3.18.4 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-allen-1.3.18.3 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-allen-1.3.18.2 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-allen-1.3.18.1 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-allen-1.3.18 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-1.3.18 spec/thinking_sphinx/active_record/has_many_association_spec.rb