Permalink
Browse files

Add unit test coverage for Trigram#rank

  • Loading branch information...
1 parent 64317d6 commit e77ecda6cc43f28977b3c838ca4d0e12a9054e0c @nertzy nertzy committed Apr 2, 2013
Showing with 26 additions and 0 deletions.
  1. +26 −0 spec/lib/pg_search/features/trigram_spec.rb
@@ -0,0 +1,26 @@
+require "spec_helper"
+
+describe PgSearch::Features::Trigram do
+ describe "#rank" do
+ with_model :Model do
+ table do |t|
+ t.string :name
+ t.text :content
+ end
+ end
+
+ it "returns an expression using the similarity() function" do
+ query = "query"
+ columns = [
+ PgSearch::Configuration::Column.new(:name, nil, Model),
+ PgSearch::Configuration::Column.new(:content, nil, Model),
+ ]
+ options = stub(:options)
+ config = stub(:config, :ignore => [])
+ normalizer = PgSearch::Normalizer.new(config)
+
+ feature = described_class.new(query, options, columns, Model, normalizer)
+ feature.rank.to_sql.should == %Q{(similarity((coalesce(#{Model.quoted_table_name}."name"::text, '') || ' ' || coalesce(#{Model.quoted_table_name}."content"::text, '')), 'query'))}
+ end
+ end
+end

0 comments on commit e77ecda

Please sign in to comment.