From 2465e2e2f16e754b93ae89e0c7e276ec436a2427 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Tue, 27 Oct 2015 11:18:33 +0100 Subject: [PATCH 1/6] Rename Doorkeeper::Request method params for clarity The arguments are strings from the `request_type` and `grant_type` parameters, not strategies. --- lib/doorkeeper/request.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/doorkeeper/request.rb b/lib/doorkeeper/request.rb index 525a96560..045a0fb63 100644 --- a/lib/doorkeeper/request.rb +++ b/lib/doorkeeper/request.rb @@ -9,22 +9,22 @@ module Doorkeeper module Request module_function - def authorization_strategy(strategy) - get_strategy strategy, Doorkeeper.configuration.authorization_response_types + def authorization_strategy(response_type) + get_strategy response_type, Doorkeeper.configuration.authorization_response_types rescue NameError raise Errors::InvalidAuthorizationStrategy end - def token_strategy(strategy) - get_strategy strategy, Doorkeeper.configuration.token_grant_types + def token_strategy(grant_type) + get_strategy grant_type, Doorkeeper.configuration.token_grant_types rescue NameError raise Errors::InvalidTokenStrategy end - def get_strategy(strategy, available) - fail Errors::MissingRequestStrategy unless strategy.present? - fail NameError unless available.include?(strategy.to_s) - "Doorkeeper::Request::#{strategy.to_s.camelize}".constantize + def get_strategy(grant_or_request_type, available) + fail Errors::MissingRequestStrategy unless grant_or_request_type.present? + fail NameError unless available.include?(grant_or_request_type.to_s) + "Doorkeeper::Request::#{grant_or_request_type.to_s.camelize}".constantize end end end From e676684ebab17452c2abb8e7667eec1eb1452f34 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Tue, 27 Oct 2015 11:46:15 +0100 Subject: [PATCH 2/6] Refactor strategies to remove .build(server) These objects don't ever seem to be initialized outside of the .build method, so we can simplify things and make them conform to a more consistent interface by allowing their initializers to take a server instead of individual parameters. --- lib/doorkeeper/request/authorization_code.rb | 8 ++------ lib/doorkeeper/request/client_credentials.rb | 8 ++------ lib/doorkeeper/request/code.rb | 9 +++------ lib/doorkeeper/request/password.rb | 10 ++++------ lib/doorkeeper/request/refresh_token.rb | 10 ++++------ lib/doorkeeper/request/token.rb | 9 +++------ lib/doorkeeper/server.rb | 4 ++-- spec/lib/server_spec.rb | 2 +- 8 files changed, 21 insertions(+), 39 deletions(-) diff --git a/lib/doorkeeper/request/authorization_code.rb b/lib/doorkeeper/request/authorization_code.rb index fc225e4b4..092e2e9d3 100644 --- a/lib/doorkeeper/request/authorization_code.rb +++ b/lib/doorkeeper/request/authorization_code.rb @@ -1,14 +1,10 @@ module Doorkeeper module Request class AuthorizationCode - def self.build(server) - new(server.grant, server.client, server) - end - attr_accessor :grant, :client, :server - def initialize(grant, client, server) - @grant, @client, @server = grant, client, server + def initialize(server) + @grant, @client, @server = server.grant, server.client, server end def request diff --git a/lib/doorkeeper/request/client_credentials.rb b/lib/doorkeeper/request/client_credentials.rb index 276f980c8..8e46810cb 100644 --- a/lib/doorkeeper/request/client_credentials.rb +++ b/lib/doorkeeper/request/client_credentials.rb @@ -1,14 +1,10 @@ module Doorkeeper module Request class ClientCredentials - def self.build(server) - new(server.client, server) - end - attr_accessor :client, :server - def initialize(client, server) - @client, @server = client, server + def initialize(server) + @client, @server = server.client, server end def request diff --git a/lib/doorkeeper/request/code.rb b/lib/doorkeeper/request/code.rb index 7756d1619..6fea02b58 100644 --- a/lib/doorkeeper/request/code.rb +++ b/lib/doorkeeper/request/code.rb @@ -1,14 +1,11 @@ module Doorkeeper module Request class Code - def self.build(server) - new(server.context.send(:pre_auth), server) - end - attr_accessor :pre_auth, :server - def initialize(pre_auth, server) - @pre_auth, @server = pre_auth, server + def initialize(server) + @pre_auth = server.context.send(:pre_auth) + @server = server end def request diff --git a/lib/doorkeeper/request/password.rb b/lib/doorkeeper/request/password.rb index 5155c23f8..26d5aa166 100644 --- a/lib/doorkeeper/request/password.rb +++ b/lib/doorkeeper/request/password.rb @@ -1,14 +1,12 @@ module Doorkeeper module Request class Password - def self.build(server) - new(server.credentials, server.resource_owner, server) - end - attr_accessor :credentials, :resource_owner, :server - def initialize(credentials, resource_owner, server) - @credentials, @resource_owner, @server = credentials, resource_owner, server + def initialize(server) + @credentials = server.credentials + @resource_owner = server.resource_owner + @server = server end def request diff --git a/lib/doorkeeper/request/refresh_token.rb b/lib/doorkeeper/request/refresh_token.rb index b478dc809..d85be9366 100644 --- a/lib/doorkeeper/request/refresh_token.rb +++ b/lib/doorkeeper/request/refresh_token.rb @@ -1,14 +1,12 @@ module Doorkeeper module Request class RefreshToken - def self.build(server) - new(server.current_refresh_token, server.credentials, server) - end - attr_accessor :refresh_token, :credentials, :server - def initialize(refresh_token, credentials, server) - @refresh_token, @credentials, @server = refresh_token, credentials, server + def initialize(server) + @refresh_token = server.current_refresh_token + @credentials = server.credentials + @server = server end def request diff --git a/lib/doorkeeper/request/token.rb b/lib/doorkeeper/request/token.rb index 2878ade06..b938d2174 100644 --- a/lib/doorkeeper/request/token.rb +++ b/lib/doorkeeper/request/token.rb @@ -1,14 +1,11 @@ module Doorkeeper module Request class Token - def self.build(server) - new(server.context.send(:pre_auth), server) - end - attr_accessor :pre_auth, :server - def initialize(pre_auth, server) - @pre_auth, @server = pre_auth, server + def initialize(server) + @pre_auth = server.context.send(:pre_auth) + @server = server end def request diff --git a/lib/doorkeeper/server.rb b/lib/doorkeeper/server.rb index cbaa8dd7b..fea36bd29 100644 --- a/lib/doorkeeper/server.rb +++ b/lib/doorkeeper/server.rb @@ -8,12 +8,12 @@ def initialize(context = nil) def authorization_request(strategy) klass = Request.authorization_strategy strategy - klass.build self + klass.new self end def token_request(strategy) klass = Request.token_strategy strategy - klass.build self + klass.new self end # TODO: context should be the request diff --git a/spec/lib/server_spec.rb b/spec/lib/server_spec.rb index 7955ee860..9feed91b3 100644 --- a/spec/lib/server_spec.rb +++ b/spec/lib/server_spec.rb @@ -45,7 +45,7 @@ it 'builds the request with selected strategy' do stub_const 'Doorkeeper::Request::Code', fake_class - expect(fake_class).to receive(:build).with(subject) + expect(fake_class).to receive(:new).with(subject) subject.authorization_request :code end end From 13229e391e436febb9d564b22daa494bd714d937 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Tue, 27 Oct 2015 11:53:23 +0100 Subject: [PATCH 3/6] Push common functionality into Doorkeeper::Request::Strategy --- lib/doorkeeper/request/authorization_code.rb | 13 ++++++------- lib/doorkeeper/request/client_credentials.rb | 13 ++++++------- lib/doorkeeper/request/code.rb | 12 +++++------- lib/doorkeeper/request/password.rb | 12 +++++------- lib/doorkeeper/request/refresh_token.rb | 12 +++++------- lib/doorkeeper/request/strategy.rb | 19 +++++++++++++++++++ lib/doorkeeper/request/token.rb | 12 +++++------- 7 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 lib/doorkeeper/request/strategy.rb diff --git a/lib/doorkeeper/request/authorization_code.rb b/lib/doorkeeper/request/authorization_code.rb index 092e2e9d3..9b5d74eec 100644 --- a/lib/doorkeeper/request/authorization_code.rb +++ b/lib/doorkeeper/request/authorization_code.rb @@ -1,19 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class AuthorizationCode - attr_accessor :grant, :client, :server + class AuthorizationCode < Strategy + attr_accessor :grant, :client def initialize(server) - @grant, @client, @server = server.grant, server.client, server + super + @grant, @client = server.grant, server.client end def request @request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/client_credentials.rb b/lib/doorkeeper/request/client_credentials.rb index 8e46810cb..e65b3467e 100644 --- a/lib/doorkeeper/request/client_credentials.rb +++ b/lib/doorkeeper/request/client_credentials.rb @@ -1,19 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class ClientCredentials - attr_accessor :client, :server + class ClientCredentials < Strategy + attr_accessor :client def initialize(server) - @client, @server = server.client, server + super + @client = server.client end def request @request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/code.rb b/lib/doorkeeper/request/code.rb index 6fea02b58..c3e045c6e 100644 --- a/lib/doorkeeper/request/code.rb +++ b/lib/doorkeeper/request/code.rb @@ -1,20 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class Code - attr_accessor :pre_auth, :server + class Code < Strategy + attr_accessor :pre_auth def initialize(server) + super @pre_auth = server.context.send(:pre_auth) - @server = server end def request @request ||= OAuth::CodeRequest.new(pre_auth, server.current_resource_owner) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/password.rb b/lib/doorkeeper/request/password.rb index 26d5aa166..977eb0fa3 100644 --- a/lib/doorkeeper/request/password.rb +++ b/lib/doorkeeper/request/password.rb @@ -1,21 +1,19 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class Password - attr_accessor :credentials, :resource_owner, :server + class Password < Strategy + attr_accessor :credentials, :resource_owner def initialize(server) + super @credentials = server.credentials @resource_owner = server.resource_owner - @server = server end def request @request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/refresh_token.rb b/lib/doorkeeper/request/refresh_token.rb index d85be9366..159b45d34 100644 --- a/lib/doorkeeper/request/refresh_token.rb +++ b/lib/doorkeeper/request/refresh_token.rb @@ -1,21 +1,19 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class RefreshToken - attr_accessor :refresh_token, :credentials, :server + class RefreshToken < Strategy + attr_accessor :refresh_token, :credentials def initialize(server) + super @refresh_token = server.current_refresh_token @credentials = server.credentials - @server = server end def request @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/strategy.rb b/lib/doorkeeper/request/strategy.rb new file mode 100644 index 000000000..a1fd13551 --- /dev/null +++ b/lib/doorkeeper/request/strategy.rb @@ -0,0 +1,19 @@ +module Doorkeeper + module Request + class Strategy + attr_accessor :server + + def initialize(server) + self.server = server + end + + def request + raise NotImplementedError, "request strategies must define #request" + end + + def authorize + request.authorize + end + end + end +end diff --git a/lib/doorkeeper/request/token.rb b/lib/doorkeeper/request/token.rb index b938d2174..55e398d44 100644 --- a/lib/doorkeeper/request/token.rb +++ b/lib/doorkeeper/request/token.rb @@ -1,20 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class Token - attr_accessor :pre_auth, :server + class Token < Strategy + attr_accessor :pre_auth def initialize(server) + super @pre_auth = server.context.send(:pre_auth) - @server = server end def request @request ||= OAuth::TokenRequest.new(pre_auth, server.current_resource_owner) end - - def authorize - request.authorize - end end end end From 4b0e5ef8ae4f27d7ce17ce8adc717118c1b072d4 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Tue, 27 Oct 2015 14:25:55 +0100 Subject: [PATCH 4/6] Add some basic unit tests for the Strategy base class --- spec/lib/request/strategy_spec.rb | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/lib/request/strategy_spec.rb diff --git a/spec/lib/request/strategy_spec.rb b/spec/lib/request/strategy_spec.rb new file mode 100644 index 000000000..101dbfd81 --- /dev/null +++ b/spec/lib/request/strategy_spec.rb @@ -0,0 +1,51 @@ +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) { + 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 + } + 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 From 6c0a1591eb028e85d9a97453b44ba1697241d878 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Tue, 27 Oct 2015 12:00:18 +0100 Subject: [PATCH 5/6] Replace custom strategy initializers with delegation --- lib/doorkeeper/request/authorization_code.rb | 9 ++------- lib/doorkeeper/request/client_credentials.rb | 9 ++------- lib/doorkeeper/request/code.rb | 9 ++++----- lib/doorkeeper/request/password.rb | 10 ++-------- lib/doorkeeper/request/refresh_token.rb | 10 ++++------ lib/doorkeeper/request/token.rb | 9 ++++----- 6 files changed, 18 insertions(+), 38 deletions(-) diff --git a/lib/doorkeeper/request/authorization_code.rb b/lib/doorkeeper/request/authorization_code.rb index 9b5d74eec..5c49870e0 100644 --- a/lib/doorkeeper/request/authorization_code.rb +++ b/lib/doorkeeper/request/authorization_code.rb @@ -3,15 +3,10 @@ module Doorkeeper module Request class AuthorizationCode < Strategy - attr_accessor :grant, :client - - def initialize(server) - super - @grant, @client = server.grant, server.client - end + delegate :grant, :client, :parameters, to: :server def request - @request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, server.parameters) + @request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, parameters) end end end diff --git a/lib/doorkeeper/request/client_credentials.rb b/lib/doorkeeper/request/client_credentials.rb index e65b3467e..e41ceaa11 100644 --- a/lib/doorkeeper/request/client_credentials.rb +++ b/lib/doorkeeper/request/client_credentials.rb @@ -3,15 +3,10 @@ module Doorkeeper module Request class ClientCredentials < Strategy - attr_accessor :client - - def initialize(server) - super - @client = server.client - end + delegate :client, :parameters, to: :server def request - @request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, server.parameters) + @request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, parameters) end end end diff --git a/lib/doorkeeper/request/code.rb b/lib/doorkeeper/request/code.rb index c3e045c6e..606f64611 100644 --- a/lib/doorkeeper/request/code.rb +++ b/lib/doorkeeper/request/code.rb @@ -3,15 +3,14 @@ module Doorkeeper module Request class Code < Strategy - attr_accessor :pre_auth + delegate :current_resource_owner, to: :server - def initialize(server) - super - @pre_auth = server.context.send(:pre_auth) + def pre_auth + server.context.send(:pre_auth) end def request - @request ||= OAuth::CodeRequest.new(pre_auth, server.current_resource_owner) + @request ||= OAuth::CodeRequest.new(pre_auth, current_resource_owner) end end end diff --git a/lib/doorkeeper/request/password.rb b/lib/doorkeeper/request/password.rb index 977eb0fa3..86f1a4f8e 100644 --- a/lib/doorkeeper/request/password.rb +++ b/lib/doorkeeper/request/password.rb @@ -3,16 +3,10 @@ module Doorkeeper module Request class Password < Strategy - attr_accessor :credentials, :resource_owner - - def initialize(server) - super - @credentials = server.credentials - @resource_owner = server.resource_owner - end + delegate :credentials, :resource_owner, :parameters, to: :server def request - @request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, server.parameters) + @request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, parameters) end end end diff --git a/lib/doorkeeper/request/refresh_token.rb b/lib/doorkeeper/request/refresh_token.rb index 159b45d34..d38906988 100644 --- a/lib/doorkeeper/request/refresh_token.rb +++ b/lib/doorkeeper/request/refresh_token.rb @@ -3,16 +3,14 @@ module Doorkeeper module Request class RefreshToken < Strategy - attr_accessor :refresh_token, :credentials + delegate :credentials, :parameters, to: :server - def initialize(server) - super - @refresh_token = server.current_refresh_token - @credentials = server.credentials + def refresh_token + server.current_refresh_token end def request - @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, server.parameters) + @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, parameters) end end end diff --git a/lib/doorkeeper/request/token.rb b/lib/doorkeeper/request/token.rb index 55e398d44..bc542da44 100644 --- a/lib/doorkeeper/request/token.rb +++ b/lib/doorkeeper/request/token.rb @@ -3,15 +3,14 @@ module Doorkeeper module Request class Token < Strategy - attr_accessor :pre_auth + delegate :current_resource_owner, to: :server - def initialize(server) - super - @pre_auth = server.context.send(:pre_auth) + def pre_auth + server.context.send(:pre_auth) end def request - @request ||= OAuth::TokenRequest.new(pre_auth, server.current_resource_owner) + @request ||= OAuth::TokenRequest.new(pre_auth, current_resource_owner) end end end From 6eb9b2d6e9dd3e94e6d8c4e9362a3e085b7e15a4 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Tue, 27 Oct 2015 23:28:53 +0100 Subject: [PATCH 6/6] Style cleanup --- lib/doorkeeper/request.rb | 14 ++++++++++++-- lib/doorkeeper/request/authorization_code.rb | 7 ++++++- lib/doorkeeper/request/client_credentials.rb | 6 +++++- lib/doorkeeper/request/password.rb | 7 ++++++- lib/doorkeeper/request/refresh_token.rb | 6 +++++- lib/doorkeeper/request/strategy.rb | 6 ++---- spec/lib/request/strategy_spec.rb | 6 ++++-- 7 files changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/doorkeeper/request.rb b/lib/doorkeeper/request.rb index 045a0fb63..73289208f 100644 --- a/lib/doorkeeper/request.rb +++ b/lib/doorkeeper/request.rb @@ -10,13 +10,13 @@ module Request module_function def authorization_strategy(response_type) - get_strategy response_type, Doorkeeper.configuration.authorization_response_types + get_strategy response_type, authorization_response_types rescue NameError raise Errors::InvalidAuthorizationStrategy end def token_strategy(grant_type) - get_strategy grant_type, Doorkeeper.configuration.token_grant_types + get_strategy grant_type, token_grant_types rescue NameError raise Errors::InvalidTokenStrategy end @@ -26,5 +26,15 @@ def get_strategy(grant_or_request_type, available) fail NameError unless available.include?(grant_or_request_type.to_s) "Doorkeeper::Request::#{grant_or_request_type.to_s.camelize}".constantize end + + def authorization_response_types + Doorkeeper.configuration.authorization_response_types + end + private_class_method :authorization_response_types + + def token_grant_types + Doorkeeper.configuration.token_grant_types + end + private_class_method :token_grant_types end end diff --git a/lib/doorkeeper/request/authorization_code.rb b/lib/doorkeeper/request/authorization_code.rb index 5c49870e0..d5e2c8cb4 100644 --- a/lib/doorkeeper/request/authorization_code.rb +++ b/lib/doorkeeper/request/authorization_code.rb @@ -6,7 +6,12 @@ class AuthorizationCode < Strategy delegate :grant, :client, :parameters, to: :server def request - @request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, parameters) + @request ||= OAuth::AuthorizationCodeRequest.new( + Doorkeeper.configuration, + grant, + client, + parameters + ) end end end diff --git a/lib/doorkeeper/request/client_credentials.rb b/lib/doorkeeper/request/client_credentials.rb index e41ceaa11..3b73e01ab 100644 --- a/lib/doorkeeper/request/client_credentials.rb +++ b/lib/doorkeeper/request/client_credentials.rb @@ -6,7 +6,11 @@ class ClientCredentials < Strategy delegate :client, :parameters, to: :server def request - @request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, parameters) + @request ||= OAuth::ClientCredentialsRequest.new( + Doorkeeper.configuration, + client, + parameters + ) end end end diff --git a/lib/doorkeeper/request/password.rb b/lib/doorkeeper/request/password.rb index 86f1a4f8e..168ffe516 100644 --- a/lib/doorkeeper/request/password.rb +++ b/lib/doorkeeper/request/password.rb @@ -6,7 +6,12 @@ class Password < Strategy delegate :credentials, :resource_owner, :parameters, to: :server def request - @request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, parameters) + @request ||= OAuth::PasswordAccessTokenRequest.new( + Doorkeeper.configuration, + credentials, + resource_owner, + parameters + ) end end end diff --git a/lib/doorkeeper/request/refresh_token.rb b/lib/doorkeeper/request/refresh_token.rb index d38906988..fd0b9ec2e 100644 --- a/lib/doorkeeper/request/refresh_token.rb +++ b/lib/doorkeeper/request/refresh_token.rb @@ -10,7 +10,11 @@ def refresh_token end def request - @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, parameters) + @request ||= OAuth::RefreshTokenRequest.new( + Doorkeeper.configuration, + refresh_token, credentials, + parameters + ) end end end diff --git a/lib/doorkeeper/request/strategy.rb b/lib/doorkeeper/request/strategy.rb index a1fd13551..ecf6f4157 100644 --- a/lib/doorkeeper/request/strategy.rb +++ b/lib/doorkeeper/request/strategy.rb @@ -3,6 +3,8 @@ module Request class Strategy attr_accessor :server + delegate :authorize, to: :request + def initialize(server) self.server = server end @@ -10,10 +12,6 @@ def initialize(server) def request raise NotImplementedError, "request strategies must define #request" end - - def authorize - request.authorize - end end end end diff --git a/spec/lib/request/strategy_spec.rb b/spec/lib/request/strategy_spec.rb index 101dbfd81..e0fdcfec5 100644 --- a/spec/lib/request/strategy_spec.rb +++ b/spec/lib/request/strategy_spec.rb @@ -21,7 +21,8 @@ module Request describe "a sample Strategy subclass" do let(:fake_request) { double } - let(:strategy_class) { + + let(:strategy_class) do subclass = Class.new(Strategy) do class << self attr_accessor :fake_request @@ -34,7 +35,8 @@ def request subclass.fake_request = fake_request subclass - } + end + subject(:strategy) { strategy_class.new(server) } it "provides a request implementation" do