A platform for community discussion. Free, open, simple.
DEV: Refactor tests for notification when liking a post.
Guo Xiang Tan78748f1501d0
diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rbindex 1650c8745ce..8cf531d4033 100644--- a/spec/models/post_action_spec.rb+++ b/spec/models/post_action_spec.rb@@ -275,28 +275,50 @@ describe PostAction doenddescribe 'when a user likes something' do+ before do+ PostActionNotifier.enable+ end- it 'should generate notifications correctly' do+ it 'should generate and remove notifications correctly' do+ expect do+ PostAction.act(codinghorror, post, PostActionType.types[:like])+ end.to change { Notification.count }.by(1)- PostActionNotifier.enable+ notification = Notification.last- PostAction.act(codinghorror, post, PostActionType.types[:like])- expect(Notification.count).to eq(1)+ expect(notification.user_id).to eq(post.user_id)+ expect(notification.notification_type).to eq(Notification.types[:liked])- mutee = Fabricate(:user)+ expect do+ PostAction.remove_act(codinghorror, post, PostActionType.types[:like])+ end.to change { Notification.count }.by(-1)- post = Fabricate(:post)+ expect(Notification.exists?(id: notification.id)).to eq(false)+ end++ it "should not generate a notification if liker has been muted" do+ mutee = Fabricate(:user)MutedUser.create!(user_id: post.user.id, muted_user_id: mutee.id)- PostAction.act(mutee, post, PostActionType.types[:like])- expect(Notification.count).to eq(1)+ expect do+ PostAction.act(mutee, post, PostActionType.types[:like])+ end.to_not change { Notification.count }+ end++ it "should generate a notification if liker is an admin irregardles of \+ muting" do# you can not mute admin, sorryMutedUser.create!(user_id: post.user.id, muted_user_id: admin.id)- PostAction.act(admin, post, PostActionType.types[:like])- expect(Notification.count).to eq(2)+ expect do+ PostAction.act(admin, post, PostActionType.types[:like])+ end.to change { Notification.count }.by(1)++ notification = Notification.last+ expect(notification.user_id).to eq(post.user_id)+ expect(notification.notification_type).to eq(Notification.types[:liked])endit 'should increase the `like_count` and `like_score` when a user likes something' dodiff --git a/spec/services/post_action_notifier_spec.rb b/spec/services/post_action_notifier_spec.rbindex b52aa8cb9a9..85d978fcf30 100644--- a/spec/services/post_action_notifier_spec.rb+++ b/spec/services/post_action_notifier_spec.rb@@ -10,26 +10,6 @@ describe PostActionNotifier dolet!(:evil_trout) { Fabricate(:evil_trout) }let(:post) { Fabricate(:post) }- context 'liking' do- context 'when liking a post' do- it 'creates a notification' do- expect {- PostAction.act(evil_trout, post, PostActionType.types[:like])- # one like (welcome badge deferred)- }.to change(Notification, :count).by(1)- end- end-- context 'when removing a liked post' do- it 'removes a notification' do- PostAction.act(evil_trout, post, PostActionType.types[:like])- expect {- PostAction.remove_act(evil_trout, post, PostActionType.types[:like])- }.to change(Notification, :count).by(-1)- end- end- end-context 'when editing a post' doit 'notifies a user of the revision' doexpect {