-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1796 from Morred/fix-unavailable-locale-crash
Fix crash when available locales are enforced but fallback locale unavailable
- Loading branch information
Showing
5 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'spec_helper' | ||
|
||
describe Grape::Exceptions::Base do | ||
describe '#compose_message' do | ||
subject { described_class.new.send(:compose_message, key, attributes) } | ||
|
||
let(:key) { :invalid_formatter } | ||
let(:attributes) { { klass: String, to_format: 'xml' } } | ||
|
||
after do | ||
I18n.available_locales = %i[en] | ||
I18n.default_locale = :en | ||
end | ||
|
||
context 'when I18n enforces available locales' do | ||
before { I18n.enforce_available_locales = true } | ||
|
||
context 'when the fallback locale is available' do | ||
before do | ||
I18n.available_locales = %i[de en] | ||
I18n.default_locale = :de | ||
end | ||
|
||
it 'returns the translated message' do | ||
expect(subject).to eq('cannot convert String to xml') | ||
end | ||
end | ||
|
||
context 'when the fallback locale is not available' do | ||
before do | ||
I18n.available_locales = %i[de jp] | ||
I18n.default_locale = :de | ||
end | ||
|
||
it 'returns the translation string' do | ||
expect(subject).to eq("grape.errors.messages.#{key}") | ||
end | ||
end | ||
end | ||
|
||
context 'when I18n does not enforce available locales' do | ||
before { I18n.enforce_available_locales = false } | ||
|
||
context 'when the fallback locale is available' do | ||
before { I18n.available_locales = %i[de en] } | ||
|
||
it 'returns the translated message' do | ||
expect(subject).to eq('cannot convert String to xml') | ||
end | ||
end | ||
|
||
context 'when the fallback locale is not available' do | ||
before { I18n.available_locales = %i[de jp] } | ||
|
||
it 'returns the translated message' do | ||
expect(subject).to eq('cannot convert String to xml') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters