-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove comment from andela_auth_mock.rb [#137599493]
- Loading branch information
Ologho Cyril Paul
committed
Feb 1, 2017
1 parent
23812a8
commit cb46396
Showing
1 changed file
with
64 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
module AndelaAuthMock | ||
extend ActiveSupport::Concern | ||
|
||
require 'webmock/rspec' | ||
WebMock.disable_net_connect!(allow_localhost: true) | ||
|
||
included do | ||
before(:each) do | ||
stub_authorized_user_auth | ||
stub_unauthorized_user_auth | ||
end | ||
end | ||
|
||
def auth_server | ||
Connection::FaradayConnection::BASE_ANDELA_URL + "/api/v1/users/me" | ||
end | ||
|
||
def stub_authorized_user_auth | ||
stub_request(:get, auth_server).with(headers: authorization_header). | ||
to_return(body: Notifications::UserSerializer.new(valid_user, root: false).to_json) | ||
end | ||
|
||
def stub_unauthorized_user_auth | ||
stub_request(:get, auth_server).with(headers: unauthorized_token). | ||
to_return(status: 401, body: {error: true}.to_json) | ||
end | ||
|
||
def authorization_header | ||
{ Authorization: "Bearer samplebearertokencanbefoundhere" } | ||
end | ||
|
||
def unauthorized_token | ||
{ Authorization: "Bearer whatever"} | ||
end | ||
|
||
def valid_user | ||
@valid_user ||= create(:user) | ||
end | ||
|
||
module AuthControllerHelper | ||
extend ActiveSupport::Concern | ||
|
||
RSpec.configure do |config| | ||
config.include self#, type: :controller | ||
end | ||
|
||
included do | ||
before(:each, valid_request: true, type: :controller) do | ||
request.headers["Authorization"] = "Bearer samplebearertokencanbefoundhere" | ||
end | ||
|
||
before(:each, invalid_request: true, type: :controller) do | ||
request.headers["Authorization"] = "Bearer whatever" | ||
end | ||
|
||
end | ||
|
||
|
||
end | ||
|
||
RSpec.configure do |config| | ||
config.include self, type: :request | ||
config.include self, type: :controller | ||
end | ||
module AndelaAuthMock | ||
extend ActiveSupport::Concern | ||
|
||
require 'webmock/rspec' | ||
WebMock.disable_net_connect!(allow_localhost: true) | ||
|
||
included do | ||
before(:each) do | ||
stub_authorized_user_auth | ||
stub_unauthorized_user_auth | ||
end | ||
end | ||
|
||
def auth_server | ||
Connection::FaradayConnection::BASE_ANDELA_URL + "/api/v1/users/me" | ||
end | ||
|
||
def stub_authorized_user_auth | ||
stub_request(:get, auth_server).with(headers: authorization_header). | ||
to_return(body: Notifications::UserSerializer.new(valid_user, root: false).to_json) | ||
end | ||
|
||
def stub_unauthorized_user_auth | ||
stub_request(:get, auth_server).with(headers: unauthorized_token). | ||
to_return(status: 401, body: {error: true}.to_json) | ||
end | ||
|
||
def authorization_header | ||
{ Authorization: "Bearer samplebearertokencanbefoundhere" } | ||
end | ||
|
||
def unauthorized_token | ||
{ Authorization: "Bearer whatever"} | ||
end | ||
|
||
def valid_user | ||
@valid_user ||= create(:user) | ||
end | ||
|
||
module AuthControllerHelper | ||
extend ActiveSupport::Concern | ||
|
||
RSpec.configure do |config| | ||
config.include self | ||
end | ||
|
||
included do | ||
before(:each, valid_request: true, type: :controller) do | ||
request.headers["Authorization"] = "Bearer samplebearertokencanbefoundhere" | ||
end | ||
|
||
before(:each, invalid_request: true, type: :controller) do | ||
request.headers["Authorization"] = "Bearer whatever" | ||
end | ||
|
||
end | ||
|
||
|
||
end | ||
|
||
RSpec.configure do |config| | ||
config.include self, type: :request | ||
config.include self, type: :controller | ||
end | ||
end |