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
DrMark-thinking-sphinx-1.1.14 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
DrMark-thinking-sphinx-1.1.15 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
DrMark-thinking-sphinx-1.1.6 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
DrMark-thinking-sphinx-1.2.5 spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
DrMark-thinking-sphinx-1.2.6 spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
bterlson-thinking-sphinx-1.2.8 spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
dpickett-thinking-sphinx-1.1.12 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
dpickett-thinking-sphinx-1.1.23 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
dpickett-thinking-sphinx-1.1.4 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
ebeigarts-thinking-sphinx-1.1.21 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
ebeigarts-thinking-sphinx-1.1.22 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
ebeigarts-thinking-sphinx-1.2.10 spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
factorylabs-thinking-sphinx-1.2.7 spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.10 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.11 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.12 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-0.9.13 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-1.1.0 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-1.1.1 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
freelancing-god-thinking-sphinx-1.1.10 spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb