Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding test and travis-ci

  • Loading branch information...
commit 004379094ef45c112e6053406c0a451c4ce103de 1 parent f13f26a
@arunagw authored
View
1  .rspec
@@ -0,0 +1 @@
+--colour
View
6 .travis.yml
@@ -0,0 +1,6 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+ - ruby-head
+ - ree
View
6 Rakefile
@@ -1 +1,7 @@
require "bundler/gem_tasks"
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
+
View
99 spec/omniauth/strategies/foursquare_spec.rb
@@ -0,0 +1,99 @@
+require 'spec_helper'
+require 'omniauth-foursquare'
+
+describe OmniAuth::Strategies::Foursquare do
+ before :each do
+ @request = double('Request')
+ @request.stub(:params) { {} }
+ end
+
+ subject do
+ OmniAuth::Strategies::Foursquare.new(nil, @options || {}).tap do |strategy|
+ strategy.stub(:request) { @request }
+ end
+ end
+
+ it_should_behave_like 'an oauth2 strategy'
+
+ describe '#client' do
+ it 'has correct Foursquare site' do
+ subject.client.site.should eq('https://foursquare.com')
+ end
+
+ it 'has correct authorize url' do
+ subject.client.options[:authorize_url].should eq('/oauth2/authorize')
+ end
+
+ it 'has correct token url' do
+ subject.client.options[:token_url].should eq('/oauth2/access_token')
+ end
+ end
+
+ describe '#info' do
+ before :each do
+ @raw_info ||= { 'firstName' => 'Fred', 'lastName' => 'Smith' }
+ subject.stub(:raw_info) { @raw_info }
+ end
+
+ context 'when data is present in raw info' do
+ it 'returns the first name' do
+ subject.info[:first_name].should eq('Fred')
+ end
+
+ it 'returns the last name' do
+ subject.info[:last_name].should eq('Smith')
+ end
+ end
+ end
+
+ describe '#credentials' do
+ before :each do
+ @access_token = double('OAuth2::AccessToken')
+ @access_token.stub(:token)
+ @access_token.stub(:expires?)
+ @access_token.stub(:expires_at)
+ @access_token.stub(:refresh_token)
+ subject.stub(:access_token) { @access_token }
+ end
+
+ it 'returns a Hash' do
+ subject.credentials.should be_a(Hash)
+ end
+
+ it 'returns the token' do
+ @access_token.stub(:token) { '123' }
+ subject.credentials['token'].should eq('123')
+ end
+
+ it 'returns the expiry status' do
+ @access_token.stub(:expires?) { true }
+ subject.credentials['expires'].should eq(true)
+
+ @access_token.stub(:expires?) { false }
+ subject.credentials['expires'].should eq(false)
+ end
+
+ it 'returns the refresh token and expiry time when expiring' do
+ ten_mins_from_now = (Time.now + 360).to_i
+ @access_token.stub(:expires?) { true }
+ @access_token.stub(:refresh_token) { '321' }
+ @access_token.stub(:expires_at) { ten_mins_from_now }
+ subject.credentials['refresh_token'].should eq('321')
+ subject.credentials['expires_at'].should eq(ten_mins_from_now)
+ end
+
+ it 'does not return the refresh token when it is nil and expiring' do
+ @access_token.stub(:expires?) { true }
+ @access_token.stub(:refresh_token) { nil }
+ subject.credentials['refresh_token'].should be_nil
+ subject.credentials.should_not have_key('refresh_token')
+ end
+
+ it 'does not return the refresh token when not expiring' do
+ @access_token.stub(:expires?) { false }
+ @access_token.stub(:refresh_token) { 'XXX' }
+ subject.credentials['refresh_token'].should be_nil
+ subject.credentials.should_not have_key('refresh_token')
+ end
+ end
+end
View
6 spec/spec_helper.rb
@@ -0,0 +1,6 @@
+require 'bundler/setup'
+require 'rspec'
+Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
+
+RSpec.configure do |config|
+end
View
37 spec/support/shared_examples.rb
@@ -0,0 +1,37 @@
+# NOTE it would be useful if this lived in omniauth-oauth2 eventually
+shared_examples 'an oauth2 strategy' do
+ describe '#client' do
+ it 'should be initialized with symbolized client_options' do
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
+ subject.client.options[:authorize_url].should == 'https://example.com'
+ end
+ end
+
+ describe '#authorize_params' do
+ it 'should include any authorize params passed in the :authorize_params option' do
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
+ subject.authorize_params['foo'].should eq('bar')
+ subject.authorize_params['baz'].should eq('zip')
+ end
+
+ it 'should include top-level options that are marked as :authorize_options' do
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
+ subject.authorize_params['scope'].should eq('bar')
+ subject.authorize_params['foo'].should eq('baz')
+ end
+ end
+
+ describe '#token_params' do
+ it 'should include any authorize params passed in the :authorize_params option' do
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
+ subject.token_params['foo'].should eq('bar')
+ subject.token_params['baz'].should eq('zip')
+ end
+
+ it 'should include top-level options that are marked as :authorize_options' do
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
+ subject.token_params['scope'].should eq('bar')
+ subject.token_params['foo'].should eq('baz')
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.