Update tests to check for touching of caching timestamps
This commit is contained in:
parent
a6f526b9c4
commit
1b05063f4a
|
@ -26,6 +26,8 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
|
|||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
|
||||
include_examples "touches user timestamp", :inbox_updated_at
|
||||
end
|
||||
|
||||
shared_examples "does not create the answer" do
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe Ajax::CommentController, :ajax_controller, type: :controller do
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
let(:answer) { FactoryBot.create(:answer, user: FactoryBot.create(:user)) }
|
||||
|
||||
describe "#create" do
|
||||
|
@ -23,6 +25,19 @@ describe Ajax::CommentController, :ajax_controller, type: :controller do
|
|||
expect(answer.reload.comments.ids).to include(Comment.last.id)
|
||||
end
|
||||
|
||||
context "a user is subscribed to the answer" do
|
||||
let(:subscribed_user) { FactoryBot.create(:user) }
|
||||
|
||||
it "updates the notification caching timestamp for a subscribed user" do
|
||||
Subscription.subscribe(subscribed_user, answer)
|
||||
|
||||
travel_to(1.day.from_now) do
|
||||
expect { subject }.to change { subscribed_user.reload.notifications_updated_at }.to(DateTime.now)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
|
||||
|
|
|
@ -65,12 +65,7 @@ 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.floor }.from(original_inbox_updated_at.floor).to(Time.now.utc.floor)
|
||||
end
|
||||
end
|
||||
include_examples "touches user timestamp", :inbox_updated_at
|
||||
|
||||
context "when requested the turbo stream format" do
|
||||
subject { get :show, format: :turbo_stream }
|
||||
|
@ -280,6 +275,8 @@ describe InboxController, type: :controller do
|
|||
it "creates an inbox entry" do
|
||||
expect { subject }.to(change { user.inboxes.count }.by(1))
|
||||
end
|
||||
|
||||
include_examples "touches user timestamp", :inbox_updated_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,18 +17,20 @@ describe Settings::ExportController, type: :controller do
|
|||
end
|
||||
|
||||
context "when user has a new DataExported notification" do
|
||||
let(:notification) do
|
||||
let!(:notification) do
|
||||
Notification::DataExported.create(
|
||||
target_id: user.id,
|
||||
target_type: "User::DataExport",
|
||||
recipient: user,
|
||||
new: true
|
||||
new: true,
|
||||
)
|
||||
end
|
||||
|
||||
it "marks the notification as read" do
|
||||
expect { subject }.to change { notification.reload.new }.from(true).to(false)
|
||||
end
|
||||
|
||||
include_examples "touches user timestamp", :notifications_updated_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.shared_examples_for "touches user timestamp" do |timestamp_column|
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
it "touches #{timestamp_column}" do
|
||||
travel_to(1.day.from_now) do
|
||||
expect { subject }.to change { user.reload.send(timestamp_column) }.to(DateTime.now)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue