* Dispatch an event only when a published article is created * Skip sending events about drafts updates * Skip sending events when a draft is destroyed * Fix article request spec * Slight refactoring
32 lines
896 B
Ruby
32 lines
896 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Articles::Destroyer do
|
|
let(:article) { create(:article) }
|
|
let(:event_dispatcher) { double }
|
|
|
|
before do
|
|
allow(event_dispatcher).to receive(:call)
|
|
end
|
|
|
|
it "destroys an article" do
|
|
described_class.call(article)
|
|
expect(Article.find_by(id: article.id)).to be_nil
|
|
end
|
|
|
|
it "schedules removing notifications" do
|
|
expect do
|
|
described_class.call(article)
|
|
end.to have_enqueued_job(Notifications::RemoveAllJob).once
|
|
end
|
|
|
|
it "calls events dispatcher" do
|
|
described_class.call(article, event_dispatcher)
|
|
expect(event_dispatcher).to have_received(:call).with("article_destroyed", article)
|
|
end
|
|
|
|
it "doesn't call a dispatched when a draft is destroyed" do
|
|
draft = create(:article, published: false)
|
|
described_class.call(draft, event_dispatcher)
|
|
expect(event_dispatcher).not_to have_received(:call)
|
|
end
|
|
end
|