Sha256: 5f3a16e304f5302f34a88aad642ab9be8ad92d517154cea0b6229d56f8945fae

Contents?: true

Size: 1.51 KB

Versions: 67

Compression:

Stored size: 1.51 KB

Contents

require 'spec/spec_helper'

describe 'ThinkingSphinx::ActiveRecord::HasManyAssociation' do
  describe "search method" do
    before :each do
      Friendship.stub_method(: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_method(:attributes => [])
      
      lambda { @person.friendships.search "test" }.should raise_error(RuntimeError)
      
      @index.unstub_method(:attributes)
    end
    
    it "should add a filter for the attribute into a normal search call" do
      @person.friendships.search "test"
      
      Friendship.should have_received(:search).with(
        "test", :with => {:person_id => @person.id}
      )
    end    
  end
  
  describe "search method for has_many :through" do
    before :each do
      Person.stub_method(: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_method(:attributes => [])
      
      lambda { @person.friends.search "test" }.should raise_error(RuntimeError)
      
      @index.unstub_method(:attributes)
    end
    
    it "should add a filter for the attribute into a normal search call" do
      @person.friends.search "test"
      
      Person.should have_received(:search).with(
        "test", :with => {:friendly_ids => @person.id}
      )
    end
  end
end

Version data entries

67 entries across 67 versions & 12 rubygems

Version Path
lostboy-thinking-sphinx-1.1.5.2 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
lostboy-thinking-sphinx-1.1.5.3 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
lostboy-thinking-sphinx-1.1.5.4 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
lostboy-thinking-sphinx-1.1.5.5 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
pixeltrix-thinking-sphinx-1.1.5 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
pixeltrix-thinking-sphinx-1.2.1 spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
sherpa99-thinking-sphinx-1.1.4 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb