Sha256: c02a7863d955c2298e93e8a99b2b91efd8a743cda6239c65d562eb9aefb4af7d

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

require 'spec/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
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
skalee-thinking-sphinx-1.3.14.2 spec/thinking_sphinx/active_record/has_many_association_spec.rb
skalee-thinking-sphinx-1.3.14.1 spec/thinking_sphinx/active_record/has_many_association_spec.rb
hawkerb-thinking-sphinx-1.3.18 spec/thinking_sphinx/active_record/has_many_association_spec.rb
hawkerb-thinking-sphinx-1.3.17 spec/thinking_sphinx/active_record/has_many_association_spec.rb
thinking-sphinx-1.3.15 spec/thinking_sphinx/active_record/has_many_association_spec.rb
hawkerb-thinking-sphinx-1.3.16 spec/thinking_sphinx/active_record/has_many_association_spec.rb
hawkerb-thinking-sphinx-1.3.15 spec/thinking_sphinx/active_record/has_many_association_spec.rb
hawkerb-thinking-sphinx-1.3.14 spec/thinking_sphinx/active_record/has_many_association_spec.rb
zipme-thinking-sphinx-1.3.14 spec/thinking_sphinx/active_record/has_many_association_spec.rb