Permalink
Browse files

Add unit test coverage for TSearch#rank

  • Loading branch information...
1 parent c260871 commit 263a0b0f097ebbde733b14d6243100b5e3eadda5 @nertzy nertzy committed Apr 2, 2013
Showing with 27 additions and 0 deletions.
  1. +27 −0 spec/lib/pg_search/features/tsearch_spec.rb
View
27 spec/lib/pg_search/features/tsearch_spec.rb
@@ -0,0 +1,27 @@
+require "spec_helper"
+
+describe PgSearch::Features::TSearch 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 ts_rank() function" do
+ query = "query"
+ columns = [
+ PgSearch::Configuration::Column.new(:name, nil, Model),
+ PgSearch::Configuration::Column.new(:content, nil, Model),
+ ]
+ 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{(ts_rank((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 0))}
+ end
+ end
+end

0 comments on commit 263a0b0

Please sign in to comment.