From 47132b9d6108cbcf6aa24e9c910a297704a30833 Mon Sep 17 00:00:00 2001 From: Stone Filipczak Date: Mon, 29 Apr 2024 15:00:59 -0400 Subject: [PATCH 1/2] use proper kwargs syntax for i18n call --- lib/cancan/ability.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 2a3dc808..3b4f7f0b 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -214,7 +214,7 @@ def unauthorized_message(action, subject) keys = unauthorized_message_keys(action, subject) variables = {:action => action.to_s} variables[:subject] = (subject.class == Class ? subject : subject.class).to_s.underscore.humanize.downcase - message = I18n.translate(nil, variables.merge(:scope => :unauthorized, :default => keys + [""])) + message = I18n.translate(nil, **variables.merge(:scope => :unauthorized, :default => keys + [""])) message.blank? ? nil : message end From d9378a8966c3ba5fbcca04c5241e89d889a278c4 Mon Sep 17 00:00:00 2001 From: Micaela Cunha Date: Fri, 14 Mar 2025 13:20:33 -0400 Subject: [PATCH 2/2] Fixed deprecations of 'failure_message_for_should_not' and 'failure_message_for_should' --- lib/cancan/matchers.rb | 4 ++-- spec/matchers.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cancan/matchers.rb b/lib/cancan/matchers.rb index 4a4fb947..c246bc51 100644 --- a/lib/cancan/matchers.rb +++ b/lib/cancan/matchers.rb @@ -4,11 +4,11 @@ ability.can?(*args) end - failure_message_for_should do |ability| + failure_message do |ability| "expected to be able to #{args.map(&:inspect).join(" ")}" end - failure_message_for_should_not do |ability| + failure_message_when_negated do |ability| "expected not to be able to #{args.map(&:inspect).join(" ")}" end end diff --git a/spec/matchers.rb b/spec/matchers.rb index b98bd24f..1827b153 100644 --- a/spec/matchers.rb +++ b/spec/matchers.rb @@ -3,11 +3,11 @@ original_string.split('').sort == given_string.split('').sort end - failure_message_for_should do |given_string| + failure_message do |given_string| "expected \"#{given_string}\" to have the same characters as \"#{original_string}\"" end - failure_message_for_should_not do |given_string| + failure_message_when_negated do |given_string| "expected \"#{given_string}\" not to have the same characters as \"#{original_string}\"" end end