<commit_before>RSpec.describe Bitly::HTTP::Request do
  let(:uri) { URI.parse("http://example.com") }

  it "is initialized with a URI and the method is GET by default" do
    request = Bitly::HTTP::Request.new(uri: uri)
    expect(request.uri).to eq(uri)
    expect(request.method).to eq("GET")
  end

  it "is initialized with a URI and a method" do
    request = Bitly::HTTP::Request.new(uri: uri, method: "POST")
    expect(request.uri).to eq(uri)
    expect(request.method).to eq("POST")
  end

  it "is initialized with a URI and a method and an optional params hash" do
    request = Bitly::HTTP::Request.new(uri: uri, method: "GET", params: { "foo" => "bar" })
    expect(request.params).to eq({ "foo" => "bar" })
  end

  it "is initialized with a URI and a method and an optional headers hash" do
    request = Bitly::HTTP::Request.new(uri: uri, method: "GET", headers: { "foo" => "bar" })
    expect(request.headers).to eq({ "foo" => "bar" })
  end

  it "expects the uri to be an object of type URI" do
    expect {
      Bitly::HTTP::Request.new(uri: "http://example.com", method: "GET")
    }.to raise_error(ArgumentError)
  end

  it "expects the method to be an HTTP method" do
    expect {
      Bitly::HTTP::Request.new(uri: uri, method: "SLEEP")
    }.to raise_error(ArgumentError)
  end

  it "expects the params to be a hash" do
    expect {
      Bitly::HTTP::Request.new(uri: uri, method: "GET", params: "wrong")
    }.to raise_error(ArgumentError)
  end

  it "expects the headers to be a hash" do
    expect {
      Bitly::HTTP::Request.new(uri: uri, method: "GET", headers: "wrong")
    }.to raise_error(ArgumentError)
  end

  describe "when the method is GET" do
    it "adds the params to the URL query string" do
      request = Bitly::HTTP::Request.new(uri: uri, method: "GET", params: { "foo" => "bar" })
      expect(request.uri.to_s).to eq("http://example.com?foo=bar")
    end

    it "adds the params to the existing URL query string" do
      uri.query = "foo=baz"
      request = Bitly::HTTP::Request.new(uri: uri, method: "GET", params: { "foo" => "bar" })
      expect(request.uri.to_s).to eq("http://example.com?foo=baz&foo=bar")
    end
  end

end<commit_msg>Ensure parameters aren't added to the URI in a POST.<commit_after>RSpec.describe Bitly::HTTP::Request do
  let(:uri) { URI.parse("http://example.com") }

  it "is initialized with a URI and the method is GET by default" do
    request = Bitly::HTTP::Request.new(uri: uri)
    expect(request.uri).to eq(uri)
    expect(request.method).to eq("GET")
  end

  it "is initialized with a URI and a method" do
    request = Bitly::HTTP::Request.new(uri: uri, method: "POST")
    expect(request.uri).to eq(uri)
    expect(request.method).to eq("POST")
  end

  it "is initialized with a URI and a method and an optional params hash" do
    request = Bitly::HTTP::Request.new(uri: uri, method: "GET", params: { "foo" => "bar" })
    expect(request.params).to eq({ "foo" => "bar" })
  end

  it "is initialized with a URI and a method and an optional headers hash" do
    request = Bitly::HTTP::Request.new(uri: uri, method: "GET", headers: { "foo" => "bar" })
    expect(request.headers).to eq({ "foo" => "bar" })
  end

  it "expects the uri to be an object of type URI" do
    expect {
      Bitly::HTTP::Request.new(uri: "http://example.com", method: "GET")
    }.to raise_error(ArgumentError)
  end

  it "expects the method to be an HTTP method" do
    expect {
      Bitly::HTTP::Request.new(uri: uri, method: "SLEEP")
    }.to raise_error(ArgumentError)
  end

  it "expects the params to be a hash" do
    expect {
      Bitly::HTTP::Request.new(uri: uri, method: "GET", params: "wrong")
    }.to raise_error(ArgumentError)
  end

  it "expects the headers to be a hash" do
    expect {
      Bitly::HTTP::Request.new(uri: uri, method: "GET", headers: "wrong")
    }.to raise_error(ArgumentError)
  end

  describe "when the method is GET" do
    it "adds the params to the URL query string" do
      request = Bitly::HTTP::Request.new(uri: uri, method: "GET", params: { "foo" => "bar" })
      expect(request.uri.to_s).to eq("http://example.com?foo=bar")
    end

    it "adds the params to the existing URL query string" do
      uri.query = "foo=baz"
      request = Bitly::HTTP::Request.new(uri: uri, method: "GET", params: { "foo" => "bar" })
      expect(request.uri.to_s).to eq("http://example.com?foo=baz&foo=bar")
    end
  end

  describe "when the method is POST" do
    it "doesn't add the params to the URL query string" do
      request = Bitly::HTTP::Request.new(uri: uri, method: "POST", params: { "foo" => "bar" })
      expect(request.uri.to_s).to eq("http://example.com")
    end

    it "keeps an existing query string, but doesn't add parameters" do
      uri.query = "foo=baz"
      request = Bitly::HTTP::Request.new(uri: uri, method: "POST", params: { "foo" => "bar" })
      expect(request.uri.to_s).to eq("http://example.com?foo=baz")
    end
  end
end
{'fraction_non_alphanumeric': 0.15186822016874246, 'fraction_numerical': 0.0, 'mean_word_length': 3.375219683655536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7368189', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1644, 'n_words': 528}