* Add delayed_job_web to dev environment for debugging * Add specs for the current Follow callbacks implementation * Move follower touching to ActiveJob * Spec for the touch followers job * Move Follow#create_chat_channel to ActiveJob and make the job safe * Add ActiveJob to send email notifications about follows * Enqueue SendEmailNotificationJob after the follow is created * Specs to wnsure jobs are enqueued on Follow creation * Make CreateChatChannelJob queue name more specific * Reaction specs for Reaction after_save callbacks logic * Touch user job * Call Users::TouchJob on reaction create * Move updating reactable to a separate job * Move busting reactable cache to a separate job * Bust homepage cache after reaction save in a separate job * Spec for enqueueing Users::TouchJob on reaction create * Refactor Reactions::UpdateReactable job * Fix observer spec
56 lines
1.8 KiB
Ruby
56 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Reaction, type: :model do
|
|
let(:article) { create(:article, featured: true) }
|
|
let(:user) { create(:user) }
|
|
# let!(:reaction) { build(:reaction, reactable: article) }
|
|
|
|
context "when creating and enqueueing" do
|
|
before { ActiveJob::Base.queue_adapter = :test }
|
|
|
|
it "enqueues the Users::TouchJob" do
|
|
expect do
|
|
create(:reaction, reactable: article, user: user)
|
|
end.to have_enqueued_job(Users::TouchJob).exactly(:once).with(user.id)
|
|
end
|
|
|
|
it "enqueues the Reactions::UpdateReactableJob" do
|
|
expect do
|
|
create(:reaction, reactable: article, user: user)
|
|
end.to have_enqueued_job(Reactions::UpdateReactableJob).exactly(:once)
|
|
end
|
|
|
|
it "enqueues the Reactions::BustReactableCacheJob" do
|
|
expect do
|
|
create(:reaction, reactable: article, user: user)
|
|
end.to have_enqueued_job(Reactions::BustReactableCacheJob).exactly(:once)
|
|
end
|
|
|
|
it "enqueues the Reactions::BustHomepageCacheJob" do
|
|
expect do
|
|
create(:reaction, reactable: article, user: user)
|
|
end.to have_enqueued_job(Reactions::BustHomepageCacheJob).exactly(:once)
|
|
end
|
|
end
|
|
|
|
context "when creating and inline" do
|
|
before { ActiveJob::Base.queue_adapter = :inline }
|
|
|
|
it "updates the reactable Comment" do
|
|
comment = create(:comment, commentable: article)
|
|
comment.update_columns(updated_at: Time.now - 1.day)
|
|
now = Time.now
|
|
create(:reaction, reactable: comment, user: user)
|
|
comment.reload
|
|
expect(comment.updated_at).to be >= now
|
|
end
|
|
|
|
it "touches the user" do
|
|
user.update_columns(updated_at: Time.now - 1.day)
|
|
now = Time.now
|
|
create(:reaction, reactable: article, user: user)
|
|
user.reload
|
|
expect(user.updated_at).to be >= now
|
|
end
|
|
end
|
|
end
|