Sha256: 099358a03c0633f4daff92a6e29e71cfdb1bd2f2e721f424c01c0b2ede278bcb

Contents?: true

Size: 1.62 KB

Versions: 33

Compression:

Stored size: 1.62 KB

Contents

require File.join(File.dirname(__FILE__), '../../spec_helper')

describe FbGraph::Query, '.new' do

  before do
    @raw_query = 'SELECT uid FROM user WHERE uid = me()'
    @query = FbGraph::Query.new(@raw_query, 'access_token')
  end

  it 'should setup query and access_token' do
    @query.query.should == @raw_query
    @query.access_token.should == 'access_token'
  end

  it 'should setup proper endpoint' do
    endpoint = @query.send :build_endpoint
    params = {
      :query => @raw_query,
      :format => :json,
      :access_token => 'access_token'
    }
    endpoint.should == "#{FbGraph::Query::ENDPOINT}?#{params.to_query}"
  end

end

describe FbGraph::Query, '.fetch' do

  before do
    @raw_query = 'SELECT uid FROM user WHERE uid = me()'
    @query = FbGraph::Query.new(@raw_query)
  end

  context 'when no access token given' do
    before do
      fake_fql_json @raw_query, 'query/user/without_token'
    end

    it 'should return blank Hash' do
      response = @query.fetch
      response.should == {}
    end
  end

  context 'when invalid access token given' do
    before do
      fake_fql_json @raw_query, 'query/user/with_invalid_token', :access_token => 'invalid'
    end

    it 'should raise exception' do
      lambda do
        @query.fetch('invalid')
      end.should raise_error(FbGraph::Exception)
    end
  end

  context 'when valid access token given' do
    before do
      fake_fql_json @raw_query, 'query/user/with_valid_token', :access_token => 'valid'
    end

    it 'should return an Array of Hash' do
      response = @query.fetch('valid')
      response.should == [{'uid' => 579612276}]
    end
  end

end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
fb_graph-1.7.0 spec/fb_graph/query/core_spec.rb
fb_graph-1.7.0.alpha2 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.9 spec/fb_graph/query/core_spec.rb
fb_graph-1.7.0.alpha spec/fb_graph/query/core_spec.rb
fb_graph-1.6.8 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.7 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.5 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.4 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.3 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.2 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.1 spec/fb_graph/query/core_spec.rb
fb_graph-1.6.0 spec/fb_graph/query/core_spec.rb
fb_graph-1.5.5 spec/fb_graph/query/core_spec.rb
fb_graph-1.5.4 spec/fb_graph/query/core_spec.rb
fb_graph-1.5.3 spec/fb_graph/query/core_spec.rb
fb_graph-1.5.2 spec/fb_graph/query/core_spec.rb
fb_graph-1.5.1 spec/fb_graph/query/core_spec.rb
fb_graph-1.5.0 spec/fb_graph/query/core_spec.rb
fb_graph-1.4.1 spec/fb_graph/query/core_spec.rb
fb_graph-1.4.0 spec/fb_graph/query/core_spec.rb