Sha256: ef067f9f285740e602e375dd861d678b63bbeb3ce1a7478ef380f47c80bbd5d6

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Github::Client::Authorizations::App, '#check' do
  let(:basic_auth) { 'login:password' }
  let(:host)       { "https://#{basic_auth}@api.github.com" }
  let(:request_path) { "/applications/#{client_id}/tokens/#{access_token}" }
  let(:client_id) { 1 }
  let(:access_token) { 'abc123' }

  before {
    subject.basic_auth = basic_auth

    stub_get(request_path, host).to_return(body: body, status: status,
      headers: {content_type: 'application/json; charset=utf-8'})
  }

  after { reset_authentication_for(subject) }

  context 'when app makes a request' do
    let(:body)   { "" }
    let(:status) { 200 }

    it "checks resource successfully" do
      subject.check client_id, access_token
      a_get(request_path, host).should have_been_made
    end

    it "fails without client_id" do
      expect { subject.check }.to raise_error(ArgumentError)
    end

    it "fails without access_token" do
      expect {subject.check(client_id)}.to raise_error(ArgumentError)
    end
  end

  context 'when app checks a token that is valid' do
    let(:body)   { fixture('auths/check.json') }
    let(:status) { 200 }


    it "returns the resource" do
      authorization = subject.check client_id, access_token
      authorization.should be_a Github::ResponseWrapper
    end

    it "gets the authorization information" do
      authorization = subject.check client_id, access_token
      authorization.token.should == 'abc123'
    end
  end

  context 'when app checks a token that is not valid' do
    let(:body)      { '' }
    let(:status)    { 404 }

    it "does not raise error for expected 404" do
      expect { subject.check client_id, access_token }.to_not raise_error
    end

    it "returns nil" do
      authorization = subject.check client_id, access_token
      authorization.should be_nil
    end
  end
end # check

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
github_api-0.12.3 spec/github/client/authorizations/app/check_spec.rb
github_api-0.12.2 spec/github/client/authorizations/app/check_spec.rb
github_api-0.12.1 spec/github/client/authorizations/app/check_spec.rb
github_api-0.12.0 spec/github/client/authorizations/app/check_spec.rb