Sha256: e4b37485b1d47fe28f6f3ee451b8b758c42e43e34a576ceb73e6fcba21217bef

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe PgSearch::Document do
  with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA

  with_model :Searchable do
    table
    model do
      include PgSearch
      multisearchable({})
    end
  end

  it { should be_an(ActiveRecord::Base) }

  describe "callbacks" do
    describe "before_validation" do
      subject { document }
      let(:document) { PgSearch::Document.new(:searchable => searchable) }
      let(:searchable) { Searchable.new }

      before do
        # Redefine the options for multisearchable
        Searchable.multisearchable(multisearchable_options)
      end

      context "when searching against a single column" do
        let(:multisearchable_options) { {:against => :some_content} }
        let(:text) { "foo bar" }
        before do
          searchable.stub!(:some_content => text)
          document.valid?
        end

        its(:content) { should == text }
      end

      context "when searching against multiple columns" do
        let(:multisearchable_options) { {:against => [:attr1, :attr2]} }
        before do
          searchable.stub!(:attr1 => "1", :attr2 => "2")
          document.valid?
        end

        its(:content) { should == "1 2" }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pg_search-0.4.1 spec/pg_search/document_spec.rb
pg_search-0.4 spec/pg_search/document_spec.rb
pg_search-0.3.4 spec/pg_search/document_spec.rb
pg_search-0.3.3 spec/pg_search/document_spec.rb
pg_search-0.3.2 spec/pg_search/document_spec.rb
pg_search-0.3.1 spec/pg_search/document_spec.rb
pg_search-0.3 spec/pg_search/document_spec.rb