Sha256: 0db36dd5014d79d72ca0d751d4b02957f079f3a8d2e92957f33256546b671e36

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require File.dirname(__FILE__) + '/test_helper'

class Twurl::AuthorizationController::DispatchTest < Minitest::Test
  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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twurl-0.9.2 test/authorization_controller_test.rb
twurl-0.9.1 test/authorization_controller_test.rb
twurl-0.9.0 test/authorization_controller_test.rb
twurl-0.8.3 test/authorization_controller_test.rb
twurl-0.8.2 test/authorization_controller_test.rb