|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe OmniAuth::Strategies::GitHub do |
| 4 | + let(:access_token) { stub('AccessToken', :options => {}) } |
| 5 | + let(:parsed_response) { stub('ParsedResponse') } |
| 6 | + let(:response) { stub('Response', :parsed => parsed_response) } |
| 7 | + |
| 8 | + let(:enterprise_site) { 'https://some.other.site.com/api/v3' } |
| 9 | + let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' } |
| 10 | + let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' } |
| 11 | + let(:enterprise) do |
| 12 | + OmniAuth::Strategies::GitHub.new('GITHUB_KEY', 'GITHUB_SECRET', |
| 13 | + { |
| 14 | + :client_options => { |
| 15 | + :site => enterprise_site, |
| 16 | + :authorize_url => enterprise_authorize_url, |
| 17 | + :token_url => enterprise_token_url |
| 18 | + } |
| 19 | + } |
| 20 | + ) |
| 21 | + end |
| 22 | + |
4 | 23 | subject do |
5 | 24 | OmniAuth::Strategies::GitHub.new({}) |
6 | 25 | end |
7 | 26 |
|
| 27 | + before(:each) do |
| 28 | + subject.stub!(:access_token).and_return(access_token) |
| 29 | + end |
| 30 | + |
8 | 31 | context "client options" do |
9 | 32 | it 'should have correct site' do |
10 | 33 | subject.options.client_options.site.should eq("https://api.github.com") |
|
17 | 40 | it 'should have correct token url' do |
18 | 41 | subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token') |
19 | 42 | end |
| 43 | + |
| 44 | + describe "should be overrideable" do |
| 45 | + it "for site" do |
| 46 | + enterprise.options.client_options.site.should eq(enterprise_site) |
| 47 | + end |
| 48 | + |
| 49 | + it "for authorize url" do |
| 50 | + enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url) |
| 51 | + end |
| 52 | + |
| 53 | + it "for token url" do |
| 54 | + enterprise.options.client_options.token_url.should eq(enterprise_token_url) |
| 55 | + end |
| 56 | + end |
20 | 57 | end |
21 | 58 |
|
22 | 59 | context "#email_access_allowed?" do |
|
80 | 117 | end |
81 | 118 | end |
82 | 119 |
|
| 120 | + context "#raw_info" do |
| 121 | + it "should use relative paths" do |
| 122 | + access_token.should_receive(:get).with('user').and_return(response) |
| 123 | + subject.raw_info.should eq(parsed_response) |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + context "#emails" do |
| 128 | + it "should use relative paths" do |
| 129 | + access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.github.v3"}).and_return(response) |
| 130 | + subject.options['scope'] = 'user' |
| 131 | + subject.emails.should eq(parsed_response) |
| 132 | + end |
| 133 | + end |
| 134 | + |
83 | 135 | end |
0 commit comments