Skip to content

Commit

Permalink
Add test for when options[:negation] is false
Browse files Browse the repository at this point in the history
  • Loading branch information
nertzy committed Dec 8, 2014
1 parent 1cf2c10 commit dcc066e
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions spec/lib/pg_search/features/tsearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,40 @@
)
end

it "returns a negated expression when a query is prepended with !" do
query = "!query"
columns = [
PgSearch::Configuration::Column.new(:name, nil, Model),
PgSearch::Configuration::Column.new(:content, nil, Model),
]
options = {:negation => true}
config = double(:config, :ignore => [])
normalizer = PgSearch::Normalizer.new(config)
context "when options[:negation] is true" do
it "returns a negated expression when a query is prepended with !" do
query = "!query"
columns = [
PgSearch::Configuration::Column.new(:name, nil, Model),
PgSearch::Configuration::Column.new(:content, nil, Model),
]
options = {:negation => true}
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', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', '!' || ''' ' || 'query' || ' ''')))}
)
feature = described_class.new(query, options, columns, Model, normalizer)
expect(feature.conditions.to_sql).to eq(
%Q{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', '!' || ''' ' || 'query' || ' ''')))}
)
end
end

context "when options[:negation] is false" do
it "does not return a negated expression when a query is prepended with !" do
query = "!query"
columns = [
PgSearch::Configuration::Column.new(:name, nil, Model),
PgSearch::Configuration::Column.new(:content, nil, Model),
]
options = {:negation => false}
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', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || '!query' || ' ''')))}
)
end
end
end
end

0 comments on commit dcc066e

Please sign in to comment.