From 254967251da4538410407711d7b2f959701db5c3 Mon Sep 17 00:00:00 2001 From: pozzer Date: Thu, 27 Feb 2025 21:27:39 -0300 Subject: [PATCH 1/3] Fix incorrect translation key for parameter_not_allowed.detail --- lib/jsonapi/exceptions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonapi/exceptions.rb b/lib/jsonapi/exceptions.rb index e917118c..9055c546 100644 --- a/lib/jsonapi/exceptions.rb +++ b/lib/jsonapi/exceptions.rb @@ -402,7 +402,7 @@ def errors status: :bad_request, title: I18n.translate('jsonapi-resources.exceptions.parameter_not_allowed.title', default: 'Param not allowed'), - detail: I18n.translate('jsonapi-resources.exceptions.parameters_not_allowed.detail', + detail: I18n.translate('jsonapi-resources.exceptions.parameter_not_allowed.detail', default: "#{param} is not allowed.", param: param))] end end From c494e3305b23e9d4beb605e6e109cc4559d9fc09 Mon Sep 17 00:00:00 2001 From: pozzer Date: Thu, 27 Feb 2025 22:22:36 -0300 Subject: [PATCH 2/3] Adds translation tests --- Gemfile | 2 ++ test/unit/exceptions/translation_test.rb | 34 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/unit/exceptions/translation_test.rb diff --git a/Gemfile b/Gemfile index 2535d020..876ad04e 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ version = ENV['RAILS_VERSION'] || 'default' platforms :ruby do gem 'pg' + gem 'concurrent-ruby', '1.3.4' + gem 'pry' if version.start_with?('4.2', '5.0') gem 'sqlite3', '~> 1.3.13' diff --git a/test/unit/exceptions/translation_test.rb b/test/unit/exceptions/translation_test.rb new file mode 100644 index 00000000..32ff03ab --- /dev/null +++ b/test/unit/exceptions/translation_test.rb @@ -0,0 +1,34 @@ +require File.expand_path('../../../test_helper', __FILE__) + +class TranslationTest < ActiveSupport::TestCase + setup do + @original_locale = I18n.locale + end + + teardown do + I18n.locale = @original_locale + end + + test "parameter_not_allowed translation is loaded correctly in another language" do + I18n.with_locale(:pt) do + I18n.backend.store_translations(:pt, { + "jsonapi-resources": { + exceptions: { + parameter_not_allowed: { + title: "Parâmetro não permitido", + detail: "%{param} não permitido." + } + } + } + }) + + param = "sort" + exception = JSONAPI::Exceptions::ParameterNotAllowed.new(param).errors[0] + expected_title = I18n.t("jsonapi-resources.exceptions.parameter_not_allowed.title") + expected_detail = I18n.t("jsonapi-resources.exceptions.parameter_not_allowed.detail", param: param) + + assert_equal expected_title, exception.title + assert_equal expected_detail, exception.detail + end + end +end \ No newline at end of file From fafa8e97ac253ea1b3778b3694bd06a5119e4583 Mon Sep 17 00:00:00 2001 From: pozzer Date: Thu, 27 Feb 2025 22:36:07 -0300 Subject: [PATCH 3/3] remove gems --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index 876ad04e..2535d020 100644 --- a/Gemfile +++ b/Gemfile @@ -10,8 +10,6 @@ version = ENV['RAILS_VERSION'] || 'default' platforms :ruby do gem 'pg' - gem 'concurrent-ruby', '1.3.4' - gem 'pry' if version.start_with?('4.2', '5.0') gem 'sqlite3', '~> 1.3.13'