Sha256: 87e6d8c3e15deb6b88d9181f189af675717c561de4719de6e79a10d33c6b159c

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

require "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

4 entries across 4 versions & 1 rubygems

Version Path
pg_search-0.7.4 spec/lib/pg_search/document_spec.rb
pg_search-0.7.3 spec/lib/pg_search/document_spec.rb
pg_search-0.7.2 spec/lib/pg_search/document_spec.rb
pg_search-0.7.1 spec/lib/pg_search/document_spec.rb