Sha256: b6d24f9e9c466d6c56cf9de309f84eafbbc830774ab1b6f4217ff3d26a66a094

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

# inspired by omniauth-github, omniauth-clef and others

require 'test_helper'
require 'omniauth-matique'

describe OmniAuth::Strategies::Matique, 'raw_info test' do
  let(:strategy)     { OmniAuth::Strategies::Matique.new({}) }
  let(:access_token) { stub('OAuth2::AccessToken') }
  let(:get_param)    { '/auth/matique/user.json?oauth_token=123' }

  def setup
    super
    strategy.stubs(:access_token).returns(access_token)
    access_token.stubs(:token).returns(123)
  end

  it 'performs a GET to https://...' do
    access_token.expects(:get).with(get_param).
      returns(stub_everything('OAuth2::Response'))
    strategy.raw_info
  end

  it 'returns a Hash' do
    raw_response = stub('Faraday::Response')
    raw_response.stubs(:body).returns('{ "ohai": "thar" }')
    raw_response.stubs(:status).returns(200)
    raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
    oauth2_response = OAuth2::Response.new(raw_response)
    access_token.stubs(:get).with(get_param).returns(oauth2_response)
    assert_kind_of Hash, strategy.raw_info
    assert_equal 'thar', strategy.raw_info['ohai']
  end

  it 'returns an empty hash when the response is false' do
    oauth2_response = stub('OAuth2::Response', :parsed => false)
    access_token.stubs(:get).with(get_param).returns(oauth2_response)
    access_token.stubs(:get).with(get_param).returns(oauth2_response)
    assert_kind_of Hash, strategy.raw_info
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
omniauth-matique-0.1.8 test/raw_info_test.rb
omniauth-matique-0.1.7 test/raw_info_test.rb
omniauth-matique-0.1.5 test/raw_info_test.rb
omniauth-matique-0.1.3 test/raw_info_test.rb
omniauth-matique-0.1.2 test/raw_info_test.rb
omniauth-matique-0.1.1 test/raw_info_test.rb