Skip to content

Commit

Permalink
symbolize failover
Browse files Browse the repository at this point in the history
  • Loading branch information
lluft committed Dec 14, 2017
1 parent 13278c0 commit eb238d1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
castle-rb (3.0.1)
castle-rb (3.1.0)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion lib/castle/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def authenticate(options = {})
if tracked?
command = Castle::Commands::Authenticate.new(@context).build(options)
begin
@api.request(command).merge('failover' => false, 'failover_reason' => nil)
@api.request(command).merge(failover: false, failover_reason: nil)
rescue Castle::RequestError, Castle::InternalServerError => error
failover_response_or_raise(FailoverAuthResponse.new(options[:user_id], reason: error.to_s), error)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/castle/failover_auth_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def initialize(user_id, strategy: Castle.config.failover_strategy, reason:)

def generate
{
'action' => @strategy.to_s,
'user_id' => @user_id,
'failover' => true,
'failover_reason' => @reason
action: @strategy.to_s,
user_id: @user_id,
failover: true,
failover_reason: @reason
}
end
end
Expand Down
28 changes: 14 additions & 14 deletions spec/lib/castle/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
end
end

it { expect(request_response['failover']).to be false }
it { expect(request_response['failover_reason']).to be_nil }
it { expect(request_response[:failover]).to be false }
it { expect(request_response[:failover_reason]).to be_nil }
end

context 'tracking disabled' do
Expand All @@ -115,10 +115,10 @@
end

it { assert_not_requested :post, 'https://api.castle.io/v1/authenticate' }
it { expect(request_response['action']).to be_eql('allow') }
it { expect(request_response['user_id']).to be_eql('1234') }
it { expect(request_response['failover']).to be true }
it { expect(request_response['failover_reason']).to be_eql('Castle set to do not track.') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
it { expect(request_response[:failover_reason]).to be_eql('Castle set to do not track.') }
end

context 'when request with fail' do
Expand All @@ -132,10 +132,10 @@

context 'with request error and not throw on eg deny strategy' do
it { assert_not_requested :post, 'https://:secret@api.castle.io/v1/authenticate' }
it { expect(request_response['action']).to be_eql('allow') }
it { expect(request_response['user_id']).to be_eql('1234') }
it { expect(request_response['failover']).to be true }
it { expect(request_response['failover_reason']).to be_eql('Castle::RequestError') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
it { expect(request_response[:failover_reason]).to be_eql('Castle::RequestError') }
end
end

Expand All @@ -150,10 +150,10 @@

context 'not throw on eg deny strategy' do
it { assert_not_requested :post, 'https://:secret@api.castle.io/v1/authenticate' }
it { expect(request_response['action']).to be_eql('allow') }
it { expect(request_response['user_id']).to be_eql('1234') }
it { expect(request_response['failover']).to be true }
it { expect(request_response['failover_reason']).to be_eql('Castle::InternalServerError') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
it { expect(request_response[:failover_reason]).to be_eql('Castle::InternalServerError') }
end
end
end
Expand Down

0 comments on commit eb238d1

Please sign in to comment.