forked from doorkeeper-gem/doorkeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request doorkeeper-gem#734 from reidab/request-strategy-re…
…factor Refactor request strategy classes
- Loading branch information
Showing
11 changed files
with
145 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Doorkeeper | ||
module Request | ||
class Strategy | ||
attr_accessor :server | ||
|
||
delegate :authorize, to: :request | ||
|
||
def initialize(server) | ||
self.server = server | ||
end | ||
|
||
def request | ||
raise NotImplementedError, "request strategies must define #request" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'spec_helper' | ||
require 'doorkeeper/request/strategy' | ||
|
||
module Doorkeeper | ||
module Request | ||
describe Strategy do | ||
let(:server) { double } | ||
subject(:strategy) { Strategy.new(server) } | ||
|
||
describe :initialize do | ||
it "sets the server attribute" do | ||
expect(strategy.server).to eq server | ||
end | ||
end | ||
|
||
describe :request do | ||
it "requires an implementation" do | ||
expect { strategy.request }.to raise_exception NotImplementedError | ||
end | ||
end | ||
|
||
describe "a sample Strategy subclass" do | ||
let(:fake_request) { double } | ||
|
||
let(:strategy_class) do | ||
subclass = Class.new(Strategy) do | ||
class << self | ||
attr_accessor :fake_request | ||
end | ||
|
||
def request | ||
self.class.fake_request | ||
end | ||
end | ||
|
||
subclass.fake_request = fake_request | ||
subclass | ||
end | ||
|
||
subject(:strategy) { strategy_class.new(server) } | ||
|
||
it "provides a request implementation" do | ||
expect(strategy.request).to eq fake_request | ||
end | ||
|
||
it "authorizes the request" do | ||
expect(fake_request).to receive :authorize | ||
strategy.authorize | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters