Skip to content

Commit

Permalink
Specify default error translation key
Browse files Browse the repository at this point in the history
I ran into this while working on my custom token generation.

- I accidentally triggered a `NoMethodError` which was rescued and
  wrapped here:
  https://github.com/doorkeeper-gem/doorkeeper/blob/master/lib/doorkeeper/models/access_token_mixin.rb#L137
- This was then fed into
  https://github.com/doorkeeper-gem/doorkeeper/blob/master/app/controllers/doorkeeper/tokens_controller.rb#L9
  and I got an error message from I18n about a missing translation key.

This changeset adds a default to prevent that from happening.

[fixes doorkeeper-gem#747]
  • Loading branch information
ryansch authored and tute committed Nov 19, 2015
1 parent bd3802b commit 8b8d7d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/doorkeeper/oauth/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module Doorkeeper
module OAuth
class Error < Struct.new(:name, :state)
def description
I18n.translate name, scope: [:doorkeeper, :errors, :messages]
I18n.translate(
name,
scope: [:doorkeeper, :errors, :messages],
default: :server_error
)
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions spec/lib/oauth/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

module Doorkeeper::OAuth
describe Error do
subject { Error.new(:some_error, :some_state) }
subject(:error) { Error.new(:some_error, :some_state) }

it { expect(subject).to respond_to(:name) }
it { expect(subject).to respond_to(:state) }

describe :description do
it 'is translated from translation messages' do
expect(I18n).to receive(:translate).with(:some_error, scope: [:doorkeeper, :errors, :messages])
subject.description
expect(I18n).to receive(:translate).with(
:some_error,
scope: [:doorkeeper, :errors, :messages],
default: :server_error
)
error.description
end
end
end
Expand Down

0 comments on commit 8b8d7d4

Please sign in to comment.