Skip to content

Commit

Permalink
Allow Application#redirect_uri= to handle array of URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Bull committed Feb 14, 2018
1 parent 4ad9458 commit a05b1c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/doorkeeper/models/application_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def by_uid(uid)
end
end

##
# Set an application's valid redirect URIs.
#
# @param uris [String, Array] Newline-separated string or array the URI(s)
#
# @return [String] The redirect URI(s) seperated by newlines.
def redirect_uri=(uris)
super(uris.is_a?(Array) ? uris.join("\n") : uris)
end

private

def has_scopes?
Expand Down
15 changes: 15 additions & 0 deletions spec/models/doorkeeper/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ module Doorkeeper
end
end

describe "#redirect_uri=" do
context "when array of valid redirect_uris" do
it "should join by newline" do
new_application.redirect_uri = ['http://localhost/callback1', 'http://localhost/callback2']
expect(new_application.redirect_uri).to eq("http://localhost/callback1\nhttp://localhost/callback2")
end
end
context "when string of valid redirect_uris" do
it "should store as-is" do
new_application.redirect_uri = "http://localhost/callback1\nhttp://localhost/callback2"
expect(new_application.redirect_uri).to eq("http://localhost/callback1\nhttp://localhost/callback2")
end
end
end

describe :authorized_for do
let(:resource_owner) { double(:resource_owner, id: 10) }

Expand Down

0 comments on commit a05b1c7

Please sign in to comment.