File: developer_spec.rb

package info (click to toggle)
ruby-omniauth 1.3.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 324 kB
  • sloc: ruby: 1,896; makefile: 3
file content (73 lines) | stat: -rw-r--r-- 2,136 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'helper'

describe OmniAuth::Strategies::Developer do
  let(:app) do
    Rack::Builder.new do |b|
      b.use Rack::Session::Cookie, :secret => 'abc123'
      b.use OmniAuth::Strategies::Developer
      b.run lambda { |_env| [200, {}, ['Not Found']] }
    end.to_app
  end

  context 'request phase' do
    before(:each) { get '/auth/developer' }

    it 'displays a form' do
      expect(last_response.status).to eq(200)
      expect(last_response.body).to be_include('<form')
    end

    it 'has the callback as the action for the form' do
      expect(last_response.body).to be_include("action='/auth/developer/callback'")
    end

    it 'has a text field for each of the fields' do
      expect(last_response.body.scan('<input').size).to eq(2)
    end
  end

  context 'callback phase' do
    let(:auth_hash) { last_request.env['omniauth.auth'] }

    context 'with default options' do
      before do
        post '/auth/developer/callback', :name => 'Example User', :email => 'user@example.com'
      end

      it 'sets the name in the auth hash' do
        expect(auth_hash.info.name).to eq('Example User')
      end

      it 'sets the email in the auth hash' do
        expect(auth_hash.info.email).to eq('user@example.com')
      end

      it 'sets the uid to the email' do
        expect(auth_hash.uid).to eq('user@example.com')
      end
    end

    context 'with custom options' do
      let(:app) do
        Rack::Builder.new do |b|
          b.use Rack::Session::Cookie, :secret => 'abc123'
          b.use OmniAuth::Strategies::Developer, :fields => [:first_name, :last_name], :uid_field => :last_name
          b.run lambda { |_env| [200, {}, ['Not Found']] }
        end.to_app
      end

      before do
        @options = {:uid_field => :last_name, :fields => [:first_name, :last_name]}
        post '/auth/developer/callback', :first_name => 'Example', :last_name => 'User'
      end

      it 'sets info fields properly' do
        expect(auth_hash.info.name).to eq('Example User')
      end

      it 'sets the uid properly' do
        expect(auth_hash.uid).to eq('User')
      end
    end
  end
end