Sha256: 731a2e36faa89f863a82bb93f821d2fff105463baa974eea4dd860196b7cb64c

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe CoalescingPanda::Oauth2Controller, :type => :controller do
  routes { CoalescingPanda::Engine.routes }
  let(:account) { FactoryGirl.create(:account, settings: {base_url: 'foo.com'}) }
  let(:user) { FactoryGirl.create(:user, account: account) }

  describe "#redirect" do
    it 'creates a token in the db' do
      ENV['OAUTH_PROTOCOL'] = 'http'
      Bearcat::Client.any_instance.stub(retrieve_token: { 'access_token' => 'token', 'refresh_token' => 'token', 'expires_in' => 3600 })
      session[:state] = 'test'
      CoalescingPanda::OauthState.create!(state_key: session[:state], data: { key: account.key, user_id: user.id, api_domain: 'foo.com' })
      get :redirect, {user_id: user.id, api_domain: 'foo.com', code: 'bar', key: account.key, state: 'test'}
      auth = CoalescingPanda::CanvasApiAuth.find_by_user_id_and_api_domain(user.id, 'foo.com')
      auth.should_not == nil
      expect(auth.api_token).to eql 'token'
      expect(auth.refresh_token).to eql 'token'
      expect(auth.expires_at).to be > 50.minutes.from_now
    end

    it "doesn't create a token in the db" do
      get :redirect, {error: 'your face'}
      CoalescingPanda::CanvasApiAuth.all.count.should == 0
    end
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
coalescing_panda-5.0.9 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.8 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.7 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.6 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.4 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.3 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.2 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.1 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.0 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.0.beta.2 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-5.0.0.beta.1 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.8.0.beta.1 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.7.0 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.6.1 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.6.0 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.6.0.rc3 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.6.0.rc2 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.6.0.rc1 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.5.7 spec/controllers/coalescing_panda/oauth2_controller_spec.rb
coalescing_panda-4.5.6 spec/controllers/coalescing_panda/oauth2_controller_spec.rb