Merge pull request #1200 from Retrospring/fix/touch-updated-at-after-mark-as-read
Touch updated at after marking inbox/notification entries as read
This commit is contained in:
commit
eca53de004
|
@ -82,10 +82,13 @@ class InboxController < ApplicationController
|
|||
.where(questions: { user: @author_user, author_is_anonymous: false })
|
||||
end
|
||||
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
def mark_inbox_entries_as_read
|
||||
# using .dup to not modify @inbox -- useful in tests
|
||||
@inbox&.dup&.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
|
||||
@inbox&.dup&.update_all(new: false)
|
||||
current_user.touch(:inbox_updated_at)
|
||||
end
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
|
||||
def increment_metric
|
||||
Retrospring::Metrics::QUESTIONS_ASKED.increment(
|
||||
|
|
|
@ -48,10 +48,13 @@ class NotificationsController < ApplicationController
|
|||
.count(:target_type)
|
||||
end
|
||||
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
def mark_notifications_as_read
|
||||
# using .dup to not modify @notifications -- useful in tests
|
||||
@notifications&.dup&.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
|
||||
@notifications&.dup&.update_all(new: false)
|
||||
current_user.touch(:notifications_updated_at)
|
||||
end
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
|
||||
def cursored_notifications_for(type:, last_id:, size: nil)
|
||||
cursor_params = { last_id: last_id, size: size }.compact
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe InboxController, type: :controller do
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
let(:original_inbox_updated_at) { 1.day.ago }
|
||||
let(:user) { FactoryBot.create(:user, inbox_updated_at: original_inbox_updated_at) }
|
||||
|
||||
describe "#show" do
|
||||
shared_examples_for "sets the expected ivars" do
|
||||
|
@ -53,7 +56,7 @@ describe InboxController, type: :controller do
|
|||
more_data_available: false,
|
||||
inbox_count: 1,
|
||||
delete_id: "ib-delete-all",
|
||||
disabled: nil
|
||||
disabled: nil,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -62,6 +65,13 @@ describe InboxController, type: :controller do
|
|||
expect { subject }.to change { inbox_entry.reload.new? }.from(true).to(false)
|
||||
end
|
||||
|
||||
it "updates the the timestamp used for caching" do
|
||||
user.update(inbox_updated_at: original_inbox_updated_at)
|
||||
travel 1.second do
|
||||
expect { subject }.to change { user.reload.inbox_updated_at }.from(original_inbox_updated_at).to(Time.now.utc)
|
||||
end
|
||||
end
|
||||
|
||||
context "when requested the turbo stream format" do
|
||||
subject { get :show, format: :turbo_stream }
|
||||
|
||||
|
|
|
@ -3,9 +3,12 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe NotificationsController do
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
describe "#index" do
|
||||
subject { get :index, params: { type: :new } }
|
||||
|
||||
let(:original_notifications_updated_at) { 1.day.ago }
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
before do
|
||||
|
@ -38,6 +41,13 @@ describe NotificationsController do
|
|||
it "marks notifications as read" do
|
||||
expect { subject }.to change { Notification.for(user).where(new: true).count }.from(2).to(0)
|
||||
end
|
||||
|
||||
it "updates the the timestamp used for caching" do
|
||||
user.update(notifications_updated_at: original_notifications_updated_at)
|
||||
travel 1.second do
|
||||
expect { subject }.to change { user.reload.notifications_updated_at }.from(original_notifications_updated_at).to(Time.now.utc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue