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:
Javi Martín
2022-08-09 13:33:45 +02:00
parent f6fefde91d
commit e66b9687a2
2 changed files with 28 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ module SearchCache
end
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
private

View 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