<commit_before>require 'spec_helper'
require 'shared_examples'

describe "GET /request_data" do
  let(:url) {'http://www.example.com/feed.rss'}

  context "The request is not stored" do

    before(:each) do
      REDIS.stub(:hgetall).with(url).and_return({})
    end

    it_should_behave_like "a successful request", '/request_data?url=http://www.example.com/feed.rss',
      "Request data not found.", "json", true
  end

  context "The request is stored" do

    before(:each) do
      Timecop.freeze(Time.now)
    end

    before(:each) do
      REDIS.stub(:hgetall).with(url).and_return({
        "response" => "Stored response",
        "count" => "5",
        "updated" => Time.now.to_i.to_s,
        "created" => (Time.now.to_i - 10).to_s
      })
    end

    context "The include response param is set to 'true'" do
      before(:each) do
        REDIS.stub(:hincrby)
      end

      it "increments the request's count by 1" do
        REDIS.should_receive(:hincrby).with(url, "count", 1)
        get "/request_data?url=#{url}&include_response=true"
      end

      it_should_behave_like "a successful request",
        '/request_data?url=http://www.example.com/feed.rss&include_response=true',
        { "http://www.example.com/feed.rss" =>
          {
            "response" => "Stored response",
            "count" => "6",
            "updated" => Time.now.to_i.to_s,
            "created" => (Time.now.to_i - 10).to_s
          }
        }.to_json, "json"
    end

    context "The include response param is not set" do<commit_msg>removed unnecessary before<commit_after>require 'spec_helper'
require 'shared_examples'

describe "GET /request_data" do
  let(:url) {'http://www.example.com/feed.rss'}

  context "The request is not stored" do

    before(:each) do
      REDIS.stub(:hgetall).with(url).and_return({})
    end

    it_should_behave_like "a successful request", '/request_data?url=http://www.example.com/feed.rss',
      "Request data not found.", "json", true
  end

  context "The request is stored" do

    before(:each) do
      Timecop.freeze(Time.now)
      REDIS.stub(:hgetall).with(url).and_return({
        "response" => "Stored response",
        "count" => "5",
        "updated" => Time.now.to_i.to_s,
        "created" => (Time.now.to_i - 10).to_s
      })
    end

    context "The include response param is set to 'true'" do
      before(:each) do
        REDIS.stub(:hincrby)
      end

      it "increments the request's count by 1" do
        REDIS.should_receive(:hincrby).with(url, "count", 1)
        get "/request_data?url=#{url}&include_response=true"
      end

      it_should_behave_like "a successful request",
        '/request_data?url=http://www.example.com/feed.rss&include_response=true',
        { "http://www.example.com/feed.rss" =>
          {
            "response" => "Stored response",
            "count" => "6",
            "updated" => Time.now.to_i.to_s,
            "created" => (Time.now.to_i - 10).to_s
          }
        }.to_json, "json"
    end

    context "The include response param is not set" do
{'fraction_non_alphanumeric': 0.1457319052255761, 'fraction_numerical': 0.00519311911716975, 'mean_word_length': 2.46681664791901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, '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': '5363828', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1015, 'n_words': 224}