1 Star 0 Fork 12

yanxiaobing2020/rubygem-actionview

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rubygem-actionview-7.0.2.3-Remove-the-multi-call-form-of-assert_called_with.patch 4.90 KB
一键复制 编辑 原始数据 按行查看 历史
yanxiaobing2020 提交于 2023-01-19 16:20 . upgrade to version 7.0.4
From df0de681dc1873534ecd2fc8371e1f2562984b68 Mon Sep 17 00:00:00 2001
From: John Crepezzi <john.crepezzi@gmail.com>
Date: Thu, 16 Jun 2022 08:34:05 -0400
Subject: [PATCH] Remove the multi-call form of assert_called_with
The `assert_called_with` helper allows passing a multi-dimensional array to
mock multiple calls to the same method for a given block. This works
fine now, but when adding support for real kwargs arguments to line up with
recent upgrades in Minitest, this approach is no longer workable because
we can't pass multiple sets of differing kwargs.
Rather than complicated this method further, this commit removes the
multi-call form of `assert_called_with` and modifies the tests that
currently make use of that functionality to just use the underlying
`Minitest::Mock` calls.
Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com>
---
.../test/template/date_helper_i18n_test.rb | 16 +++-
.../template/form_helper/form_with_test.rb | 10 ++-
actionview/test/template/form_helper_test.rb | 10 ++-
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/actionview/test/template/date_helper_i18n_test.rb b/actionview/test/template/date_helper_i18n_test.rb
index f100a011a83f7..2f098e2f5158f 100644
--- a/actionview/test/template/date_helper_i18n_test.rb
+++ b/actionview/test/template/date_helper_i18n_test.rb
@@ -146,9 +146,15 @@ def test_date_or_time_select_given_an_order_options_does_not_translate_order
end
def test_date_or_time_select_given_no_order_options_translates_order
- assert_called_with(I18n, :translate, [ [:'date.order', locale: "en", default: []], [:"date.month_names", { locale: "en" }] ], returns: %w(year month day)) do
+ mock = Minitest::Mock.new
+ mock.expect(:call, ["year", "month", "day"], [:'date.order', { locale: "en", default: [] }])
+ mock.expect(:call, [], [:'date.month_names', { locale: "en" }])
+
+ I18n.stub(:translate, mock) do
datetime_select("post", "updated_at", locale: "en")
end
+
+ assert_mock(mock)
end
def test_date_or_time_select_given_invalid_order
@@ -160,8 +166,14 @@ def test_date_or_time_select_given_invalid_order
end
def test_date_or_time_select_given_symbol_keys
- assert_called_with(I18n, :translate, [ [:'date.order', locale: "en", default: []], [:"date.month_names", { locale: "en" }] ], returns: [:year, :month, :day]) do
+ mock = Minitest::Mock.new
+ mock.expect(:call, [:year, :month, :day], [:'date.order', { locale: "en", default: [] }])
+ mock.expect(:call, [], [:'date.month_names', { locale: "en" }])
+
+ I18n.stub(:translate, mock) do
datetime_select("post", "updated_at", locale: "en")
end
+
+ assert_mock(mock)
end
end
diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb
index eadddc15002ee..00e6ca42ea473 100644
--- a/actionview/test/template/form_helper/form_with_test.rb
+++ b/actionview/test/template/form_helper/form_with_test.rb
@@ -1745,14 +1745,20 @@ def test_nested_fields_arel_like
def test_nested_fields_label_translation_with_more_than_10_records
@post.comments = Array.new(11) { |id| Comment.new(id + 1) }
- params = 11.times.map { ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"] }
- assert_called_with(I18n, :t, params, returns: "Write body here") do
+ mock = Minitest::Mock.new
+ @post.comments.each do
+ mock.expect(:call, "body", ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"])
+ end
+
+ I18n.stub(:t, mock) do
form_with(model: @post) do |f|
f.fields(:comments) do |cf|
concat cf.label(:body)
end
end
end
+
+ assert_mock(mock)
end
def test_nested_fields_with_existing_records_on_a_supplied_nested_attributes_collection_different_from_record_one
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index d08f00cd36c35..8560be2770ca4 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -3267,14 +3267,20 @@ def test_nested_fields_for_arel_like
def test_nested_fields_label_translation_with_more_than_10_records
@post.comments = Array.new(11) { |id| Comment.new(id + 1) }
- params = 11.times.map { ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"] }
- assert_called_with(I18n, :t, params, returns: "Write body here") do
+ mock = Minitest::Mock.new
+ @post.comments.each do
+ mock.expect(:call, "body", ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"])
+ end
+
+ I18n.stub(:t, mock) do
form_for(@post) do |f|
f.fields_for(:comments) do |cf|
concat cf.label(:body)
end
end
end
+
+ assert_mock(mock)
end
def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection_different_from_record_one
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yanxiaobing2020/rubygem-actionview.git
git@gitee.com:yanxiaobing2020/rubygem-actionview.git
yanxiaobing2020
rubygem-actionview
rubygem-actionview
master

搜索帮助