<commit_before>require "../spec_helper"

describe Crest::Response do
  it "do GET request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments")
    response = resource.get
    (response.body).should eq("Post 1: comments")
  end

  it "do GET request with []" do
    site = Crest::Resource.new("#{TEST_SERVER_URL}")
    response = site["/post/1/comments"].get
    (response.body).should eq("Post 1: comments")
  end

  it "do GET request with params" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/resize")
    response = resource.get(params: {:width => "100", :height => 100})
    (response.body).should eq("Width: 100, height: 100")
  end

  it "do GET request with [] and params" do
    resource = Crest::Resource.new(TEST_SERVER_URL)
    response = resource["/resize"].get(params: {:width => 100, :height => 100})
    (response.body).should eq("Width: 100, height: 100")
  end

  it "do GET request with [] and default params" do
    resource = Crest::Resource.new(
      TEST_SERVER_URL,
      params: {:width => 100, :height => 100}
    )
    response = resource["/resize"].get
    (response.body).should eq("Width: 100, height: 100")
  end

  it "do POST request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments")
    response = resource.post({:title => "Title"})
    (response.body).should eq("Post with title `Title` created")
  end

  it "do POST request with []" do
    site = Crest::Resource.new(TEST_SERVER_URL)
    response = site["/post/1/comments"].post({:title => "Title"})
    (response.body).should eq("Post with title `Title` created")
  end

  it "do POST request with [] and default params" do
    site = Crest::Resource.new(TEST_SERVER_URL, params: {"key" => "key"})
    response = site["/resize"].post(
      payload: {:height => 100, "width" => "100"},
      params: {:secret => "secret"}
    )
    (response.body).should eq("Width: 100, height: 100. Key: key, secret: secret")
  end

  it "do PUT request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments/1")
    response = resource.put({:title => "Put Update"})
    (response.body).should eq("Update Comment `1` for Post `1` with title `Put Update`")
  end

  it "do PATCH request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments/1")<commit_msg>test upload file in resource<commit_after>require "../spec_helper"

describe Crest::Response do
  it "do GET request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments")
    response = resource.get
    (response.body).should eq("Post 1: comments")
  end

  it "do GET request with []" do
    site = Crest::Resource.new("#{TEST_SERVER_URL}")
    response = site["/post/1/comments"].get
    (response.body).should eq("Post 1: comments")
  end

  it "do GET request with params" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/resize")
    response = resource.get(params: {:width => "100", :height => 100})
    (response.body).should eq("Width: 100, height: 100")
  end

  it "do GET request with [] and params" do
    resource = Crest::Resource.new(TEST_SERVER_URL)
    response = resource["/resize"].get(params: {:width => 100, :height => 100})
    (response.body).should eq("Width: 100, height: 100")
  end

  it "do GET request with [] and default params" do
    resource = Crest::Resource.new(
      TEST_SERVER_URL,
      params: {:width => 100, :height => 100}
    )
    response = resource["/resize"].get
    (response.body).should eq("Width: 100, height: 100")
  end

  it "do POST request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments")
    response = resource.post({:title => "Title"})
    (response.body).should eq("Post with title `Title` created")
  end

  it "do POST request with []" do
    site = Crest::Resource.new(TEST_SERVER_URL)
    response = site["/post/1/comments"].post({:title => "Title"})
    (response.body).should eq("Post with title `Title` created")
  end

  it "do POST request with [] and default params" do
    site = Crest::Resource.new(TEST_SERVER_URL, params: {"key" => "key"})
    response = site["/resize"].post(
      payload: {:height => 100, "width" => "100"},
      params: {:secret => "secret"}
    )
    (response.body).should eq("Width: 100, height: 100. Key: key, secret: secret")
  end

  it "upload file" do
    file = File.open("#{__DIR__}/../support/fff.png")
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/upload")
    response = resource.post(payload: {:image1 => file})

    (response.body).should eq("Upload ok")
  end

  it "upload file with []" do
    file = File.open("#{__DIR__}/../support/fff.png")
    resource = Crest::Resource.new("#{TEST_SERVER_URL}")
    response = resource["/upload"].post(payload: {:image1 => file})

    (response.body).should eq("Upload ok")
  end

  it "do PUT request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments/1")
    response = resource.put({:title => "Put Update"})
    (response.body).should eq("Update Comment `1` for Post `1` with title `Put Update`")
  end

  it "do PATCH request" do
    resource = Crest::Resource.new("#{TEST_SERVER_URL}/post/1/comments/1")
{'fraction_non_alphanumeric': 0.16965490649701176, 'fraction_numerical': 0.023520339309812992, 'mean_word_length': 3.6865401987353206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '6592655', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1636, 'n_words': 438}