DEV: Don’t use change { … }.by(0) in specs

This commit is contained in:
Loïc Guitaut 2022-07-19 16:03:03 +02:00 committed by Loïc Guitaut
parent 3bfc254c4e
commit 91b6b5eee7
44 changed files with 138 additions and 136 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"))

View File

@ -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

View File

@ -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

View File

@ -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: "<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 log
expect(post.reload.raw).to eq("<img src=\"#{Upload.last.short_url}\">")
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("<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 }
end
end
end

View File

@ -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

View File

@ -8,7 +8,7 @@ describe Jobs::RemoveBanner do
it 'doesnt 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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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```")

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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])

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -604,7 +604,7 @@ describe WebHook do
it 'shouldnt 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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,3 @@
# frozen_string_literal: true
RSpec::Matchers.define_negated_matcher :not_change, :change