Skip to content

Commit 67b7c3c

Browse files
committed
WIP: Fix some Mocha deprecation warnings
This fixes some of the warnings related to strict keyword argument matching, like this one: Mocha deprecation warning at app/services/asset_manager/attachment_updater/update.rb:15:in `call': Expectation defined at test/unit/services/asset_manager/attachment_updater/draft_status_updates_test.rb:28: in `block (3 levels) in <class:DraftStatusUpdatesTest>' expected keyword arguments ("draft" => true), but received positional hash ({"draft" => true}). These will stop matching when strict keyword argument matching is enabled. See the documentation for Mocha::Configuration#strict_keyword_argument_matching=. In order to fix the warnings, I've changed the signature of AssetManager::AssetUpdater#call so that new_attributes parameter must be supplied as keyword arguments rather than a positional Hash. This had the advantage that I only needed to change AssetManager::AttachmentUpdater::Update#call to convert the deep_stringify_keys into keyword arguments using a double-splat; I didn't need to change all the places where AssetManager::AssetUpdater#call is stubbed. An alternative would be to leave the signature of AssetManager::AssetUpdater#call unchanged and change the calls to Expectation#with for all the relevant stubs to pass a positional Hash, i.e. wrapped in braces. This article [1] is a very useful reference. [1]: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
1 parent 4b62bcb commit 67b7c3c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

app/services/asset_manager/asset_updater.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def initialize(attachment_data_id, legacy_url_path)
1313
end
1414
end
1515

16-
def self.call(*args)
17-
new.call(*args)
16+
def self.call(...)
17+
new.call(...)
1818
end
1919

20-
def call(asset_data, legacy_url_path, new_attributes = {})
20+
def call(asset_data, legacy_url_path, **new_attributes)
2121
attributes = find_asset_by(legacy_url_path)
2222
asset_deleted = attributes["deleted"]
2323

app/services/asset_manager/attachment_updater/update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def call
1515
AssetManager::AssetUpdater.call(
1616
attachment_data,
1717
legacy_url_path,
18-
new_attributes.deep_stringify_keys,
18+
**new_attributes.deep_stringify_keys,
1919
)
2020
end
2121

0 commit comments

Comments
 (0)