-
Notifications
You must be signed in to change notification settings - Fork 302
/
authorization_controller_test.rb
30 lines (25 loc) · 1.13 KB
/
authorization_controller_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require File.dirname(__FILE__) + '/test_helper'
class Twurl::AuthorizationController::DispatchTest < MiniTest::Unit::TestCase
attr_reader :options, :client, :controller
def setup
@options = Twurl::Options.new
@client = Twurl::OAuthClient.load_new_client_from_options(options)
@controller = Twurl::AuthorizationController.new(client, options)
end
def test_successful_authentication_saves_retrieved_access_token
mock(client).exchange_credentials_for_access_token.times(1)
mock(client).save.times(1)
mock(controller).raise(Twurl::Exception, Twurl::AuthorizationController::AUTHORIZATION_FAILED_MESSAGE).never
mock(Twurl::CLI).puts(Twurl::AuthorizationController::AUTHORIZATION_SUCCEEDED_MESSAGE).times(1)
controller.dispatch
end
module ErrorCases
def test_failed_authorization_does_not_save_client
mock(client).exchange_credentials_for_access_token { raise OAuth::Unauthorized }
mock(client).save.never
mock(controller).raise(Twurl::Exception, Twurl::AuthorizationController::AUTHORIZATION_FAILED_MESSAGE).times(1)
controller.dispatch
end
end
include ErrorCases
end