A platform for community discussion. Free, open, simple.
DEV: Don’t use `change { … }.by(0)` in specs
Loïc Guitaut91b6b5eee7a1
diff --git a/Gemfile.lock b/Gemfile.lockindex 34ff4f912f3..a974329832f 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -7,7 +7,7 @@ GITGITremote: https://github.com/discourse/rubocop-discourse.git- revision: 0de6d72891fea488cae22332505e4e3f26b4e157+ revision: e44784b759aef45306b0eaee29ddadd8ca5b40a6specs:rubocop-discourse (2.5.0)rubocop (>= 1.1.0)diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rbindex b3e436f7d0c..a82c3eb9b24 100644--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb@@ -490,7 +490,7 @@ describe DiscourseNarrativeBot::TrackSelector dopost.update!(raw: 'thanks @discobot!')expect { described_class.new(:reply, user, post_id: post.id).select }- .to change { PostAction.count }.by(0)+ .not_to change { PostAction.count }new_post = Post.lastexpect(new_post.raw).to eq(random_mention_reply)diff --git a/plugins/discourse-narrative-bot/spec/user_spec.rb b/plugins/discourse-narrative-bot/spec/user_spec.rbindex 2514a86561f..4018ea4acf8 100644--- a/plugins/discourse-narrative-bot/spec/user_spec.rb+++ b/plugins/discourse-narrative-bot/spec/user_spec.rb@@ -121,7 +121,7 @@ describe User doexpect {user.user_option.save!}.to change { Topic.count }.by(-1)- .and change { UserHistory.count }.by(0)+ .and not_change { UserHistory.count }.and change { user.unread_high_priority_notifications }.by(-1).and change { user.notifications.count }.by(-1)enddiff --git a/spec/import_export/importer_spec.rb b/spec/import_export/importer_spec.rbindex 6ccbe13af16..78c52eccb7a 100644--- a/spec/import_export/importer_spec.rb+++ b/spec/import_export/importer_spec.rb@@ -26,8 +26,8 @@ describe ImportExport::Importer doexpect {import(data)- }.to change { Category.count }.by(0)- .and change { Group.count }.by(0)+ }.to not_change { Category.count }+ .and not_change { Group.count }.and change { Topic.count }.by(2).and change { User.count }.by(2)end@@ -43,7 +43,7 @@ describe ImportExport::Importer do}.to change { Category.count }.by(6).and change { Group.count }.by(2).and change { Topic.count }.by(6)- .and change { User.count }.by(0)+ .and not_change { User.count }endit 'works with sub-sub-categories' do@@ -91,10 +91,10 @@ describe ImportExport::Importer doexpect {import(data)- }.to change { Category.count }.by(0)+ }.to not_change { Category.count }.and change { Group.count }.by(2)- .and change { Topic.count }.by(0)- .and change { User.count }.by(0)+ .and not_change { Topic.count }+ .and not_change { User.count }endit 'all' dodiff --git a/spec/integration/topic_thumbnail_spec.rb b/spec/integration/topic_thumbnail_spec.rbindex 5a2bcdcba45..db67e603b14 100644--- a/spec/integration/topic_thumbnail_spec.rb+++ b/spec/integration/topic_thumbnail_spec.rb@@ -69,7 +69,7 @@ describe "Topic Thumbnails" do# Request againexpect dotopic_json = get_topic- end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(0)+ end.not_to change { Jobs::GenerateTopicThumbnails.jobs.size }thumbnails = topic_json["thumbnails"]@@ -110,7 +110,7 @@ describe "Topic Thumbnails" do# Request againexpect dotopic_json = get_topic- end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(0)+ end.not_to change { Jobs::GenerateTopicThumbnails.jobs.size }thumbnails = topic_json["thumbnails"]diff --git a/spec/jobs/activation_reminder_emails_spec.rb b/spec/jobs/activation_reminder_emails_spec.rbindex 3179c8bc119..32a59ff9f4b 100644--- a/spec/jobs/activation_reminder_emails_spec.rb+++ b/spec/jobs/activation_reminder_emails_spec.rb@@ -14,7 +14,7 @@ describe Jobs::ActivationReminderEmails do.and change { user.email_tokens.count }.by(1)expect(user.custom_fields['activation_reminder']).to eq("t")- expect { described_class.new.execute({}) }.to change { ActionMailer::Base.deliveries.size }.by(0)+ expect { described_class.new.execute({}) }.not_to change { ActionMailer::Base.deliveries.size }user.activateexpect(user.reload.custom_fields['activation_reminder']).to eq(nil)@@ -24,15 +24,15 @@ describe Jobs::ActivationReminderEmails douser = Fabricate(:user, active: true, created_at: created_at)expect { described_class.new.execute({}) }- .to change { ActionMailer::Base.deliveries.size }.by(0)- .and change { user.email_tokens.count }.by(0)+ .to not_change { ActionMailer::Base.deliveries.size }+ .and not_change { user.email_tokens.count }endit 'should not email staged users' douser = Fabricate(:user, active: false, staged: true, created_at: created_at)expect { described_class.new.execute({}) }- .to change { ActionMailer::Base.deliveries.size }.by(0)- .and change { user.email_tokens.count }.by(0)+ .to not_change { ActionMailer::Base.deliveries.size }+ .and not_change { user.email_tokens.count }endenddiff --git a/spec/jobs/clean_up_post_reply_keys_spec.rb b/spec/jobs/clean_up_post_reply_keys_spec.rbindex 06697e19ae2..10594c1ac5e 100644--- a/spec/jobs/clean_up_post_reply_keys_spec.rb+++ b/spec/jobs/clean_up_post_reply_keys_spec.rb@@ -11,7 +11,7 @@ RSpec.describe Jobs::CleanUpPostReplyKeys doSiteSetting.disallow_reply_by_email_after_days = 0expect { Jobs::CleanUpPostReplyKeys.new.execute({}) }- .to change { PostReplyKey.count }.by(0)+ .not_to change { PostReplyKey.count }SiteSetting.disallow_reply_by_email_after_days = 2diff --git a/spec/jobs/clean_up_uploads_spec.rb b/spec/jobs/clean_up_uploads_spec.rbindex 202b77ff711..d6448995d68 100644--- a/spec/jobs/clean_up_uploads_spec.rb+++ b/spec/jobs/clean_up_uploads_spec.rb@@ -63,7 +63,7 @@ describe Jobs::CleanUpUploads doit 'does not delete uploads skipped by an unused callback' doexpect doJobs::CleanUpUploads.new.execute(nil)- end.to change { Upload.count }.by(0)+ end.not_to change { Upload.count }expect(Upload.exists?(id: expired_upload.id)).to eq(true)end@@ -97,7 +97,7 @@ describe Jobs::CleanUpUploads doit 'does not delete uploads that are in use by callback' doexpect doJobs::CleanUpUploads.new.execute(nil)- end.to change { Upload.count }.by(0)+ end.not_to change { Upload.count }expect(Upload.exists?(id: expired_upload.id)).to eq(true)enddiff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rbindex fa86b1c2ed9..9410c2e2c60 100644--- a/spec/jobs/emit_web_hook_event_spec.rb+++ b/spec/jobs/emit_web_hook_event_spec.rb@@ -120,7 +120,7 @@ describe Jobs::EmitWebHookEvent doweb_hook_id: post_hook.id,event_type: described_class::PING_EVENT)- end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(0)+ end.not_to change { Jobs::EmitWebHookEvent.jobs.size }endit 'properly logs error on rescue' dodiff --git a/spec/jobs/export_user_archive_spec.rb b/spec/jobs/export_user_archive_spec.rbindex 27b490904d8..42fb4f2fdec 100644--- a/spec/jobs/export_user_archive_spec.rb+++ b/spec/jobs/export_user_archive_spec.rb@@ -102,7 +102,7 @@ describe Jobs::ExportUserArchive doJobs::ExportUserArchive.new.execute(user_id: user.id,)- end.to change { Upload.count }.by(0)+ end.not_to change { Upload.count }system_message = user.topics_allowed.lastexpect(system_message.title).to eq(I18n.t("system_messages.csv_export_failed.subject_template"))diff --git a/spec/jobs/notify_mailing_list_subscribers_spec.rb b/spec/jobs/notify_mailing_list_subscribers_spec.rbindex a9bea5a8676..271bc26a45a 100644--- a/spec/jobs/notify_mailing_list_subscribers_spec.rb+++ b/spec/jobs/notify_mailing_list_subscribers_spec.rb@@ -220,7 +220,7 @@ describe Jobs::NotifyMailingListSubscribers doJobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)- end.to change { SkippedEmailLog.count }.by(0)+ end.not_to change { SkippedEmailLog.count }endenddiff --git a/spec/jobs/old_keys_reminder_spec.rb b/spec/jobs/old_keys_reminder_spec.rbindex 26407b31fc1..8459ca1b06a 100644--- a/spec/jobs/old_keys_reminder_spec.rb+++ b/spec/jobs/old_keys_reminder_spec.rb@@ -56,10 +56,10 @@ describe Jobs::OldKeysReminder doendit 'does not send message when send_old_credential_reminder_days is set to 0 or no old keys' do- expect { described_class.new.execute({}) }.to change { Post.count }.by(0)+ expect { described_class.new.execute({}) }.not_to change { Post.count }SiteSetting.send_old_credential_reminder_days = '0'freeze_time 2.years.from_now- expect { described_class.new.execute({}) }.to change { Post.count }.by(0)+ expect { described_class.new.execute({}) }.not_to change { Post.count }endit 'does not send a message if already exists' do@@ -67,9 +67,9 @@ describe Jobs::OldKeysReminder dofreeze_time 2.years.from_nowexpect { described_class.new.execute({}) }.to change { Post.count }.by(1)Topic.last.trash!- expect { described_class.new.execute({}) }.to change { Post.count }.by(0)+ expect { described_class.new.execute({}) }.not_to change { Post.count }freeze_time 1.years.from_now- expect { described_class.new.execute({}) }.to change { Post.count }.by(0)+ expect { described_class.new.execute({}) }.not_to change { Post.count }freeze_time 3.days.from_nowexpect { described_class.new.execute({}) }.to change { Post.count }.by(1)enddiff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rbindex 187e93e6881..c44f00f95e0 100644--- a/spec/jobs/pull_hotlinked_images_spec.rb+++ b/spec/jobs/pull_hotlinked_images_spec.rb@@ -43,7 +43,7 @@ describe Jobs::PullHotlinkedImages doexpect doJobs::PullHotlinkedImages.new.execute(post_id: post.id)- end.to change { Upload.count }.by(0)+ end.not_to change { Upload.count }endit 'does nothing if there are no large images to pull' do@@ -59,10 +59,9 @@ describe Jobs::PullHotlinkedImages dopost = Fabricate(:post, raw: "<img src='#{image_url}'>")stub_image_size- expect do- Jobs::PullHotlinkedImages.new.execute(post_id: post.id)- end.to change { Upload.count }.by(1) &- change { UserHistory.count }.by(0) # Should not add to the staff log+ expect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }+ .to change { Upload.count }.by(1)+ .and not_change { UserHistory.count } # Should not add to the staff logexpect(post.reload.raw).to eq("<img src=\"#{Upload.last.short_url}\">")end@@ -110,7 +109,7 @@ describe Jobs::PullHotlinkedImages doexpect dopost.rebake!- end.to change { Upload.count }.by(0) # We alread have the upload+ end.not_to change { Upload.count } # We alread have the uploadexpect(post.reload.raw).to eq("<img src=\"#{Upload.last.short_url}\">")end@@ -278,7 +277,7 @@ describe Jobs::PullHotlinkedImages do.to change { Upload.count }.by(1)expect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }- .to change { Upload.count }.by(0)+ .not_to change { Upload.count }endendenddiff --git a/spec/jobs/pull_user_profile_hotlinked_images_spec.rb b/spec/jobs/pull_user_profile_hotlinked_images_spec.rbindex 748709e35d0..c6b77439057 100644--- a/spec/jobs/pull_user_profile_hotlinked_images_spec.rb+++ b/spec/jobs/pull_user_profile_hotlinked_images_spec.rb@@ -23,7 +23,7 @@ describe Jobs::PullUserProfileHotlinkedImages doendit 'handles nil bio' do- expect { Jobs::PullUserProfileHotlinkedImages.new.execute(user_id: user.id) }.to change { Upload.count }.by(0)+ expect { Jobs::PullUserProfileHotlinkedImages.new.execute(user_id: user.id) }.not_to change { Upload.count }expect(user.user_profile.reload.bio_cooked).to eq(nil)endenddiff --git a/spec/jobs/remove_banner_spec.rb b/spec/jobs/remove_banner_spec.rbindex d07188abe8d..b9026f1afcf 100644--- a/spec/jobs/remove_banner_spec.rb+++ b/spec/jobs/remove_banner_spec.rb@@ -8,7 +8,7 @@ describe Jobs::RemoveBanner doit 'doesn’t enqueue a future job to remove it' doexpect dotopic.make_banner!(user)- end.to change { Jobs::RemoveBanner.jobs.size }.by(0)+ end.not_to change { Jobs::RemoveBanner.jobs.size }endend@@ -42,7 +42,7 @@ describe Jobs::RemoveBanner doexpect dotopic.make_banner!(user, 'xxx')end.to raise_error(Discourse::InvalidParameters)- end.to change { Jobs::RemoveBanner.jobs.size }.by(0)+ end.not_to change { Jobs::RemoveBanner.jobs.size }endendenddiff --git a/spec/jobs/update_gravatar_spec.rb b/spec/jobs/update_gravatar_spec.rbindex 83ef9d5e17f..98addd98066 100644--- a/spec/jobs/update_gravatar_spec.rb+++ b/spec/jobs/update_gravatar_spec.rb@@ -39,7 +39,7 @@ describe Jobs::UpdateGravatar doSiteSetting.automatically_download_gravatars = trueexpect { user.refresh_avatar }- .to change { Jobs::UpdateGravatar.jobs.count }.by(0)+ .not_to change { Jobs::UpdateGravatar.jobs.count }user.reloadexpect(user.uploaded_avatar_id).to eq(nil)diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rbindex cb8c6708a98..f15b02a7d72 100644--- a/spec/jobs/user_email_spec.rb+++ b/spec/jobs/user_email_spec.rb@@ -607,7 +607,7 @@ describe Jobs::UserEmail donotification_id: notification.id,post_id: post.id)- end.to change { SkippedEmailLog.count }.by(0)+ end.not_to change { SkippedEmailLog.count }endit "sends critical email" dodiff --git a/spec/lib/auth/managed_authenticator_spec.rb b/spec/lib/auth/managed_authenticator_spec.rbindex 23c196d6bf6..8a7fbf1844c 100644--- a/spec/lib/auth/managed_authenticator_spec.rb+++ b/spec/lib/auth/managed_authenticator_spec.rb@@ -182,7 +182,7 @@ describe Auth::ManagedAuthenticator doit "schedules the job upon update correctly" do# No image supplied, do not scheduleexpect { result = authenticator.after_authenticate(hash) }- .to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0)+ .not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }# Image supplied, scheduleexpect { result = authenticator.after_authenticate(hash.deep_merge(info: { image: "https://some.domain/image.jpg" })) }@@ -192,7 +192,7 @@ describe Auth::ManagedAuthenticator douser.user_avatar = Fabricate(:user_avatar, custom_upload: Fabricate(:upload))user.save!expect { result = authenticator.after_authenticate(hash.deep_merge(info: { image: "https://some.domain/image.jpg" })) }- .to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0)+ .not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }endend@@ -226,7 +226,7 @@ describe Auth::ManagedAuthenticator doit "doesn't schedule with no image" doexpect { result = authenticator.after_create_account(user, create_auth_result(extra_data: create_hash)) }- .to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0)+ .not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }endit "schedules with image" dodiff --git a/spec/lib/backup_restore/backuper_spec.rb b/spec/lib/backup_restore/backuper_spec.rbindex 6c9e64829fb..affb41081ab 100644--- a/spec/lib/backup_restore/backuper_spec.rb+++ b/spec/lib/backup_restore/backuper_spec.rb@@ -29,7 +29,7 @@ describe BackupRestore::Backuper doexpect { backuper.send(:notify_user) }.to change { Topic.private_messages.count }.by(1)- .and change { Upload.count }.by(0)+ .and not_change { Upload.count }endexpect(Topic.last.first_post.raw).to include("```text\n[2010-01-01 12:00:00] Notifying 'system' of the end of the backup...\n```")@@ -63,7 +63,7 @@ describe BackupRestore::Backuper doexpect { backuper.send(:notify_user) }.to change { Topic.private_messages.count }.by(1)- .and change { Upload.count }.by(0)+ .and not_change { Upload.count }endexpect(Topic.last.first_post.raw).to include("```text\n...\n[2010-01-01 12:00:00] Line 10\n[2010-01-01 12:00:00] Notifying 'system' of the end of the backup...\n```")diff --git a/spec/lib/backup_restore/uploads_restorer_spec.rb b/spec/lib/backup_restore/uploads_restorer_spec.rbindex 92cdf1ef669..02db3c50902 100644--- a/spec/lib/backup_restore/uploads_restorer_spec.rb+++ b/spec/lib/backup_restore/uploads_restorer_spec.rb@@ -172,8 +172,8 @@ describe BackupRestore::UploadsRestorer dostore_class.any_instance.expects(:copy_from).with(path).onceexpect { subject.restore(directory) }- .to change { OptimizedImage.count }.by(0)- .and change { Jobs::CreateAvatarThumbnails.jobs.size }.by(0)+ .to not_change { OptimizedImage.count }+ .and not_change { Jobs::CreateAvatarThumbnails.jobs.size }.and change { Post.where(baked_version: nil).count }.by(1)endenddiff --git a/spec/lib/email/processor_spec.rb b/spec/lib/email/processor_spec.rbindex f789670b0cc..931aff5b11c 100644--- a/spec/lib/email/processor_spec.rb+++ b/spec/lib/email/processor_spec.rb@@ -84,7 +84,7 @@ describe Email::Processor doexpect {Email::Processor.process!(mail2)- }.to change { EmailLog.count }.by(0)+ }.not_to change { EmailLog.count }freeze_time(Date.today + 1)@@ -148,7 +148,7 @@ describe Email::Processor doexpect {Email::Processor.process!(mail)- }.to change { EmailLog.count }.by(0)+ }.not_to change { EmailLog.count }endenddiff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rbindex eb441e5cff5..73b0fb873d0 100644--- a/spec/lib/email/receiver_spec.rb+++ b/spec/lib/email/receiver_spec.rb@@ -1112,7 +1112,7 @@ describe Email::Receiver doendit "creates the reply when the sender and referenced messsage id are known" do- expect { process(:email_reply_to_group_email_username) }.to change { topic.posts.count }.by(1).and change { Topic.count }.by(0)+ expect { process(:email_reply_to_group_email_username) }.to change { topic.posts.count }.by(1).and not_change { Topic.count }endend@@ -1266,7 +1266,7 @@ describe Email::Receiver doreply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id)expect doEmail::Receiver.new(reply_email).process!- end.to change { Topic.count }.by(0).and change { Post.count }.by(1)+ end.to not_change { Topic.count }.and change { Post.count }.by(1)reply_post = Post.lastexpect(reply_post.reply_to_user).to eq(user_in_group)@@ -1294,7 +1294,7 @@ describe Email::Receiver doreply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id)expect doEmail::Receiver.new(reply_email).process!- end.to change { Topic.count }.by(0).and change { Post.count }.by(1)+ end.to not_change { Topic.count }.and change { Post.count }.by(1)reply_post = Post.lastexpect(reply_post.topic_id).to eq(original_inbound_email_topic.id)@@ -1333,24 +1333,24 @@ describe Email::Receiver doendit "creates a reply when the sender and referenced message id are known" do- expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1).and change { Topic.count }.by(0)+ expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1).and not_change { Topic.count }endit "creates a new topic when the sender is not known and the group does not allow unknown senders to reply to topics" doIncomingEmail.where(message_id: '[email protected]').update(cc_addresses: '[email protected]')group.update(allow_unknown_sender_topic_replies: false)- expect { process(:email_reply_2) }.to change { topic.posts.count }.by(0).and change { Topic.count }.by(1)+ expect { process(:email_reply_2) }.to not_change { topic.posts.count }.and change { Topic.count }.by(1)endit "creates a new topic when the referenced message id is not known" doIncomingEmail.where(message_id: '[email protected]').update(message_id: '[email protected]')- expect { process(:email_reply_2) }.to change { topic.posts.count }.by(0).and change { Topic.count }.by(1)+ expect { process(:email_reply_2) }.to not_change { topic.posts.count }.and change { Topic.count }.by(1)endit "includes the sender on the topic when the message id is known, the sender is not known, and the group allows unknown senders to reply to topics" doIncomingEmail.where(message_id: '[email protected]').update(cc_addresses: '[email protected]')group.update(allow_unknown_sender_topic_replies: true)- expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1).and change { Topic.count }.by(0)+ expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1).and not_change { Topic.count }endcontext "when the sender is not in the topic allowed users" do@@ -1362,7 +1362,7 @@ describe Email::Receiver doit "adds them to the topic at the same time" doIncomingEmail.where(message_id: '[email protected]').update(cc_addresses: '[email protected]')group.update(allow_unknown_sender_topic_replies: true)- expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1).and change { Topic.count }.by(0)+ expect { process(:email_reply_2) }.to change { topic.posts.count }.by(1).and not_change { Topic.count }endendend@@ -2097,8 +2097,8 @@ describe Email::Receiver doit "makes all posts in same topic" doexpect { receive(email_1) }.to change { Topic.count }.by(1).and change { Post.where(post_type: Post.types[:regular]).count }.by(1)- expect { post_2 }.to change { Topic.count }.by(0).and change { Post.where(post_type: Post.types[:regular]).count }.by(1)- expect { receive(email_3) }.to change { Topic.count }.by(0).and change { Post.where(post_type: Post.types[:regular]).count }.by(1)+ expect { post_2 }.to not_change { Topic.count }.and change { Post.where(post_type: Post.types[:regular]).count }.by(1)+ expect { receive(email_3) }.to not_change { Topic.count }.and change { Post.where(post_type: Post.types[:regular]).count }.by(1)endenddiff --git a/spec/lib/email/sender_spec.rb b/spec/lib/email/sender_spec.rbindex f2615b96dab..1dea67595f3 100644--- a/spec/lib/email/sender_spec.rb+++ b/spec/lib/email/sender_spec.rb@@ -778,12 +778,12 @@ describe Email::Sender doexpect(message.header[header]).to eq(nil)expect(post_reply_key.user_id).to eq(user.id)expect(post_reply_key.post_id).to eq(post.id)- expect { email_sender.send }.to change { PostReplyKey.count }.by(0)+ expect { email_sender.send }.not_to change { PostReplyKey.count }endit 'should find existing key' doexisting_post_reply_key = PostReplyKey.create(post_id: post.id, user_id: user.id)- expect { email_sender.send }.to change { PostReplyKey.count }.by(0)+ expect { email_sender.send }.not_to change { PostReplyKey.count }post_reply_key = PostReplyKey.lastexpect(post_reply_key).to eq(existing_post_reply_key)enddiff --git a/spec/lib/imap/sync_spec.rb b/spec/lib/imap/sync_spec.rbindex 7873aedd79b..d5ff2d02457 100644--- a/spec/lib/imap/sync_spec.rb+++ b/spec/lib/imap/sync_spec.rb@@ -128,9 +128,9 @@ describe Imap::Sync do.and change { IncomingEmail.count }.by(1)expect { sync_handler.process }- .to change { Topic.count }.by(0)- .and change { Post.where(post_type: Post.types[:regular]).count }.by(0)- .and change { IncomingEmail.count }.by(0)+ .to not_change { Topic.count }+ .and not_change { Post.where(post_type: Post.types[:regular]).count }+ .and not_change { IncomingEmail.count }endit 'creates a new incoming email if the message ID does not match the receiver post id regex' do@@ -155,9 +155,9 @@ describe Imap::Sync doincoming_email = Fabricate(:incoming_email, message_id: message_id)expect { sync_handler.process }- .to change { Topic.count }.by(0)- .and change { Post.where(post_type: Post.types[:regular]).count }.by(0)- .and change { IncomingEmail.count }.by(0)+ .to not_change { Topic.count }+ .and not_change { Post.where(post_type: Post.types[:regular]).count }+ .and not_change { IncomingEmail.count }incoming_email.reloadexpect(incoming_email.message_id).to eq(message_id)@@ -248,7 +248,7 @@ describe Imap::Sync do)expect { sync_handler.process }- .to change { Topic.count }.by(0)+ .to not_change { Topic.count }.and change { Post.where(post_type: Post.types[:regular]).count }.by(1).and change { IncomingEmail.count }.by(1)@@ -276,9 +276,9 @@ describe Imap::Sync do)expect { sync_handler.process }- .to change { Topic.count }.by(0)- .and change { Post.where(post_type: Post.types[:regular]).count }.by(0)- .and change { IncomingEmail.count }.by(0)+ .to not_change { Topic.count }+ .and not_change { Post.where(post_type: Post.types[:regular]).count }+ .and not_change { IncomingEmail.count }topic = Topic.lastexpect(topic.title).to eq(subject)@@ -618,9 +618,9 @@ describe Imap::Sync do)expect { sync_handler.process }- .to change { Topic.count }.by(0)- .and change { Post.where(post_type: Post.types[:regular]).count }.by(0)- .and change { IncomingEmail.count }.by(0)+ .to not_change { Topic.count }+ .and not_change { Post.where(post_type: Post.types[:regular]).count }+ .and not_change { IncomingEmail.count }imap_data = Topic.last.incoming_email.pluck(:imap_uid_validity, :imap_uid, :imap_group_id)expect(imap_data).to contain_exactly([2, 111, group.id], [2, 222, group.id])diff --git a/spec/lib/post_creator_spec.rb b/spec/lib/post_creator_spec.rbindex 7ff0b6fd00f..748cd6a2250 100644--- a/spec/lib/post_creator_spec.rb+++ b/spec/lib/post_creator_spec.rb@@ -323,7 +323,7 @@ describe PostCreator docreator = PostCreator.new(user, basic_topic_params.merge(advance_draft: false))Draft.set(user, Draft::NEW_TOPIC, 0, 'test')expect(Draft.where(user: user).size).to eq(1)- expect { creator.create }.to change { Draft.count }.by(0)+ expect { creator.create }.not_to change { Draft.count }endit "updates topic stats" do@@ -487,7 +487,7 @@ describe PostCreator doendit "doesn't create tags" do- expect { @post = creator_with_tags.create }.to change { Tag.count }.by(0)+ expect { @post = creator_with_tags.create }.not_to change { Tag.count }expect(@post.topic&.tags&.size).to eq(nil)endend@@ -524,7 +524,7 @@ describe PostCreator doit "only uses existing tags" doexisting_tag1 = Fabricate(:tag, name: tag_names[1])- expect { @post = creator_with_tags.create }.to change { Tag.count }.by(0)+ expect { @post = creator_with_tags.create }.not_to change { Tag.count }expect(@post.topic.tags.map(&:name)).to eq([existing_tag1.name])endend@@ -786,7 +786,7 @@ describe PostCreator doSiteSetting.review_every_post = trueGroupMessage.stubs(:create)- expect { creator.create }.to change(ReviewablePost, :count).by(0)+ expect { creator.create }.not_to change(ReviewablePost, :count)endend@@ -1478,7 +1478,7 @@ describe PostCreator doexpect {PostCreator.create!(user, raw: "", topic_id: topic.id, skip_validations: true)- }.to change { user2.notifications.count }.by(0)+ }.not_to change { user2.notifications.count }expect {PostCreator.create!(user, raw: "hello world", topic_id: topic.id, skip_validations: true)@@ -1864,7 +1864,7 @@ describe PostCreator doit 'does not create a reviewable post if the post is not valid' dopost_creator = PostCreator.new(user, title: '', raw: '')- expect { post_creator.create }.to change(ReviewablePost, :count).by(0)+ expect { post_creator.create }.not_to change(ReviewablePost, :count)endendenddiff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rbindex 5d6718d006e..7d0aa2183ed 100644--- a/spec/lib/post_revisor_spec.rb+++ b/spec/lib/post_revisor_spec.rb@@ -148,7 +148,7 @@ describe PostRevisor doSiteSetting.disable_tags_edit_notifications = trueexpect { subject.revise!(admin, tags: ['new-tag']) }- .to change { Notification.count }.by(0)+ .not_to change { Notification.count }endend@@ -1278,8 +1278,8 @@ describe PostRevisor do{ title: "updated title for my topic" },keep_existing_draft: true)- }.to change { Draft.where(user: user, draft_key: draft_key).first.sequence }.by(0)- .and change { DraftSequence.where(user_id: user.id, draft_key: draft_key).first.sequence }.by(0)+ }.to not_change { Draft.where(user: user, draft_key: draft_key).first.sequence }+ .and not_change { DraftSequence.where(user_id: user.id, draft_key: draft_key).first.sequence }expect {PostRevisor.new(post).revise!(@@ -1307,7 +1307,7 @@ describe PostRevisor doit 'does nothing when a staff member edits a post' doadmin = Fabricate(:admin)- expect { revisor.revise!(admin, { raw: 'updated body' }) }.to change(ReviewablePost, :count).by(0)+ expect { revisor.revise!(admin, { raw: 'updated body' }) }.not_to change(ReviewablePost, :count)endit 'skips grace period edits' do@@ -1315,7 +1315,7 @@ describe PostRevisor doexpect {revisor.revise!(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 10.seconds)- }.to change(ReviewablePost, :count).by(0)+ }.not_to change(ReviewablePost, :count)endendenddiff --git a/spec/lib/seed_data/categories_spec.rb b/spec/lib/seed_data/categories_spec.rbindex c2ef1f62450..91b9aed7c64 100644--- a/spec/lib/seed_data/categories_spec.rb+++ b/spec/lib/seed_data/categories_spec.rb@@ -42,8 +42,8 @@ describe SeedData::Categories doit "does not create another category" doexpect { create_category }- .to change { Category.count }.by(0)- .and change { Topic.count }.by(0)+ .to not_change { Category.count }+ .and not_change { Topic.count }endit "creates a missing 'About Category' topic" do@@ -51,7 +51,7 @@ describe SeedData::Categories doTopic.delete(category.topic_id)expect { create_category }- .to change { Category.count }.by(0)+ .to not_change { Category.count }.and change { Topic.count }.by(1)category.reload@@ -103,7 +103,7 @@ describe SeedData::Categories doexpect(category.category_groups.first).to have_attributes(permissions(:trust_level_2, :full))expect { create_category("lounge_category_id") }- .to change { CategoryGroup.count }.by(0)+ .not_to change { CategoryGroup.count }category.reloadexpect(category.category_groups.first).to have_attributes(permissions(:trust_level_2, :full))diff --git a/spec/lib/topics_bulk_action_spec.rb b/spec/lib/topics_bulk_action_spec.rbindex 1edcc92163a..732e5be9bff 100644--- a/spec/lib/topics_bulk_action_spec.rb+++ b/spec/lib/topics_bulk_action_spec.rb@@ -49,7 +49,7 @@ describe TopicsBulkAction doFabricate(:topic_user, user: user, topic: topic3, last_read_post_number: 1)expect doTopicsBulkAction.new(user, [Topic.all.pluck(:id)], type: "dismiss_topics").perform!- end.to change { DismissedTopicUser.count }.by(0)+ end.not_to change { DismissedTopicUser.count }endit 'dismisses when topic user without last_read_post_number' dodiff --git a/spec/lib/upload_creator_spec.rb b/spec/lib/upload_creator_spec.rbindex bd240a5de0b..bd244d2f5a2 100644--- a/spec/lib/upload_creator_spec.rb+++ b/spec/lib/upload_creator_spec.rb@@ -31,7 +31,7 @@ RSpec.describe UploadCreator doexpect doUploadCreator.new(file, "utf-8\n.txt").create_for(user2.id)- end.to change { Upload.count }.by(0)+ end.not_to change { Upload.count }expect(user.user_uploads.count).to eq(1)expect(user2.user_uploads.count).to eq(1)diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rbindex 31a4a9bc627..fc722d8c3a1 100644--- a/spec/models/notification_spec.rb+++ b/spec/models/notification_spec.rb@@ -106,7 +106,7 @@ describe Notification dopost_args[:topic].notify_muted!(user)expect {Fabricate(:post, user: user2, topic: post.topic, raw: 'hello @' + user.username)- }.to change(user.notifications, :count).by(0)+ }.not_to change(user.notifications, :count)endenddiff --git a/spec/models/screened_ip_address_spec.rb b/spec/models/screened_ip_address_spec.rbindex d2d12eac578..74f5cc12700 100644--- a/spec/models/screened_ip_address_spec.rb+++ b/spec/models/screened_ip_address_spec.rb@@ -340,7 +340,7 @@ describe ScreenedIpAddress doexpect(ScreenedIpAddress.pluck(:ip_address)).not_to include("1.1.1.1", "1.1.1.2", "1.1.1.3")# expect roll up to be stable- expect { ScreenedIpAddress.roll_up }.to change { ScreenedIpAddress.count }.by(0)+ expect { ScreenedIpAddress.roll_up }.not_to change { ScreenedIpAddress.count }endit 'rolls up IPv6 addresses' do@@ -358,10 +358,10 @@ describe ScreenedIpAddress doexpect(ScreenedIpAddress.pluck(:ip_address)).not_to include("2001:db8:3333:4441:5555:6666:7777:8888", "2001:db8:3333:4441:5555:6666:7777:8889", "2001:db8:3333:4441:5555:6666:7777:888a")# expect roll up to be stable- expect { ScreenedIpAddress.roll_up }.to change { ScreenedIpAddress.count }.by(0)+ expect { ScreenedIpAddress.roll_up }.not_to change { ScreenedIpAddress.count }Fabricate(:screened_ip_address, ip_address: "2001:db8:3333:4442::/64")- expect { ScreenedIpAddress.roll_up }.to change { ScreenedIpAddress.count }.by(0)+ expect { ScreenedIpAddress.roll_up }.not_to change { ScreenedIpAddress.count }Fabricate(:screened_ip_address, ip_address: "2001:db8:3333:4443::/64")expect { ScreenedIpAddress.roll_up }.to change { ScreenedIpAddress.count }.by(-2)@@ -369,7 +369,7 @@ describe ScreenedIpAddress doexpect(ScreenedIpAddress.pluck(:ip_address)).not_to include("2001:db8:3333:4441::/64", "2001:db8:3333:4442::/64", "2001:db8:3333:4443::/64")# expect roll up to be stable- expect { ScreenedIpAddress.roll_up }.to change { ScreenedIpAddress.count }.by(0)+ expect { ScreenedIpAddress.roll_up }.not_to change { ScreenedIpAddress.count }endendenddiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex 910c9e8e86c..5594c81e422 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -806,7 +806,7 @@ describe Topic doexpect { topic.invite(user, user1.username) }.to change { Notification.count }.by(1)- .and change { Post.where(post_type: Post.types[:small_action]).count }.by(0)+ .and not_change { Post.where(post_type: Post.types[:small_action]).count }endcontext "from a muted user" do@@ -1787,7 +1787,7 @@ describe Topic doexpect dotopic.change_category_to_id(new_category.id)- end.to change { Notification.count }.by(0)+ end.not_to change { Notification.count }expect(topic.category_id).to eq(new_category.id)end@@ -1823,7 +1823,7 @@ describe Topic doexpect dotopic.change_category_to_id(new_category.id)- end.to change { Notification.count }.by(0)+ end.not_to change { Notification.count }endend@@ -1856,7 +1856,7 @@ describe Topic doit 'should not set a topic timer' doexpect { topic.change_category_to_id(new_category.id) }- .to change { TopicTimer.with_deleted.count }.by(0)+ .not_to change { TopicTimer.with_deleted.count }expect(topic.closed).to eq(true)expect(topic.reload.category).to eq(new_category)diff --git a/spec/models/topic_tag_spec.rb b/spec/models/topic_tag_spec.rbindex 585d06ddf2d..9e18aa547f5 100644--- a/spec/models/topic_tag_spec.rb+++ b/spec/models/topic_tag_spec.rb@@ -19,7 +19,7 @@ describe TopicTag doexpect {topic_tag- }.to change(tag, :topic_count).by(0)+ }.not_to change(tag, :topic_count)endend@@ -39,7 +39,7 @@ describe TopicTag doexpect {topic_tag.destroy- }.to change(tag, :topic_count).by(0)+ }.not_to change(tag, :topic_count)endenddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 572bef65d6c..b641ade93d8 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -319,7 +319,7 @@ RSpec.describe User douser.update(admin: true)expect {user.grant_admin!- }.to change { Jobs::SendSystemMessage.jobs.count }.by 0+ }.not_to change { Jobs::SendSystemMessage.jobs.count }endend@@ -2681,7 +2681,7 @@ RSpec.describe User doexpect douser.update_ip_address!('0.0.0.1')- end.to change { UserIpAddressHistory.where(user_id: user.id).count }.by(0)+ end.not_to change { UserIpAddressHistory.where(user_id: user.id).count }expect(UserIpAddressHistory.where(user_id: user.id).pluck(:ip_address).map(&:to_s)diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rbindex 2f391272d11..c603f3980b9 100644--- a/spec/models/web_hook_spec.rb+++ b/spec/models/web_hook_spec.rb@@ -604,7 +604,7 @@ describe WebHook doit 'shouldn’t trigger when the user is demoted' doexpect {another_user.change_trust_level!(another_user.trust_level - 1)- }.to change { Jobs::EmitWebHookEvent.jobs.length }.by(0)+ }.not_to change { Jobs::EmitWebHookEvent.jobs.length }endenddiff --git a/spec/requests/admin/site_settings_controller_spec.rb b/spec/requests/admin/site_settings_controller_spec.rbindex cc9859a54eb..93ec96c861d 100644--- a/spec/requests/admin/site_settings_controller_spec.rb+++ b/spec/requests/admin/site_settings_controller_spec.rb@@ -84,7 +84,7 @@ describe Admin::SiteSettingsController doput "/admin/site_settings/default_email_in_reply_to.json", params: {default_email_in_reply_to: false}- }.to change { UserOption.where(email_in_reply_to: false).count }.by(0)+ }.not_to change { UserOption.where(email_in_reply_to: false).count }endit 'should update `email_digests` column in existing user options' do@@ -153,7 +153,7 @@ describe Admin::SiteSettingsController doput "/admin/site_settings/default_categories_watching.json", params: {default_categories_watching: category_ids.last(2).join("|")}- }.to change { CategoryUser.where(category_id: category_ids.first, notification_level: watching).count }.by(0)+ }.not_to change { CategoryUser.where(category_id: category_ids.first, notification_level: watching).count }expect(response.status).to eq(200)expect(CategoryUser.where(category_id: category_ids.last, notification_level: watching).count).to eq(0)@@ -204,7 +204,7 @@ describe Admin::SiteSettingsController doput "/admin/site_settings/default_tags_watching.json", params: {default_tags_watching: tags.last(2).pluck(:name).join("|")}- }.to change { TagUser.where(tag_id: tags.first.id, notification_level: watching).count }.by(0)+ }.not_to change { TagUser.where(tag_id: tags.first.id, notification_level: watching).count }expect(TagUser.where(tag_id: tags.last.id, notification_level: watching).count).to eq(0)enddiff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rbindex b3656ea9677..3e2cfc096e4 100644--- a/spec/requests/admin/users_controller_spec.rb+++ b/spec/requests/admin/users_controller_spec.rb@@ -154,7 +154,7 @@ RSpec.describe Admin::UsersController dosuspend_until: 5.hours.from_now,reason: "because I said so"}- end.to change { Jobs::CriticalUserEmail.jobs.size }.by(0)+ end.not_to change { Jobs::CriticalUserEmail.jobs.size }expect(response.status).to eq(200)diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rbindex 9c45c296b26..05d87ec5787 100644--- a/spec/requests/groups_controller_spec.rb+++ b/spec/requests/groups_controller_spec.rb@@ -1352,7 +1352,7 @@ describe GroupsController doit "does not notify users when the param is not present" doexpect {put "/groups/#{group.id}/members.json", params: { usernames: user2.username }- }.to change { Topic.where(archetype: "private_message").count }.by(0)+ }.not_to change { Topic.where(archetype: "private_message").count }expect(response.status).to eq(200)end@@ -1453,7 +1453,7 @@ describe GroupsController doexpect doput "/groups/#{group.id}/members.json",params: { user_emails: [user1.email, user2.email, user3.email].join(",") }- end.to change { group.users.count }.by(0)+ end.not_to change { group.users.count }expect(response.status).to eq(422)@@ -1469,7 +1469,7 @@ describe GroupsController doexpect doput "/groups/#{group.id}/members.json",params: { user_emails: [user1.email, user2.email].join(",") }- end.to change { group.reload.users.count }.by(0)+ end.not_to change { group.reload.users.count }expect(response.status).to eq(422)diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rbindex d04b10535d5..da602dc3977 100644--- a/spec/requests/invites_controller_spec.rb+++ b/spec/requests/invites_controller_spec.rb@@ -124,7 +124,7 @@ describe InvitesController douser.update!(email: "[email protected]")invite.update!(email: nil, domain: 'discourse.org')- expect { get "/invites/#{invite.invite_key}" }.to change { InvitedUser.count }.by(0)+ expect { get "/invites/#{invite.invite_key}" }.not_to change { InvitedUser.count }expect(response).to redirect_to("/")end@@ -132,7 +132,7 @@ describe InvitesController doit "redirects to root if a tries to view an invite meant for a specific email that is not the user's" doinvite.update_columns(email: "[email protected]")- expect { get "/invites/#{invite.invite_key}" }.to change { InvitedUser.count }.by(0)+ expect { get "/invites/#{invite.invite_key}" }.not_to change { InvitedUser.count }expect(response).to redirect_to("/")end@@ -773,7 +773,7 @@ describe InvitesController doit 'does not activate user if email token is missing' doexpect doput "/invites/show/#{invite.invite_key}.json", params: { password: 'verystrongpassword' }- end.to change { UserAuthToken.count }.by(0)+ end.not_to change { UserAuthToken.count }expect(response.status).to eq(200)diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex b5a13613327..f7b1e3e9228 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1583,7 +1583,7 @@ RSpec.describe TopicsController doput "/t/#{topic.slug}/#{topic.id}.json", params: {tags: [tag.name]}- end.to change { topic.reload.first_post.revisions.count }.by(0)+ end.not_to change { topic.reload.first_post.revisions.count }expect(response.status).to eq(200)enddiff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rbindex 27a789cbca8..c38569abd52 100644--- a/spec/serializers/topic_view_serializer_spec.rb+++ b/spec/serializers/topic_view_serializer_spec.rb@@ -81,7 +81,7 @@ describe TopicViewSerializer doexpect dojson = serialize_topic(topic, user)- end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(0)+ end.not_to change { Jobs::GenerateTopicThumbnails.jobs.size }endenddiff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex b626b89c86e..ae57bf6d14e 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -240,7 +240,7 @@ describe PostAlerter docreate_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)endendend@@ -353,7 +353,7 @@ describe PostAlerter doexpect {PostAlerter.post_created(post)- }.to change(evil_trout.notifications, :count).by(0)+ }.not_to change(evil_trout.notifications, :count)endit 'does not notify for ignored users' do@@ -362,7 +362,7 @@ describe PostAlerter doexpect {PostAlerter.post_created(post)- }.to change(evil_trout.notifications, :count).by(0)+ }.not_to change(evil_trout.notifications, :count)endit '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.destroyexpect {@@ -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)endit "sends to correct user when user has a full name that matches another user's username" do@@ -478,7 +478,7 @@ describe PostAlerter dotopic: 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)endendend@@ -550,12 +550,12 @@ describe PostAlerter doendit '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)endit 'does not work if user here exists' doFabricate(: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)endit 'notifies users who replied' do@@ -564,7 +564,7 @@ describe PostAlerter doexpect { 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 doexpect {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 doreply = 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 = falseNotificationEmailer.expects(:process_notification).once@@ -1479,7 +1479,7 @@ describe PostAlerter doexpect { 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 doincoming_email_post = create_post_with_incomingtopic = incoming_email_post.topicpost = 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 }endit "does not send a group smtp email if SiteSetting.enable_smtp is false" do@@ -1749,14 +1749,14 @@ describe PostAlerter doincoming_email_post = create_post_with_incomingtopic = incoming_email_post.topicpost = 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 }endit "does not send group smtp emails for a whisper" doincoming_email_post = create_post_with_incomingtopic = incoming_email_post.topicpost = 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 }endit "sends the group smtp email job with a delay of personal_email_time_window_seconds" do@@ -1783,7 +1783,7 @@ describe PostAlerter dopost = 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 }endend@@ -1974,12 +1974,12 @@ describe PostAlerter doUser.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)diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rbindex e532c5fed3c..98b28977f71 100644--- a/spec/services/username_changer_spec.rb+++ b/spec/services/username_changer_spec.rb@@ -77,11 +77,11 @@ describe UsernameChanger doexpect doUsernameChanger.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 dupeexpect doUsernameChanger.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 existsendenddiff --git a/spec/support/negated_matcher.rb b/spec/support/negated_matcher.rbnew file mode 100644index 00000000000..8ef4694982d--- /dev/null+++ b/spec/support/negated_matcher.rb@@ -0,0 +1,3 @@+# frozen_string_literal: true++RSpec::Matchers.define_negated_matcher :not_change, :change