Ensure inbox caching timestamp gets updated when answering questions and returning to inbox
This commit is contained in:
parent
eed4ed5d4b
commit
54ac832c91
|
@ -20,6 +20,7 @@ class Answer < ApplicationRecord
|
|||
|
||||
after_create do
|
||||
Inbox.where(user: self.user, question: self.question).destroy_all
|
||||
user.touch :inbox_updated_at # rubocop:disable Rails/SkipsModelValidations
|
||||
|
||||
Notification.notify self.question.user, self unless self.question.user == self.user or self.question.user.nil?
|
||||
Subscription.subscribe self.user, self
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe Ajax::AnswerController, :ajax_controller, type: :controller do
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
let(:question) { FactoryBot.create(:question, user: FactoryBot.build(:user, privacy_allow_stranger_answers: asker_allows_strangers)) }
|
||||
let(:asker_allows_strangers) { true }
|
||||
|
||||
|
@ -327,6 +329,14 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
|
|||
user.save
|
||||
expect { subject }.to(change { Inbox.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
|
||||
end
|
||||
|
||||
it "updates the inbox caching timestamp for the user who answered" do
|
||||
initial_timestamp = 1.day.ago
|
||||
answer.user.update(inbox_updated_at: initial_timestamp)
|
||||
freeze_time do
|
||||
expect { subject }.to(change { answer.user.reload.inbox_updated_at }.from(initial_timestamp).to(DateTime.now))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the answer exists and was not made by the current user" do
|
||||
|
|
Loading…
Reference in New Issue