DEV: Fix mocha deprecations (#18828)

It now supports strict keyword argument matching by default.
This commit is contained in:
Jarek Radosz 2022-11-02 10:47:59 +01:00 committed by GitHub
parent b9bcb225f2
commit c32fe340f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 45 additions and 40 deletions

View File

@ -62,7 +62,7 @@ RSpec.describe ::Jobs::Base do
end
it 'delegates the process call to execute' do
::Jobs::Base.any_instance.expects(:execute).with('hello' => 'world')
::Jobs::Base.any_instance.expects(:execute).with({ 'hello' => 'world' })
::Jobs::Base.new.perform('hello' => 'world', 'sync_exec' => true)
end

View File

@ -106,7 +106,7 @@ RSpec.describe Jobs do
end
it "executes the job right away" do
Jobs::ProcessPost.any_instance.expects(:perform).with("post_id" => 1, "sync_exec" => true, "current_site_id" => "default")
Jobs::ProcessPost.any_instance.expects(:perform).with({ "post_id" => 1, "sync_exec" => true, "current_site_id" => "default" })
Jobs.enqueue(:process_post, post_id: 1)
end

View File

@ -190,7 +190,7 @@ RSpec.describe DiscoursePluginRegistry do
describe '.register_archetype' do
it "delegates archetypes to the Archetype component" do
Archetype.expects(:register).with('threaded', hello: 123)
Archetype.expects(:register).with('threaded', { hello: 123 })
registry_instance.register_archetype('threaded', hello: 123)
end
end

View File

@ -31,11 +31,12 @@ RSpec.describe FileStore::S3Store do
it "returns an absolute schemaless url" do
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
s3_bucket.expects(:object).with(regexp_matches(%r{original/\d+X.*/#{upload.sha1}\.png})).returns(s3_object)
s3_object.expects(:put).with(
s3_object.expects(:put).with({
acl: "public-read",
cache_control: "max-age=31556952, public, immutable",
content_type: "image/png",
body: uploaded_file).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
body: uploaded_file
}).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
expect(store.store_upload(uploaded_file, upload)).to match(
%r{//s3-upload-bucket\.s3\.dualstack\.us-west-1\.amazonaws\.com/original/\d+X.*/#{upload.sha1}\.png}
@ -69,12 +70,13 @@ RSpec.describe FileStore::S3Store do
s3_helper.expects(:s3_bucket).returns(s3_bucket)
s3_bucket.expects(:object).with(regexp_matches(%r{original/\d+X.*/#{upload.sha1}\.pdf})).returns(s3_object)
s3_object.expects(:put).with(
s3_object.expects(:put).with({
acl: "private",
cache_control: "max-age=31556952, public, immutable",
content_type: "application/pdf",
content_disposition: "attachment; filename=\"#{upload.original_filename}\"; filename*=UTF-8''#{upload.original_filename}",
body: uploaded_file).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
body: uploaded_file
}).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
expect(store.store_upload(uploaded_file, upload)).to match(
%r{//s3-upload-bucket\.s3\.dualstack\.us-west-1\.amazonaws\.com/original/\d+X.*/#{upload.sha1}\.pdf}
@ -86,11 +88,12 @@ RSpec.describe FileStore::S3Store do
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
s3_bucket.expects(:object).with(regexp_matches(%r{original/\d+X.*/#{upload.sha1}\.png})).returns(s3_object).at_least_once
s3_object.expects(:put).with(
s3_object.expects(:put).with({
acl: "public-read",
cache_control: "max-age=31556952, public, immutable",
content_type: "image/png",
body: uploaded_file).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
body: uploaded_file
}).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
expect(store.store_upload(uploaded_file, upload)).to match(
%r{//s3-upload-bucket\.s3\.dualstack\.us-west-1\.amazonaws\.com/original/\d+X.*/#{upload.sha1}\.png}

View File

@ -7,7 +7,7 @@ RSpec.describe Onebox::JsonLd do
invalid_json = "{\"@type\":invalid-json}"
doc = Nokogiri::HTML("<script type=\"application/ld+json\">#{invalid_json}</script>")
Discourse.expects(:warn_exception).with(
instance_of(JSON::ParserError), { message: "Error parsing JSON-LD: #{invalid_json}" }
instance_of(JSON::ParserError), message: "Error parsing JSON-LD: #{invalid_json}"
)
json_ld = described_class.new(doc)

View File

@ -70,7 +70,7 @@ RSpec.describe "S3Helper" do
'some' => 'testing'
}.each do |bucket_name, prefix|
s3_helper = S3Helper.new(bucket_name, "", client: client)
Aws::S3::Bucket.any_instance.expects(:objects).with(prefix: prefix)
Aws::S3::Bucket.any_instance.expects(:objects).with({ prefix: prefix })
s3_helper.list('testing')
end
end

View File

@ -53,14 +53,14 @@ RSpec.describe SiteSettings::YamlLoader do
end
it "can load client settings" do
receiver.expects(:setting).with('category1', 'title', 'Discourse', client: true)
receiver.expects(:setting).with('category2', 'tos_url', '', client: true)
receiver.expects(:setting).with('category2', 'must_approve_users', false, client: true)
receiver.expects(:setting).with('category1', 'title', 'Discourse', { client: true })
receiver.expects(:setting).with('category2', 'tos_url', '', { client: true })
receiver.expects(:setting).with('category2', 'must_approve_users', false, { client: true })
receiver.load_yaml(client)
end
it "can load enum settings" do
receiver.expects(:setting).with('email', 'default_email_digest_frequency', 7, enum: 'DigestEmailSiteSetting')
receiver.expects(:setting).with('email', 'default_email_digest_frequency', 7, { enum: 'DigestEmailSiteSetting' })
receiver.load_yaml(enum)
end
@ -76,7 +76,7 @@ RSpec.describe SiteSettings::YamlLoader do
end
it "can load settings with locale default" do
receiver.expects(:setting).with('search', 'min_search_term_length', 3, min: 2, client: true, locale_default: { zh_CN: 2, zh_TW: 2 })
receiver.expects(:setting).with('search', 'min_search_term_length', 3, { min: 2, client: true, locale_default: { zh_CN: 2, zh_TW: 2 } })
receiver.load_yaml(locale_default)
end
end

View File

@ -1,13 +1,10 @@
# encoding: utf-8
# frozen_string_literal: true
require 'theme_store/git_importer'
RSpec.describe ThemeStore::GitImporter do
describe "#import" do
let(:url) { "https://github.com/example/example.git" }
let(:trailing_slash_url) { "https://github.com/example/example/" }
let(:ssh_url) { "git@github.com:example/example.git" }
@ -27,7 +24,7 @@ RSpec.describe ThemeStore::GitImporter do
.expects(:execute_command)
.with(
{ "GIT_TERMINAL_PROMPT" => "0" },
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, { timeout: 20 }
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, timeout: 20
)
importer = ThemeStore::GitImporter.new(url)
@ -39,7 +36,7 @@ RSpec.describe ThemeStore::GitImporter do
.expects(:execute_command)
.with(
{ "GIT_TERMINAL_PROMPT" => "0" },
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, { timeout: 20 }
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, timeout: 20
)
importer = ThemeStore::GitImporter.new(trailing_slash_url)
@ -51,7 +48,7 @@ RSpec.describe ThemeStore::GitImporter do
.expects(:execute_command)
.with(
{ "GIT_SSH_COMMAND" => "ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no" },
"git", "clone", "ssh://git@github.com/example/example.git", @temp_folder, { timeout: 20 }
"git", "clone", "ssh://git@github.com/example/example.git", @temp_folder, timeout: 20
)
importer = ThemeStore::GitImporter.new(ssh_url, private_key: "private_key")
@ -63,7 +60,7 @@ RSpec.describe ThemeStore::GitImporter do
.expects(:execute_command)
.with(
{ "GIT_TERMINAL_PROMPT" => "0" },
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "-b", branch, "https://github.com/example/example.git", @temp_folder, { timeout: 20 }
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "-b", branch, "https://github.com/example/example.git", @temp_folder, timeout: 20
)
importer = ThemeStore::GitImporter.new(url, branch: branch)
@ -75,7 +72,7 @@ RSpec.describe ThemeStore::GitImporter do
.expects(:execute_command)
.with(
{ "GIT_SSH_COMMAND" => "ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no" },
"git", "clone", "-b", branch, "ssh://git@github.com/example/example.git", @temp_folder, { timeout: 20 }
"git", "clone", "-b", branch, "ssh://git@github.com/example/example.git", @temp_folder, timeout: 20
)
importer = ThemeStore::GitImporter.new(ssh_url, private_key: "private_key", branch: branch)

View File

@ -1289,12 +1289,12 @@ RSpec.describe Report do
end
it "caches exception reports for 1 minute" do
Discourse.cache.expects(:write).with(Report.cache_key(exception_report), exception_report.as_json, { expires_in: 1.minute })
Discourse.cache.expects(:write).with(Report.cache_key(exception_report), exception_report.as_json, expires_in: 1.minute)
Report.cache(exception_report)
end
it "caches valid reports for 35 minutes" do
Discourse.cache.expects(:write).with(Report.cache_key(valid_report), valid_report.as_json, { expires_in: 35.minutes })
Discourse.cache.expects(:write).with(Report.cache_key(valid_report), valid_report.as_json, expires_in: 35.minutes)
Report.cache(valid_report)
end
end

View File

@ -138,7 +138,7 @@ RSpec.describe ReviewableUser, type: :model do
it "optionally sends email with reject reason" do
SiteSetting.must_approve_users = true
Jobs::CriticalUserEmail.any_instance.expects(:execute).with(type: :signup_after_reject, user_id: reviewable.target_id, reject_reason: "reject reason").once
Jobs::CriticalUserEmail.any_instance.expects(:execute).with({ type: :signup_after_reject, user_id: reviewable.target_id, reject_reason: "reject reason" }).once
reviewable.perform(moderator, :delete_user_block, reject_reason: "reject reason", send_email: true)
end

View File

@ -198,7 +198,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite do
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
s3_bucket.expects(:object).with("#{upload_path}/#{path}").returns(s3_object).at_least_once
s3_object.expects(:presigned_url).with(:get, expires_in: SiteSetting.s3_presigned_get_url_expires_after_seconds)
s3_object.expects(:presigned_url).with(:get, { expires_in: SiteSetting.s3_presigned_get_url_expires_after_seconds })
upload.url = store.store_upload(uploaded_file, upload)
expect(upload.url).to eq(

View File

@ -83,7 +83,7 @@ RSpec.describe Admin::BackupsController do
describe '#create' do
it "starts a backup" do
BackupRestore.expects(:backup!).with(admin.id, publish_to_message_bus: true, with_uploads: false, client_id: "foo")
BackupRestore.expects(:backup!).with(admin.id, { publish_to_message_bus: true, with_uploads: false, client_id: "foo" })
post "/admin/backups.json", params: {
with_uploads: false, client_id: "foo"
@ -162,7 +162,7 @@ RSpec.describe Admin::BackupsController do
describe '#restore' do
it "starts a restore" do
BackupRestore.expects(:restore!).with(admin.id, filename: backup_filename, publish_to_message_bus: true, client_id: "foo")
BackupRestore.expects(:restore!).with(admin.id, { filename: backup_filename, publish_to_message_bus: true, client_id: "foo" })
post "/admin/backups/#{backup_filename}/restore.json", params: { client_id: "foo" }

View File

@ -542,13 +542,16 @@ RSpec.describe ReviewablesController do
fab!(:reviewable_phony) { Fabricate(:reviewable, type: "ReviewablePhony") }
it "passes the added param into the reviewable class' perform method" do
MessageBus.expects(:publish)
.with("/phony-reviewable-test", { args: {
version: reviewable_phony.version,
"fake_id" => "2" }
MessageBus.expects(:publish).with(
"/phony-reviewable-test",
{
args: {
version: reviewable_phony.version,
"fake_id" => "2",
}
},
{ user_ids: [1] })
.once
user_ids: [1]
).once
put "/review/#{reviewable_phony.id}/perform/approve_phony.json?version=#{reviewable_phony.version}", params: { fake_id: 2 }
expect(response.status).to eq(200)

View File

@ -1049,10 +1049,12 @@ RSpec.describe UserMerger do
it "updates the username" do
Jobs::UpdateUsername.any_instance
.expects(:execute)
.with(user_id: source_user.id,
old_username: 'alice1',
new_username: 'alice',
avatar_template: target_user.avatar_template)
.with({
user_id: source_user.id,
old_username: 'alice1',
new_username: 'alice',
avatar_template: target_user.avatar_template
})
.once
merge_users!