From a05b1c76077dd0dd4933fcab0d627896edfa9256 Mon Sep 17 00:00:00 2001 From: Justin Bull Date: Wed, 14 Feb 2018 10:20:55 -0500 Subject: [PATCH] Allow Application#redirect_uri= to handle array of URIs --- lib/doorkeeper/models/application_mixin.rb | 10 ++++++++++ spec/models/doorkeeper/application_spec.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/doorkeeper/models/application_mixin.rb b/lib/doorkeeper/models/application_mixin.rb index a46ebd0fc..22e5e803b 100644 --- a/lib/doorkeeper/models/application_mixin.rb +++ b/lib/doorkeeper/models/application_mixin.rb @@ -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? diff --git a/spec/models/doorkeeper/application_spec.rb b/spec/models/doorkeeper/application_spec.rb index cae1e12ce..9a92b588f 100644 --- a/spec/models/doorkeeper/application_spec.rb +++ b/spec/models/doorkeeper/application_spec.rb @@ -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) }