Sha256: 92cfb450e4735b3d2023793f6c486a91d8723e36e9c0277d6322342c438802c3

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

require File.join File.dirname(__FILE__), 'env.rb'

describe Geoloqi::Config do
  describe 'with redirect_uri' do
    it 'returns authorize url' do
      Geoloqi.config :client_id => CLIENT_ID, :client_secret => CLIENT_SECRET, :redirect_uri => 'http://blah.blah/test'
      authorize_url = Geoloqi.authorize_url 'test'
      expect { authorize_url == "#{Geoloqi.oauth_url}?"+
                                'response_type=code&'+
                                "client_id=#{Rack::Utils.escape 'test'}&"+
                                "redirect_uri=#{Rack::Utils.escape 'http://blah.blah/test'}" }
    end
  end
  
  it 'displays log information if logger is provided' do
    stub_request(:get, api_url('account/username?cats=lol')).
      with(:headers => {'Authorization'=>'OAuth access_token1234'}).
      to_return(:body => {'username' => 'bulbasaurrulzok'}.to_json)
    
    io = StringIO.new
    Geoloqi.config :client_id => CLIENT_ID, :client_secret => CLIENT_SECRET, :logger => io
    
    Geoloqi.get ACCESS_TOKEN, 'account/username', :cats => 'lol'
    expect { io.string =~ /Geoloqi::Session/ }
  end
  
  it 'displays log information if logger is provided and query is nil' do
    stub_request(:get, api_url('account/username')).
      with(:headers => {'Authorization'=>'OAuth access_token1234'}).
      to_return(:body => {'username' => 'bulbasaurrulzok'}.to_json)
    
    io = StringIO.new
    Geoloqi.config :client_id => CLIENT_ID, :client_secret => CLIENT_SECRET, :logger => io
    
    Geoloqi.get ACCESS_TOKEN, 'account/username'
    expect { io.string =~ /Geoloqi::Session/ }
  end

  it 'correctly checks booleans for client_id and client_secret' do
    [:client_id, :client_secret].each do |k|
      expect { Geoloqi.config(k => '').send("#{k}?") == false }
      expect { Geoloqi.config(k => nil).send("#{k}?") == false }
      expect { Geoloqi.config(k => 'lol').send("#{k}?") == true }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geoloqi-0.9.33 spec/geoloqi_config.rb
geoloqi-0.9.32 spec/geoloqi_config.rb
geoloqi-0.9.31 spec/geoloqi_config.rb
geoloqi-0.9.30 spec/geoloqi_config.rb
geoloqi-0.9.28 spec/geoloqi_config.rb
geoloqi-0.9.27 spec/geoloqi_config.rb