<commit_before>
if respond_to?(:require_relative, true)
  require_relative 'common'
else
  require File.dirname(__FILE__) + '/common'
end

describe RestGraph do
  after do
    WebMock.reset!
    RR.verify
  end

  should 'generate correct url' do
    TestHelper.normalize_url(
    RestGraph.new(:access_token => 'awesome').url('path', :query => 'str')).
      should ==
        'https://graph.facebook.com/path?access_token=awesome&query=str'
  end

  should 'request to correct server' do
    stub_request(:get, 'http://nothing.godfat.org/me').with(
      :headers => {'Accept'          => 'text/plain',
                   'Accept-Language' => 'zh-tw',
                   'Accept-Encoding' => 'gzip, deflate', # this is by ruby
                  }.merge(RUBY_VERSION < '1.9.2' ?
                  {} :
                  {'User-Agent'      => 'Ruby'})).       # this is by ruby
      to_return(:body => '{"data": []}')

    RestGraph.new(:graph_server => 'http://nothing.godfat.org/',
                  :lang   => 'zh-tw',
                  :accept => 'text/plain').get('me').should == {'data' => []}
  end

  should 'post right' do
    stub_request(:post, 'https://graph.facebook.com/feed/me').
      with(:body => 'message=hi%20there').to_return(:body => 'ok')

    RestGraph.new(:auto_decode => false).
      post('feed/me', :message => 'hi there').should == 'ok'
  end

  should 'suppress auto-decode in an api call' do
    stub_request(:get, 'https://graph.facebook.com/woot').
      to_return(:body => 'bad json')

    rg = RestGraph.new(:auto_decode => true)
    rg.get('woot', {}, :suppress_decode => true).should == 'bad json'
    rg.auto_decode.should == true
  end

  should 'call post_request after request' do
    url = 'https://graph.facebook.com/feed/me'
    stub_request(:put, url).
      with(:body => 'message=hi%20there').to_return(:body => '[]')

    mock.proxy(rg = RestGraph.new).post_request('[]', url, {})
    rg.put('feed/me', :message => 'hi there').
      should == []
  end

  should 'not raise exception when encountering error' do<commit_msg>test_api.rb: test for :secret => true<commit_after>
if respond_to?(:require_relative, true)
  require_relative 'common'
else
  require File.dirname(__FILE__) + '/common'
end

describe RestGraph do
  after do
    WebMock.reset!
    RR.verify
  end

  should 'generate correct url' do
    TestHelper.normalize_url(
    RestGraph.new(:access_token => 'awesome').url('path', :query => 'str')).
      should ==
        'https://graph.facebook.com/path?access_token=awesome&query=str'
  end

  should 'request to correct server' do
    stub_request(:get, 'http://nothing.godfat.org/me').with(
      :headers => {'Accept'          => 'text/plain',
                   'Accept-Language' => 'zh-tw',
                   'Accept-Encoding' => 'gzip, deflate', # this is by ruby
                  }.merge(RUBY_VERSION < '1.9.2' ?
                  {} :
                  {'User-Agent'      => 'Ruby'})).       # this is by ruby
      to_return(:body => '{"data": []}')

    RestGraph.new(:graph_server => 'http://nothing.godfat.org/',
                  :lang   => 'zh-tw',
                  :accept => 'text/plain').get('me').should == {'data' => []}
  end

  should 'post right' do
    stub_request(:post, 'https://graph.facebook.com/feed/me').
      with(:body => 'message=hi%20there').to_return(:body => 'ok')

    RestGraph.new(:auto_decode => false).
      post('feed/me', :message => 'hi there').should == 'ok'
  end

  should 'use secret_access_token' do
    stub_request(:get,
      'https://graph.facebook.com/me?access_token=1|2').
      to_return(:body => 'ok')

    RestGraph.new(:auto_decode => false, :access_token => 'wrong',
                  :app_id => '1', :secret => '2').
      get('me', {}, :secret => true).should == 'ok'
  end

  should 'suppress auto-decode in an api call' do
    stub_request(:get, 'https://graph.facebook.com/woot').
      to_return(:body => 'bad json')

    rg = RestGraph.new(:auto_decode => true)
    rg.get('woot', {}, :suppress_decode => true).should == 'bad json'
    rg.auto_decode.should == true
  end

  should 'call post_request after request' do
    url = 'https://graph.facebook.com/feed/me'
    stub_request(:put, url).
      with(:body => 'message=hi%20there').to_return(:body => '[]')

    mock.proxy(rg = RestGraph.new).post_request('[]', url, {})
    rg.put('feed/me', :message => 'hi there').
      should == []
  end

  should 'not raise exception when encountering error' do
{'fraction_non_alphanumeric': 0.17908787541713014, 'fraction_numerical': 0.004004449388209121, 'mean_word_length': 2.640485829959514, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2308738', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1435, 'n_words': 304}