Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jsonapi/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/unit/exceptions/translation_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading