Skip to content

Commit

Permalink
Add test to confirm crash when available locales are enforced but fal…
Browse files Browse the repository at this point in the history
…lback locale unavailable
  • Loading branch information
Morred committed Sep 29, 2018
1 parent 35b432c commit 100c705
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/grape/exceptions/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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' } }

context 'when I18n enforces available locales' do
before { I18n.enforce_available_locales = true }
after { 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 'currently raises an error' do
expect { subject }.to raise_error(I18n::InvalidLocale)
end
end
end
end
end

0 comments on commit 100c705

Please sign in to comment.