mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Don’t use change { … }.by(0) in specs
This commit is contained in:
committed by
Loïc Guitaut
parent
3bfc254c4e
commit
91b6b5eee7
@@ -240,7 +240,7 @@ describe PostAlerter do
|
||||
create_post_with_alerts(
|
||||
raw: quote_raw, topic: pm, user: admin, post_type: Post.types[:whisper]
|
||||
)
|
||||
}.to change(user2.notifications, :count).by(0)
|
||||
}.not_to change(user2.notifications, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -353,7 +353,7 @@ describe PostAlerter do
|
||||
|
||||
expect {
|
||||
PostAlerter.post_created(post)
|
||||
}.to change(evil_trout.notifications, :count).by(0)
|
||||
}.not_to change(evil_trout.notifications, :count)
|
||||
end
|
||||
|
||||
it 'does not notify for ignored users' do
|
||||
@@ -362,7 +362,7 @@ describe PostAlerter do
|
||||
|
||||
expect {
|
||||
PostAlerter.post_created(post)
|
||||
}.to change(evil_trout.notifications, :count).by(0)
|
||||
}.not_to change(evil_trout.notifications, :count)
|
||||
end
|
||||
|
||||
it 'does not notify for users with new reply notification' do
|
||||
@@ -376,7 +376,7 @@ describe PostAlerter do
|
||||
)
|
||||
expect {
|
||||
PostAlerter.post_edited(post)
|
||||
}.to change(evil_trout.notifications, :count).by(0)
|
||||
}.not_to change(evil_trout.notifications, :count)
|
||||
|
||||
notification.destroy
|
||||
expect {
|
||||
@@ -463,7 +463,7 @@ describe PostAlerter do
|
||||
)
|
||||
}.to change(evil_trout.notifications, :count).by(1)
|
||||
.and change(walterwhite.notifications, :count).by(1)
|
||||
.and change(user.notifications, :count).by(0)
|
||||
.and not_change(user.notifications, :count)
|
||||
end
|
||||
|
||||
it "sends to correct user when user has a full name that matches another user's username" do
|
||||
@@ -478,7 +478,7 @@ describe PostAlerter do
|
||||
topic: topic
|
||||
)
|
||||
}.to change(user_with_matching_full_name.notifications, :count).by(1)
|
||||
.and change(evil_trout.notifications, :count).by(0)
|
||||
.and not_change(evil_trout.notifications, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -550,12 +550,12 @@ describe PostAlerter do
|
||||
end
|
||||
|
||||
it 'does not notify unrelated users' do
|
||||
expect { post }.to change(evil_trout.notifications, :count).by(0)
|
||||
expect { post }.not_to change(evil_trout.notifications, :count)
|
||||
end
|
||||
|
||||
it 'does not work if user here exists' do
|
||||
Fabricate(:user, username: SiteSetting.here_mention)
|
||||
expect { post }.to change(other_post.user.notifications, :count).by(0)
|
||||
expect { post }.not_to change(other_post.user.notifications, :count)
|
||||
end
|
||||
|
||||
it 'notifies users who replied' do
|
||||
@@ -564,7 +564,7 @@ describe PostAlerter do
|
||||
|
||||
expect { post }
|
||||
.to change(other_post.user.notifications, :count).by(1)
|
||||
.and change(post2.user.notifications, :count).by(0)
|
||||
.and not_change(post2.user.notifications, :count)
|
||||
.and change(post3.user.notifications, :count).by(1)
|
||||
end
|
||||
|
||||
@@ -604,14 +604,14 @@ describe PostAlerter do
|
||||
|
||||
expect {
|
||||
create_post_with_alerts(raw: "Hello, @group-alt should not trigger a notification?")
|
||||
}.to change(evil_trout.notifications, :count).by(0)
|
||||
}.not_to change(evil_trout.notifications, :count)
|
||||
|
||||
expect(GroupMention.count).to eq(2)
|
||||
|
||||
group.update_columns(mentionable_level: Group::ALIAS_LEVELS[:members_mods_and_admins])
|
||||
expect {
|
||||
create_post_with_alerts(raw: "Hello @group you are not mentionable")
|
||||
}.to change(evil_trout.notifications, :count).by(0)
|
||||
}.not_to change(evil_trout.notifications, :count)
|
||||
|
||||
expect(GroupMention.count).to eq(3)
|
||||
|
||||
@@ -1316,7 +1316,7 @@ describe PostAlerter do
|
||||
reply = Fabricate(:post, topic: topic, reply_to_post_number: 1)
|
||||
|
||||
NotificationEmailer.expects(:process_notification).never
|
||||
expect { PostAlerter.post_created(reply) }.to change(user.notifications, :count).by(0)
|
||||
expect { PostAlerter.post_created(reply) }.not_to change(user.notifications, :count)
|
||||
|
||||
category.mailinglist_mirror = false
|
||||
NotificationEmailer.expects(:process_notification).once
|
||||
@@ -1479,7 +1479,7 @@ describe PostAlerter do
|
||||
expect { PostRevisor.new(post).revise!(Fabricate(:user), tags: [other_tag.name, watched_tag.name]) }.to change { Notification.where(user_id: user.id).count }.by(1)
|
||||
expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(1)
|
||||
|
||||
expect { PostRevisor.new(post).revise!(Fabricate(:user), tags: [watched_tag.name, other_tag.name]) }.to change { Notification.count }.by(0)
|
||||
expect { PostRevisor.new(post).revise!(Fabricate(:user), tags: [watched_tag.name, other_tag.name]) }.not_to change { Notification.count }
|
||||
expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(1)
|
||||
end
|
||||
|
||||
@@ -1741,7 +1741,7 @@ describe PostAlerter do
|
||||
incoming_email_post = create_post_with_incoming
|
||||
topic = incoming_email_post.topic
|
||||
post = Fabricate(:post, topic: topic)
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.to change { ActionMailer::Base.deliveries.size }.by(0)
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.not_to change { ActionMailer::Base.deliveries.size }
|
||||
end
|
||||
|
||||
it "does not send a group smtp email if SiteSetting.enable_smtp is false" do
|
||||
@@ -1749,14 +1749,14 @@ describe PostAlerter do
|
||||
incoming_email_post = create_post_with_incoming
|
||||
topic = incoming_email_post.topic
|
||||
post = Fabricate(:post, topic: topic)
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.to change { ActionMailer::Base.deliveries.size }.by(0)
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.not_to change { ActionMailer::Base.deliveries.size }
|
||||
end
|
||||
|
||||
it "does not send group smtp emails for a whisper" do
|
||||
incoming_email_post = create_post_with_incoming
|
||||
topic = incoming_email_post.topic
|
||||
post = Fabricate(:post, topic: topic, post_type: Post.types[:whisper])
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.to change { ActionMailer::Base.deliveries.size }.by(0)
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.not_to change { ActionMailer::Base.deliveries.size }
|
||||
end
|
||||
|
||||
it "sends the group smtp email job with a delay of personal_email_time_window_seconds" do
|
||||
@@ -1783,7 +1783,7 @@ describe PostAlerter do
|
||||
post = Fabricate(:post, topic: topic)
|
||||
Fabricate(:incoming_email, post: post, topic: topic, is_auto_generated: true)
|
||||
expect_not_enqueued_with(job: :group_smtp_email) do
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.to change { ActionMailer::Base.deliveries.size }.by(0)
|
||||
expect { PostAlerter.new.after_save_post(post, true) }.not_to change { ActionMailer::Base.deliveries.size }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1974,12 +1974,12 @@ describe PostAlerter do
|
||||
User.count # the two new cc addresses have users created
|
||||
}.by(2).and change {
|
||||
TopicAllowedUser.where(topic: topic).count # and they are added as topic allowed users
|
||||
}.by(2).and change {
|
||||
}.by(2).and not_change {
|
||||
# but they are not sent emails because they were cc'd on an email.
|
||||
# no group smtp message is sent because the OP is not sent an email,
|
||||
# they made this post.
|
||||
ActionMailer::Base.deliveries.size
|
||||
}.by(0).and change {
|
||||
}.and change {
|
||||
Notification.count # and they are still sent their normal discourse notification
|
||||
}.by(2)
|
||||
|
||||
|
||||
@@ -77,11 +77,11 @@ describe UsernameChanger do
|
||||
|
||||
expect do
|
||||
UsernameChanger.change(myself, "HanSolo", myself)
|
||||
end.to change { UserHistory.count }.by(0) # make sure it does not log a dupe
|
||||
end.not_to change { UserHistory.count } # make sure it does not log a dupe
|
||||
|
||||
expect do
|
||||
UsernameChanger.change(myself, user.username, myself)
|
||||
end.to change { UserHistory.count }.by(0) # does not log if the username already exists
|
||||
end.not_to change { UserHistory.count } # does not log if the username already exists
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user