From c32fe340f0311537d741e0d55405551ccd1136ee Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 2 Nov 2022 10:47:59 +0100 Subject: [PATCH] DEV: Fix mocha deprecations (#18828) It now supports strict keyword argument matching by default. --- spec/jobs/jobs_base_spec.rb | 2 +- spec/jobs/jobs_spec.rb | 2 +- spec/lib/discourse_plugin_registry_spec.rb | 2 +- spec/lib/file_store/s3_store_spec.rb | 15 +++++++++------ spec/lib/onebox/json_ld_spec.rb | 2 +- spec/lib/s3_helper_spec.rb | 2 +- spec/lib/site_settings/yaml_loader_spec.rb | 10 +++++----- spec/lib/theme_store/git_importer_spec.rb | 13 +++++-------- spec/models/report_spec.rb | 4 ++-- spec/models/reviewable_user_spec.rb | 2 +- spec/multisite/s3_store_spec.rb | 2 +- spec/requests/admin/backups_controller_spec.rb | 4 ++-- spec/requests/reviewables_controller_spec.rb | 15 +++++++++------ spec/services/user_merger_spec.rb | 10 ++++++---- 14 files changed, 45 insertions(+), 40 deletions(-) diff --git a/spec/jobs/jobs_base_spec.rb b/spec/jobs/jobs_base_spec.rb index 619ab0f8cd9..6b267af9c3c 100644 --- a/spec/jobs/jobs_base_spec.rb +++ b/spec/jobs/jobs_base_spec.rb @@ -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 diff --git a/spec/jobs/jobs_spec.rb b/spec/jobs/jobs_spec.rb index 09c4252decd..09406eb66be 100644 --- a/spec/jobs/jobs_spec.rb +++ b/spec/jobs/jobs_spec.rb @@ -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 diff --git a/spec/lib/discourse_plugin_registry_spec.rb b/spec/lib/discourse_plugin_registry_spec.rb index 162a2f051ee..96f84df3df7 100644 --- a/spec/lib/discourse_plugin_registry_spec.rb +++ b/spec/lib/discourse_plugin_registry_spec.rb @@ -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 diff --git a/spec/lib/file_store/s3_store_spec.rb b/spec/lib/file_store/s3_store_spec.rb index bff47c3ce8b..0473c5ab196 100644 --- a/spec/lib/file_store/s3_store_spec.rb +++ b/spec/lib/file_store/s3_store_spec.rb @@ -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} diff --git a/spec/lib/onebox/json_ld_spec.rb b/spec/lib/onebox/json_ld_spec.rb index e17bc3fbbef..d668622184e 100644 --- a/spec/lib/onebox/json_ld_spec.rb +++ b/spec/lib/onebox/json_ld_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Onebox::JsonLd do invalid_json = "{\"@type\":invalid-json}" doc = Nokogiri::HTML("") 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) diff --git a/spec/lib/s3_helper_spec.rb b/spec/lib/s3_helper_spec.rb index 45ef50a3e79..623580dbc0f 100644 --- a/spec/lib/s3_helper_spec.rb +++ b/spec/lib/s3_helper_spec.rb @@ -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 diff --git a/spec/lib/site_settings/yaml_loader_spec.rb b/spec/lib/site_settings/yaml_loader_spec.rb index 38b9d16a283..8c38befb9e1 100644 --- a/spec/lib/site_settings/yaml_loader_spec.rb +++ b/spec/lib/site_settings/yaml_loader_spec.rb @@ -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 diff --git a/spec/lib/theme_store/git_importer_spec.rb b/spec/lib/theme_store/git_importer_spec.rb index 59ed3573137..c6905c95751 100644 --- a/spec/lib/theme_store/git_importer_spec.rb +++ b/spec/lib/theme_store/git_importer_spec.rb @@ -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) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index dae205cdaf3..930398864d8 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -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 diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rb index 0c3440a00cf..ece77650c44 100644 --- a/spec/models/reviewable_user_spec.rb +++ b/spec/models/reviewable_user_spec.rb @@ -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 diff --git a/spec/multisite/s3_store_spec.rb b/spec/multisite/s3_store_spec.rb index b10aeffb8b2..675484ae941 100644 --- a/spec/multisite/s3_store_spec.rb +++ b/spec/multisite/s3_store_spec.rb @@ -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( diff --git a/spec/requests/admin/backups_controller_spec.rb b/spec/requests/admin/backups_controller_spec.rb index f3cfdda31a0..2f269bb9c84 100644 --- a/spec/requests/admin/backups_controller_spec.rb +++ b/spec/requests/admin/backups_controller_spec.rb @@ -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" } diff --git a/spec/requests/reviewables_controller_spec.rb b/spec/requests/reviewables_controller_spec.rb index ae84f5e23f3..bc2effa1d70 100644 --- a/spec/requests/reviewables_controller_spec.rb +++ b/spec/requests/reviewables_controller_spec.rb @@ -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) diff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rb index 1a289365640..8b5d1b45194 100644 --- a/spec/services/user_merger_spec.rb +++ b/spec/services/user_merger_spec.rb @@ -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!