Sha256: 55110a0ac7db848093ce02072bff1de94c7e097fb6410ec36162b9ae8b100ba9

Contents?: true

Size: 1.99 KB

Versions: 10

Compression:

Stored size: 1.99 KB

Contents

require "spec_helper"

describe PgSearch::Features::DMetaphone do
  describe "#rank" do
    with_model :Model do
      table do |t|
        t.string :name
        t.text :content
      end
    end

    it "returns an expression similar to a TSearch, but wraps the arguments in pg_search_dmetaphone()" do
      query = "query"
      columns = [
        PgSearch::Configuration::Column.new(:name, nil, Model),
        PgSearch::Configuration::Column.new(:content, nil, Model),
      ]
      options = {}
      config = double(:config, :ignore => [])
      normalizer = PgSearch::Normalizer.new(config)

      feature = described_class.new(query, options, columns, Model, normalizer)
      expect(feature.rank.to_sql).to eq(
        %Q{(ts_rank((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))), (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')), 0))}
      )
    end
  end

  describe "#conditions" do
    with_model :Model do
      table do |t|
        t.string :name
        t.text :content
      end
    end

    it "returns an expression similar to a TSearch, but wraps the arguments in pg_search_dmetaphone()" do
      query = "query"
      columns = [
        PgSearch::Configuration::Column.new(:name, nil, Model),
        PgSearch::Configuration::Column.new(:content, nil, Model),
      ]
      options = {}
      config = double(:config, :ignore => [])
      normalizer = PgSearch::Normalizer.new(config)

      feature = described_class.new(query, options, columns, Model, normalizer)
      expect(feature.conditions.to_sql).to eq(
        %Q{((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')))}
      )
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pg_search-1.0.4 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-1.0.3 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-1.0.2 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-1.0.1 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-1.0.0 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-0.7.9 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-0.7.8 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-0.7.7 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-0.7.6 spec/lib/pg_search/features/dmetaphone_spec.rb
pg_search-0.7.5 spec/lib/pg_search/features/dmetaphone_spec.rb