<commit_before>require "spec_helper"
require 'faraday'
require 'wordpress/client'
require 'wordpress/request'

describe Wordpress::Client do
  subject :client do
    Wordpress::Client.new
  end

  context do
    it "should call get request" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      Faraday::Connection.any_instance.should_receive(:get).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:get, 'url', {})
      client.call(request)
    end

    it "should call post request" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      req.should_receive(:body=).with(anything)
      Faraday::Connection.any_instance.should_receive(:post).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:post, 'url', {}, {})
      client.call(request)
    end
  end

  context "with bearer_token_request option" do
    it "should call get request" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.headers.should_receive(:[]=).with('Authorization', 'Bearer something').once
      req.headers.should_receive(:[]=).with(any_args).at_least(:once)
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      Faraday::Connection.any_instance.should_receive(:get).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:get, 'url', {})
      client.access_token = 'something'
      client.call(request, :bearer_token_request => true)
    end
  end
end<commit_msg>Add spec test for no access token request.<commit_after>require "spec_helper"
require 'faraday'
require 'wordpress/client'
require 'wordpress/request'

describe Wordpress::Client do
  subject :client do
    Wordpress::Client.new
  end

  context do
    it "should call get request" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      Faraday::Connection.any_instance.should_receive(:get).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:get, 'url', {})
      client.call(request)
    end

    it "should call post request" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      req.should_receive(:body=).with(anything)
      Faraday::Connection.any_instance.should_receive(:post).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:post, 'url', {}, {})
      client.call(request)
    end
  end

  context "with bearer_token_request option" do
    it "should call get request with Authorization header" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.headers.should_receive(:[]=).with('Authorization', 'Bearer something').once
      req.headers.should_receive(:[]=).with(any_args).at_least(:once)
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      Faraday::Connection.any_instance.should_receive(:get).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:get, 'url', {})
      client.access_token = '<PASSWORD>'
      client.call(request, :bearer_token_request => true)
    end

    it "should call get request without Authorization header for no access_token" do
      req = Faraday::Request.new
      req.stub(:headers).and_return({})
      req.headers.should_not_receive(:[]=).with('Authorization', 'Bearer something')
      req.stub(:options).and_return({})
      req.should_receive(:url).with(anything)
      req.should_receive(:params=).with(anything)
      Faraday::Connection.any_instance.should_receive(:get).and_yield(req).and_return(Faraday::Response.new)

      request = Wordpress::Request.new(:get, 'url', {})
      client.call(request, :bearer_token_request => true)
    end
  end
end
{'fraction_non_alphanumeric': 0.14828048235819563, 'fraction_numerical': 0.0, 'mean_word_length': 4.078231292517007, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '7222952', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1378, 'n_words': 216}