Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adds translation tests
  • Loading branch information
pozzer committed Feb 28, 2025
commit c494e3305b23e9d4beb605e6e109cc4559d9fc09
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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