Fix calculating tsvector on hidden records
We introduced this bug in commit 55d339572, since we didn't take hidden
records into consideration.
I've tried to use `update_column` to simplify the code, but got a syntax
error `unnamed portal parameter` and didn't find how to fix it.
This commit is contained in:
@@ -6,7 +6,7 @@ module SearchCache
|
|||||||
end
|
end
|
||||||
|
|
||||||
def calculate_tsvector
|
def calculate_tsvector
|
||||||
self.class.where(id: id).update_all("tsv = (#{searchable_values_sql})")
|
self.class.with_hidden.where(id: id).update_all("tsv = (#{searchable_values_sql})")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
27
spec/models/search_cache_spec.rb
Normal file
27
spec/models/search_cache_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe SearchCache do
|
||||||
|
describe "#calculate_tsvector" do
|
||||||
|
it "calculates the tsv column of a record" do
|
||||||
|
debate = create(:debate)
|
||||||
|
debate.update_column(:tsv, nil)
|
||||||
|
|
||||||
|
expect(debate.reload.tsv).to be_nil
|
||||||
|
|
||||||
|
debate.calculate_tsvector
|
||||||
|
|
||||||
|
expect(debate.reload.tsv).not_to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "calculates the tsv column of a hidden record" do
|
||||||
|
debate = create(:debate, :hidden)
|
||||||
|
debate.update_column(:tsv, nil)
|
||||||
|
|
||||||
|
expect(debate.reload.tsv).to be_nil
|
||||||
|
|
||||||
|
debate.calculate_tsvector
|
||||||
|
|
||||||
|
expect(debate.reload.tsv).not_to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user