Sha256: a6b2a8d03585bc88a970f68e6c72b6c1ab2549915d72acb499bbe5871f0e5787

Contents?: true

Size: 1.22 KB

Versions: 9

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

9 entries across 9 versions & 1 rubygems

Version Path
pg_search-0.7.0 spec/lib/pg_search/document_spec.rb
pg_search-0.6.4 spec/lib/pg_search/document_spec.rb
pg_search-0.6.3 spec/lib/pg_search/document_spec.rb
pg_search-0.6.2 spec/lib/pg_search/document_spec.rb
pg_search-0.6.1 spec/lib/pg_search/document_spec.rb
pg_search-0.6.0 spec/lib/pg_search/document_spec.rb
pg_search-0.5.7 spec/pg_search/document_spec.rb
pg_search-0.5.6 spec/pg_search/document_spec.rb
pg_search-0.5.5 spec/pg_search/document_spec.rb