From 91b6b5eee7a193b9adcff07131c8e1904e29b61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Tue, 19 Jul 2022 16:03:03 +0200 Subject: [PATCH] =?UTF-8?q?DEV:=20Don=E2=80=99t=20use=20`change=20{=20?= =?UTF-8?q?=E2=80=A6=20}.by(0)`=20in=20specs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 2 +- .../track_selector_spec.rb | 2 +- .../discourse-narrative-bot/spec/user_spec.rb | 2 +- spec/import_export/importer_spec.rb | 12 +++--- spec/integration/topic_thumbnail_spec.rb | 4 +- spec/jobs/activation_reminder_emails_spec.rb | 10 ++--- spec/jobs/clean_up_post_reply_keys_spec.rb | 2 +- spec/jobs/clean_up_uploads_spec.rb | 4 +- spec/jobs/emit_web_hook_event_spec.rb | 2 +- spec/jobs/export_user_archive_spec.rb | 2 +- .../notify_mailing_list_subscribers_spec.rb | 2 +- spec/jobs/old_keys_reminder_spec.rb | 8 ++-- spec/jobs/pull_hotlinked_images_spec.rb | 13 +++---- ...pull_user_profile_hotlinked_images_spec.rb | 2 +- spec/jobs/remove_banner_spec.rb | 4 +- spec/jobs/update_gravatar_spec.rb | 2 +- spec/jobs/user_email_spec.rb | 2 +- spec/lib/auth/managed_authenticator_spec.rb | 6 +-- spec/lib/backup_restore/backuper_spec.rb | 4 +- .../backup_restore/uploads_restorer_spec.rb | 4 +- spec/lib/email/processor_spec.rb | 4 +- spec/lib/email/receiver_spec.rb | 20 +++++----- spec/lib/email/sender_spec.rb | 4 +- spec/lib/imap/sync_spec.rb | 26 ++++++------- spec/lib/post_creator_spec.rb | 12 +++--- spec/lib/post_revisor_spec.rb | 10 ++--- spec/lib/seed_data/categories_spec.rb | 8 ++-- spec/lib/topics_bulk_action_spec.rb | 2 +- spec/lib/upload_creator_spec.rb | 2 +- spec/models/notification_spec.rb | 2 +- spec/models/screened_ip_address_spec.rb | 8 ++-- spec/models/topic_spec.rb | 8 ++-- spec/models/topic_tag_spec.rb | 4 +- spec/models/user_spec.rb | 4 +- spec/models/web_hook_spec.rb | 2 +- .../admin/site_settings_controller_spec.rb | 6 +-- spec/requests/admin/users_controller_spec.rb | 2 +- spec/requests/groups_controller_spec.rb | 6 +-- spec/requests/invites_controller_spec.rb | 6 +-- spec/requests/topics_controller_spec.rb | 2 +- .../serializers/topic_view_serializer_spec.rb | 2 +- spec/services/post_alerter_spec.rb | 38 +++++++++---------- spec/services/username_changer_spec.rb | 4 +- spec/support/negated_matcher.rb | 3 ++ 44 files changed, 138 insertions(+), 136 deletions(-) create mode 100644 spec/support/negated_matcher.rb diff --git a/Gemfile.lock b/Gemfile.lock index 34ff4f912f3..a974329832f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/discourse/rubocop-discourse.git - revision: 0de6d72891fea488cae22332505e4e3f26b4e157 + revision: e44784b759aef45306b0eaee29ddadd8ca5b40a6 specs: 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.rb index 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 do post.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.last expect(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.rb index 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 do expect { 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) end diff --git a/spec/import_export/importer_spec.rb b/spec/import_export/importer_spec.rb index 6ccbe13af16..78c52eccb7a 100644 --- a/spec/import_export/importer_spec.rb +++ b/spec/import_export/importer_spec.rb @@ -26,8 +26,8 @@ describe ImportExport::Importer do expect { 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 } end it 'works with sub-sub-categories' do @@ -91,10 +91,10 @@ describe ImportExport::Importer do expect { 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 } end it 'all' do diff --git a/spec/integration/topic_thumbnail_spec.rb b/spec/integration/topic_thumbnail_spec.rb index 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 again expect do topic_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 again expect do topic_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.rb index 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.activate expect(user.reload.custom_fields['activation_reminder']).to eq(nil) @@ -24,15 +24,15 @@ describe Jobs::ActivationReminderEmails do user = 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 } end it 'should not email staged users' do user = 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 } end end diff --git a/spec/jobs/clean_up_post_reply_keys_spec.rb b/spec/jobs/clean_up_post_reply_keys_spec.rb index 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 do SiteSetting.disallow_reply_by_email_after_days = 0 expect { Jobs::CleanUpPostReplyKeys.new.execute({}) } - .to change { PostReplyKey.count }.by(0) + .not_to change { PostReplyKey.count } SiteSetting.disallow_reply_by_email_after_days = 2 diff --git a/spec/jobs/clean_up_uploads_spec.rb b/spec/jobs/clean_up_uploads_spec.rb index 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 do it 'does not delete uploads skipped by an unused callback' do expect do Jobs::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 do it 'does not delete uploads that are in use by callback' do expect do Jobs::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 diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rb index 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 do web_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 } end it 'properly logs error on rescue' do diff --git a/spec/jobs/export_user_archive_spec.rb b/spec/jobs/export_user_archive_spec.rb index 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 do Jobs::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.last expect(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.rb index 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 do Jobs::NotifyMailingListSubscribers.new.execute( post_id: post.id ) - end.to change { SkippedEmailLog.count }.by(0) + end.not_to change { SkippedEmailLog.count } end end diff --git a/spec/jobs/old_keys_reminder_spec.rb b/spec/jobs/old_keys_reminder_spec.rb index 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 do end it '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 } end it 'does not send a message if already exists' do @@ -67,9 +67,9 @@ describe Jobs::OldKeysReminder do freeze_time 2.years.from_now expect { 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_now expect { described_class.new.execute({}) }.to change { Post.count }.by(1) end diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index 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 do expect do Jobs::PullHotlinkedImages.new.execute(post_id: post.id) - end.to change { Upload.count }.by(0) + end.not_to change { Upload.count } end it 'does nothing if there are no large images to pull' do @@ -59,10 +59,9 @@ describe Jobs::PullHotlinkedImages do post = Fabricate(:post, raw: "") 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 log expect(post.reload.raw).to eq("") end @@ -110,7 +109,7 @@ describe Jobs::PullHotlinkedImages do expect do post.rebake! - end.to change { Upload.count }.by(0) # We alread have the upload + end.not_to change { Upload.count } # We alread have the upload expect(post.reload.raw).to eq("") 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 } end end end diff --git a/spec/jobs/pull_user_profile_hotlinked_images_spec.rb b/spec/jobs/pull_user_profile_hotlinked_images_spec.rb index 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 do end it '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) end end diff --git a/spec/jobs/remove_banner_spec.rb b/spec/jobs/remove_banner_spec.rb index d07188abe8d..b9026f1afcf 100644 --- a/spec/jobs/remove_banner_spec.rb +++ b/spec/jobs/remove_banner_spec.rb @@ -8,7 +8,7 @@ describe Jobs::RemoveBanner do it 'doesn’t enqueue a future job to remove it' do expect do topic.make_banner!(user) - end.to change { Jobs::RemoveBanner.jobs.size }.by(0) + end.not_to change { Jobs::RemoveBanner.jobs.size } end end @@ -42,7 +42,7 @@ describe Jobs::RemoveBanner do expect do topic.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 } end end end diff --git a/spec/jobs/update_gravatar_spec.rb b/spec/jobs/update_gravatar_spec.rb index 83ef9d5e17f..98addd98066 100644 --- a/spec/jobs/update_gravatar_spec.rb +++ b/spec/jobs/update_gravatar_spec.rb @@ -39,7 +39,7 @@ describe Jobs::UpdateGravatar do SiteSetting.automatically_download_gravatars = true expect { user.refresh_avatar } - .to change { Jobs::UpdateGravatar.jobs.count }.by(0) + .not_to change { Jobs::UpdateGravatar.jobs.count } user.reload expect(user.uploaded_avatar_id).to eq(nil) diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index cb8c6708a98..f15b02a7d72 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -607,7 +607,7 @@ describe Jobs::UserEmail do notification_id: notification.id, post_id: post.id ) - end.to change { SkippedEmailLog.count }.by(0) + end.not_to change { SkippedEmailLog.count } end it "sends critical email" do diff --git a/spec/lib/auth/managed_authenticator_spec.rb b/spec/lib/auth/managed_authenticator_spec.rb index 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 do it "schedules the job upon update correctly" do # No image supplied, do not schedule expect { result = authenticator.after_authenticate(hash) } - .to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0) + .not_to change { Jobs::DownloadAvatarFromUrl.jobs.count } # Image supplied, schedule expect { result = authenticator.after_authenticate(hash.deep_merge(info: { image: "https://some.domain/image.jpg" })) } @@ -192,7 +192,7 @@ describe Auth::ManagedAuthenticator do user.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 } end end @@ -226,7 +226,7 @@ describe Auth::ManagedAuthenticator do it "doesn't schedule with no image" do expect { 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 } end it "schedules with image" do diff --git a/spec/lib/backup_restore/backuper_spec.rb b/spec/lib/backup_restore/backuper_spec.rb index 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 do expect { backuper.send(:notify_user) } .to change { Topic.private_messages.count }.by(1) - .and change { Upload.count }.by(0) + .and not_change { Upload.count } end expect(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 do expect { backuper.send(:notify_user) } .to change { Topic.private_messages.count }.by(1) - .and change { Upload.count }.by(0) + .and not_change { Upload.count } end expect(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.rb index 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 do store_class.any_instance.expects(:copy_from).with(path).once expect { 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) end end diff --git a/spec/lib/email/processor_spec.rb b/spec/lib/email/processor_spec.rb index f789670b0cc..931aff5b11c 100644 --- a/spec/lib/email/processor_spec.rb +++ b/spec/lib/email/processor_spec.rb @@ -84,7 +84,7 @@ describe Email::Processor do expect { 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 do expect { Email::Processor.process!(mail) - }.to change { EmailLog.count }.by(0) + }.not_to change { EmailLog.count } end end diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rb index eb441e5cff5..73b0fb873d0 100644 --- a/spec/lib/email/receiver_spec.rb +++ b/spec/lib/email/receiver_spec.rb @@ -1112,7 +1112,7 @@ describe Email::Receiver do end it "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 } end end @@ -1266,7 +1266,7 @@ describe Email::Receiver do reply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id) expect do Email::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.last expect(reply_post.reply_to_user).to eq(user_in_group) @@ -1294,7 +1294,7 @@ describe Email::Receiver do reply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id) expect do Email::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.last expect(reply_post.topic_id).to eq(original_inbound_email_topic.id) @@ -1333,24 +1333,24 @@ describe Email::Receiver do end it "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 } end it "creates a new topic when the sender is not known and the group does not allow unknown senders to reply to topics" do IncomingEmail.where(message_id: '34@foo.bar.mail').update(cc_addresses: 'three@foo.com') 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) end it "creates a new topic when the referenced message id is not known" do IncomingEmail.where(message_id: '34@foo.bar.mail').update(message_id: '99@foo.bar.mail') - 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) end it "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" do IncomingEmail.where(message_id: '34@foo.bar.mail').update(cc_addresses: 'three@foo.com') 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 } end context "when the sender is not in the topic allowed users" do @@ -1362,7 +1362,7 @@ describe Email::Receiver do it "adds them to the topic at the same time" do IncomingEmail.where(message_id: '34@foo.bar.mail').update(cc_addresses: 'three@foo.com') 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 } end end end @@ -2097,8 +2097,8 @@ describe Email::Receiver do it "makes all posts in same topic" do expect { 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) end end diff --git a/spec/lib/email/sender_spec.rb b/spec/lib/email/sender_spec.rb index f2615b96dab..1dea67595f3 100644 --- a/spec/lib/email/sender_spec.rb +++ b/spec/lib/email/sender_spec.rb @@ -778,12 +778,12 @@ describe Email::Sender do expect(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 } end it 'should find existing key' do existing_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.last expect(post_reply_key).to eq(existing_post_reply_key) end diff --git a/spec/lib/imap/sync_spec.rb b/spec/lib/imap/sync_spec.rb index 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 } end it '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 do incoming_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.reload expect(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.last expect(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.rb index 7ff0b6fd00f..748cd6a2250 100644 --- a/spec/lib/post_creator_spec.rb +++ b/spec/lib/post_creator_spec.rb @@ -323,7 +323,7 @@ describe PostCreator do creator = 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 } end it "updates topic stats" do @@ -487,7 +487,7 @@ describe PostCreator do end it "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) end end @@ -524,7 +524,7 @@ describe PostCreator do it "only uses existing tags" do existing_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]) end end @@ -786,7 +786,7 @@ describe PostCreator do SiteSetting.review_every_post = true GroupMessage.stubs(:create) - expect { creator.create }.to change(ReviewablePost, :count).by(0) + expect { creator.create }.not_to change(ReviewablePost, :count) end end @@ -1478,7 +1478,7 @@ describe PostCreator do expect { 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 do it 'does not create a reviewable post if the post is not valid' do post_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) end end end diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb index 5d6718d006e..7d0aa2183ed 100644 --- a/spec/lib/post_revisor_spec.rb +++ b/spec/lib/post_revisor_spec.rb @@ -148,7 +148,7 @@ describe PostRevisor do SiteSetting.disable_tags_edit_notifications = true expect { subject.revise!(admin, tags: ['new-tag']) } - .to change { Notification.count }.by(0) + .not_to change { Notification.count } end end @@ -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 do it 'does nothing when a staff member edits a post' do admin = 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) end it 'skips grace period edits' do @@ -1315,7 +1315,7 @@ describe PostRevisor do expect { 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) end end end diff --git a/spec/lib/seed_data/categories_spec.rb b/spec/lib/seed_data/categories_spec.rb index 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 do it "does not create another category" do expect { create_category } - .to change { Category.count }.by(0) - .and change { Topic.count }.by(0) + .to not_change { Category.count } + .and not_change { Topic.count } end it "creates a missing 'About Category' topic" do @@ -51,7 +51,7 @@ describe SeedData::Categories do Topic.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 do expect(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.reload expect(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.rb index 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 do Fabricate(:topic_user, user: user, topic: topic3, last_read_post_number: 1) expect do TopicsBulkAction.new(user, [Topic.all.pluck(:id)], type: "dismiss_topics").perform! - end.to change { DismissedTopicUser.count }.by(0) + end.not_to change { DismissedTopicUser.count } end it 'dismisses when topic user without last_read_post_number' do diff --git a/spec/lib/upload_creator_spec.rb b/spec/lib/upload_creator_spec.rb index bd240a5de0b..bd244d2f5a2 100644 --- a/spec/lib/upload_creator_spec.rb +++ b/spec/lib/upload_creator_spec.rb @@ -31,7 +31,7 @@ RSpec.describe UploadCreator do expect do UploadCreator.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.rb index 31a4a9bc627..fc722d8c3a1 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -106,7 +106,7 @@ describe Notification do post_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) end end diff --git a/spec/models/screened_ip_address_spec.rb b/spec/models/screened_ip_address_spec.rb index 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 do expect(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 } end it 'rolls up IPv6 addresses' do @@ -358,10 +358,10 @@ describe ScreenedIpAddress do expect(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 do expect(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 } end end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 910c9e8e86c..5594c81e422 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -806,7 +806,7 @@ describe Topic do expect { 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 } end context "from a muted user" do @@ -1787,7 +1787,7 @@ describe Topic do expect do topic.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 do expect do topic.change_category_to_id(new_category.id) - end.to change { Notification.count }.by(0) + end.not_to change { Notification.count } end end @@ -1856,7 +1856,7 @@ describe Topic do it 'should not set a topic timer' do expect { 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.rb index 585d06ddf2d..9e18aa547f5 100644 --- a/spec/models/topic_tag_spec.rb +++ b/spec/models/topic_tag_spec.rb @@ -19,7 +19,7 @@ describe TopicTag do expect { topic_tag - }.to change(tag, :topic_count).by(0) + }.not_to change(tag, :topic_count) end end @@ -39,7 +39,7 @@ describe TopicTag do expect { topic_tag.destroy - }.to change(tag, :topic_count).by(0) + }.not_to change(tag, :topic_count) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 572bef65d6c..b641ade93d8 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -319,7 +319,7 @@ RSpec.describe User do user.update(admin: true) expect { user.grant_admin! - }.to change { Jobs::SendSystemMessage.jobs.count }.by 0 + }.not_to change { Jobs::SendSystemMessage.jobs.count } end end @@ -2681,7 +2681,7 @@ RSpec.describe User do expect do user.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.rb index 2f391272d11..c603f3980b9 100644 --- a/spec/models/web_hook_spec.rb +++ b/spec/models/web_hook_spec.rb @@ -604,7 +604,7 @@ describe WebHook do it 'shouldn’t trigger when the user is demoted' do expect { 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 } end end diff --git a/spec/requests/admin/site_settings_controller_spec.rb b/spec/requests/admin/site_settings_controller_spec.rb index 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 do put "/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 } end it 'should update `email_digests` column in existing user options' do @@ -153,7 +153,7 @@ describe Admin::SiteSettingsController do put "/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 do put "/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) end diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb index 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 do suspend_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.rb index 9c45c296b26..05d87ec5787 100644 --- a/spec/requests/groups_controller_spec.rb +++ b/spec/requests/groups_controller_spec.rb @@ -1352,7 +1352,7 @@ describe GroupsController do it "does not notify users when the param is not present" do expect { 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 do expect do put "/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 do expect do put "/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.rb index d04b10535d5..da602dc3977 100644 --- a/spec/requests/invites_controller_spec.rb +++ b/spec/requests/invites_controller_spec.rb @@ -124,7 +124,7 @@ describe InvitesController do user.update!(email: "someguy@discourse.com") 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 do it "redirects to root if a tries to view an invite meant for a specific email that is not the user's" do invite.update_columns(email: "notuseremail@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 @@ -773,7 +773,7 @@ describe InvitesController do it 'does not activate user if email token is missing' do expect do put "/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.rb index b5a13613327..f7b1e3e9228 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1583,7 +1583,7 @@ RSpec.describe TopicsController do put "/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) end diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rb index 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 do expect do json = serialize_topic(topic, user) - end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(0) + end.not_to change { Jobs::GenerateTopicThumbnails.jobs.size } end end diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index b626b89c86e..ae57bf6d14e 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -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) diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rb index e532c5fed3c..98b28977f71 100644 --- a/spec/services/username_changer_spec.rb +++ b/spec/services/username_changer_spec.rb @@ -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 diff --git a/spec/support/negated_matcher.rb b/spec/support/negated_matcher.rb new file mode 100644 index 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