Sha256: c124d309388078ec523e9500c4e46cab9c85522a69d2947930571c23c2630bbe

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 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.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.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

10 entries across 10 versions & 5 rubygems

Version Path
DrMark-thinking-sphinx-0.9.7 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
DrMark-thinking-sphinx-0.9.8 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
DrMark-thinking-sphinx-0.9.9 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.5 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.6 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.7 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.8 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
nixme-thinking-sphinx-0.9.7 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
ryanb-thinking-sphinx-0.9.8 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
ryanb-thinking_sphinx-0.9.8 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb