Skip to content

Commit

Permalink
Don't require against if tsvector_column is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Hunter authored and nertzy committed Dec 19, 2021
1 parent 849e667 commit 40335c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/pg_search/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def default_options
}.freeze

def assert_valid_options(options)
unless options[:against] || options[:associated_against]
raise ArgumentError, "the search scope #{@name} must have :against or :associated_against in its options"
unless options[:against] || options[:associated_against] || using_tsvector_column?(options[:using])
raise ArgumentError, "the search scope #{@name} must have :against or :associated_against in its options or specify a tsvector_column"
end

options.assert_valid_keys(VALID_KEYS)
Expand All @@ -104,5 +104,12 @@ def assert_valid_options(options)
end
end
end

def using_tsvector_column?(options)
return unless options.is_a?(Hash)

options.dig(:dmetaphone, :tsvector_column).present? ||
options.dig(:tsearch, :tsvector_column).present?
end
end
end
16 changes: 16 additions & 0 deletions spec/integration/pg_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@
}.to raise_error(ArgumentError, /against/)
end
end

context "when a tsvector column is specified" do
it "does not raise an exception when invoked" do
ModelWithPgSearch.pg_search_scope :with_unknown_ignoring, {
using: {
tsearch: {
tsvector_column: "tsv"
}
}
}

expect {
ModelWithPgSearch.with_unknown_ignoring("foo")
}.not_to raise_error
end
end
end
end
end
Expand Down

0 comments on commit 40335c5

Please sign in to comment.