docbrown/spec/services/notifications/remove_all_spec.rb
cyrillefr abb4831a53 Move remove_all notifications method in own job (#2882)
- that calls a service
    - spec for job + service
    - check actual integration spec
    - minor refactoring
2019-05-20 13:54:39 -04:00

20 lines
1,017 B
Ruby

require "rails_helper"
RSpec.describe Notifications::RemoveAll do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:organization) { create(:organization) }
let(:article) { create(:article) }
let(:article2) { create(:article) }
let(:comment) { create(:comment, user_id: user.id, commentable_id: article.id, commentable_type: "Article") }
before do
create(:notification, user: user, organization: organization, notifiable_id: article.id, notifiable_type: "Article", action: "Published")
create(:notification, user: user2, organization: organization, notifiable_id: article.id, notifiable_type: "Article", action: "Published")
create(:notification, user: user, organization: organization, notifiable_id: comment.id, notifiable_type: "Comment", action: "Reaction")
end
it "checks all notifications for an article are deleted and only for an article" do
expect { described_class.call(article.id, "Article", "Published") }.to change(Notification, :count).by(-2)
end
end