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 end
it 'delegates the process call to execute' do 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) ::Jobs::Base.new.perform('hello' => 'world', 'sync_exec' => true)
end end

View File

@ -106,7 +106,7 @@ RSpec.describe Jobs do
end end
it "executes the job right away" do 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) Jobs.enqueue(:process_post, post_id: 1)
end end

View File

@ -190,7 +190,7 @@ RSpec.describe DiscoursePluginRegistry do
describe '.register_archetype' do describe '.register_archetype' do
it "delegates archetypes to the Archetype component" 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) registry_instance.register_archetype('threaded', hello: 123)
end end
end end

View File

@ -31,11 +31,12 @@ RSpec.describe FileStore::S3Store do
it "returns an absolute schemaless url" do it "returns an absolute schemaless url" do
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once 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_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", acl: "public-read",
cache_control: "max-age=31556952, public, immutable", cache_control: "max-age=31556952, public, immutable",
content_type: "image/png", 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( 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} %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_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_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", acl: "private",
cache_control: "max-age=31556952, public, immutable", cache_control: "max-age=31556952, public, immutable",
content_type: "application/pdf", content_type: "application/pdf",
content_disposition: "attachment; filename=\"#{upload.original_filename}\"; filename*=UTF-8''#{upload.original_filename}", 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( 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} %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_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_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", acl: "public-read",
cache_control: "max-age=31556952, public, immutable", cache_control: "max-age=31556952, public, immutable",
content_type: "image/png", 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( 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} %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}" invalid_json = "{\"@type\":invalid-json}"
doc = Nokogiri::HTML("<script type=\"application/ld+json\">#{invalid_json}</script>") doc = Nokogiri::HTML("<script type=\"application/ld+json\">#{invalid_json}</script>")
Discourse.expects(:warn_exception).with( 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) json_ld = described_class.new(doc)

View File

@ -70,7 +70,7 @@ RSpec.describe "S3Helper" do
'some' => 'testing' 'some' => 'testing'
}.each do |bucket_name, prefix| }.each do |bucket_name, prefix|
s3_helper = S3Helper.new(bucket_name, "", client: client) 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') s3_helper.list('testing')
end end
end end

View File

@ -53,14 +53,14 @@ RSpec.describe SiteSettings::YamlLoader do
end end
it "can load client settings" do it "can load client settings" do
receiver.expects(:setting).with('category1', 'title', 'Discourse', 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', 'tos_url', '', { client: true })
receiver.expects(:setting).with('category2', 'must_approve_users', false, client: true) receiver.expects(:setting).with('category2', 'must_approve_users', false, { client: true })
receiver.load_yaml(client) receiver.load_yaml(client)
end end
it "can load enum settings" do 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) receiver.load_yaml(enum)
end end
@ -76,7 +76,7 @@ RSpec.describe SiteSettings::YamlLoader do
end end
it "can load settings with locale default" do 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) receiver.load_yaml(locale_default)
end end
end end

View File

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

View File

@ -1289,12 +1289,12 @@ RSpec.describe Report do
end end
it "caches exception reports for 1 minute" do 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) Report.cache(exception_report)
end end
it "caches valid reports for 35 minutes" do 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) Report.cache(valid_report)
end end
end end

View File

@ -138,7 +138,7 @@ RSpec.describe ReviewableUser, type: :model do
it "optionally sends email with reject reason" do it "optionally sends email with reject reason" do
SiteSetting.must_approve_users = true 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) reviewable.perform(moderator, :delete_user_block, reject_reason: "reject reason", send_email: true)
end 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_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_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) upload.url = store.store_upload(uploaded_file, upload)
expect(upload.url).to eq( expect(upload.url).to eq(

View File

@ -83,7 +83,7 @@ RSpec.describe Admin::BackupsController do
describe '#create' do describe '#create' do
it "starts a backup" 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: { post "/admin/backups.json", params: {
with_uploads: false, client_id: "foo" with_uploads: false, client_id: "foo"
@ -162,7 +162,7 @@ RSpec.describe Admin::BackupsController do
describe '#restore' do describe '#restore' do
it "starts a 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" } 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") } fab!(:reviewable_phony) { Fabricate(:reviewable, type: "ReviewablePhony") }
it "passes the added param into the reviewable class' perform method" do it "passes the added param into the reviewable class' perform method" do
MessageBus.expects(:publish) MessageBus.expects(:publish).with(
.with("/phony-reviewable-test", { args: { "/phony-reviewable-test",
version: reviewable_phony.version, {
"fake_id" => "2" } args: {
version: reviewable_phony.version,
"fake_id" => "2",
}
}, },
{ user_ids: [1] }) user_ids: [1]
.once ).once
put "/review/#{reviewable_phony.id}/perform/approve_phony.json?version=#{reviewable_phony.version}", params: { fake_id: 2 } put "/review/#{reviewable_phony.id}/perform/approve_phony.json?version=#{reviewable_phony.version}", params: { fake_id: 2 }
expect(response.status).to eq(200) expect(response.status).to eq(200)

View File

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