spec/omniauth/strategies/outrightmental_spec.rb in omniauth-outrightmental-0.1.5 vs spec/omniauth/strategies/outrightmental_spec.rb in omniauth-outrightmental-0.1.7

- old
+ new

@@ -19,28 +19,27 @@ } ) end subject do - OmniAuth::Strategies::OutrightMental.new({}) + OmniAuth::Strategies::OutrightMental end - before(:each) do - subject.stub(:access_token).and_return(access_token) - end - context "client options" do it 'should have correct site' do - subject.options.client_options.site.should eq("https://ont.io/") + instance = subject.new({}) + instance.options.client_options.site.should eq("https://ont.io/") end it 'should have correct authorize url' do - subject.options.client_options.authorize_url.should eq('https://ont.io/#/auth/authorize') + instance = subject.new({}) + instance.options.client_options.authorize_url.should eq('https://ont.io/oauth/authorize') end it 'should have correct token url' do - subject.options.client_options.token_url.should eq('https://ont.io/#/auth/token') + instance = subject.new({}) + instance.options.client_options.token_url.should eq('https://ont.io/oauth/token') end describe "should be overrideable" do it "for site" do enterprise.options.client_options.site.should eq(enterprise_site) @@ -56,87 +55,101 @@ end end context "#email_access_allowed?" do it "should not allow email if scope is nil" do - subject.options['scope'].should be_nil - subject.should_not be_email_access_allowed + instance = subject.new({}) + instance.options['scope'].should be_nil + instance.should_not be_email_access_allowed end it "should allow email if scope is user" do - subject.options['scope'] = 'user' - subject.should be_email_access_allowed + instance = subject.new({}) + instance.options['scope'] = 'user' + instance.should be_email_access_allowed end it "should allow email if scope is a bunch of stuff including user" do - subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist' - subject.should be_email_access_allowed + instance = subject.new({}) + instance.options['scope'] = 'public_repo,user,repo,delete_repo,gist' + instance.should be_email_access_allowed end it "should not allow email if scope does not grant email access" do - subject.options['scope'] = 'repo,user:follow' - subject.should_not be_email_access_allowed + instance = subject.new({}) + instance.options['scope'] = 'repo,user:follow' + instance.should_not be_email_access_allowed end it "should assume email access not allowed if scope is something currently not documented " do - subject.options['scope'] = 'currently_not_documented' - subject.should_not be_email_access_allowed + instance = subject.new({}) + instance.options['scope'] = 'currently_not_documented' + instance.should_not be_email_access_allowed end end context "#email" do it "should return email from raw_info if available" do - subject.stub(:raw_info).and_return({'email' => 'you@example.com'}) - subject.email.should eq('you@example.com') + instance = subject.new({}) + instance.stub(:raw_info).and_return({'email' => 'you@example.com'}) + instance.email.should eq('you@example.com') end it "should return nil if there is no raw_info and email access is not allowed" do - subject.stub(:raw_info).and_return({}) - subject.email.should be_nil + instance = subject.new({}) + instance.stub(:raw_info).and_return({}) + instance.email.should be_nil end it "should return the primary email if there is no raw_info and email access is allowed" do + instance = subject.new({}) emails = [ { 'email' => 'secondary@example.com', 'primary' => false }, { 'email' => 'primary@example.com', 'primary' => true } ] - subject.stub(:raw_info).and_return({}) - subject.options['scope'] = 'user' - subject.stub(:emails).and_return(emails) - subject.email.should eq('primary@example.com') + instance.stub(:raw_info).and_return({}) + instance.options['scope'] = 'user' + instance.stub(:emails).and_return(emails) + instance.email.should eq('primary@example.com') end it "should return the first email if there is no raw_info and email access is allowed" do + instance = subject.new({}) emails = [ { 'email' => 'first@example.com', 'primary' => false }, { 'email' => 'second@example.com', 'primary' => false } ] - subject.stub(:raw_info).and_return({}) - subject.options['scope'] = 'user' - subject.stub(:emails).and_return(emails) - subject.email.should eq('first@example.com') + instance.stub(:raw_info).and_return({}) + instance.options['scope'] = 'user' + instance.stub(:emails).and_return(emails) + instance.email.should eq('first@example.com') end end context "#raw_info" do it "should use relative paths" do + instance = subject.new({}) + instance.stub(:access_token).and_return(access_token) access_token.should_receive(:get).with('user').and_return(response) - subject.raw_info.should eq(parsed_response) + instance.raw_info.should eq(parsed_response) end end context "#emails" do it "should use relative paths" do + instance = subject.new({}) + instance.stub(:access_token).and_return(access_token) access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.outrightmental.v1"}).and_return(response) - subject.options['scope'] = 'user' - subject.emails.should eq(parsed_response) + instance.options['scope'] = 'user' + instance.emails.should eq(parsed_response) end end context '#info.urls' do it 'should use html_url from raw_info' do - subject.stub(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' }) - subject.info['urls']['OutrightMental'].should == 'http://enterprise/me' + instance = subject.new({}) + instance.stub(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' }) + instance.info['urls']['OutrightMental'].should == 'http://enterprise/me' end end end