Skip to content

Commit

Permalink
scopes field accepts Array
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Mar 13, 2019
1 parent 5aa6bcb commit 421be78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ User-visible changes worth mentioning.
## master

- [#1215] Fix deprecates for Rails 6.
- [#1214] Scopes field accepts array.
- [#1209] Fix tokens validation for Token Introspection request.
- [#1202] Use correct HTTP status codes for error responses.

Expand Down
4 changes: 4 additions & 0 deletions lib/doorkeeper/models/concerns/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def scopes
OAuth::Scopes.from_string(scopes_string)
end

def scopes=(value)
super Array(value).join(' ')
end

def scopes_string
self[:scopes]
end
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/models/scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'Doorkeeper::Models::Scopes' do
subject do
Class.new(Hash) do
Class.new(Struct.new(:scopes)) do
include Doorkeeper::Models::Scopes
end.new
end
Expand All @@ -21,6 +21,18 @@
end
end

describe :scopes= do
it 'accepts String' do
subject.scopes = 'private admin'
expect(subject.scopes_string).to eq('private admin')
end

it 'accepts Array' do
subject.scopes = %w[private admin]
expect(subject.scopes_string).to eq('private admin')
end
end

describe :scopes_string do
it 'is a `Scopes` class' do
expect(subject.scopes_string).to eq('public admin')
Expand Down

0 comments on commit 421be78

Please sign in to comment.