<commit_before>require 'spec_helper'

describe SearchController do

  let (:user)  {FactoryGirl.create :user}

  render_views

  describe "Search" do
    it "should render succesful" do
      authenticate_user!(user)
      get :search, s: "Baron"
      response.should be_success

      response.should render_template("search")
    end

    it "should render json successful" do
      Timecop.freeze Time.local(1995, 4, 30, 15, 35, 45)
      FactoryGirl.reload # hack because of fixture in check

      ElasticSearch.stub synchronous: true

      channel = FactoryGirl.create(:channel, title: "Baron")
      user = FactoryGirl.create(:user, username: "Baron")
      fact = FactoryGirl.create(:fact, data: FactoryGirl.create(:fact_data, displaystring: "Baron"))

      authenticate_user!(user)
      get :search, s: "Baron", format: :json
      response.should be_success

      response_body = response.body.to_s
      # strip mongo id, since otherwise comparison will always fail
      response_body.gsub!(/"id":\s*"[^"]*"/, '"id": "<STRIPPED>"')
      Approvals.verify(response_body, format: :json, name: 'search#search should keep the same content')
    end
  end

end
<commit_msg>Improved name of test case and added some comments to clarify behaviour.<commit_after>require 'spec_helper'

describe SearchController do

  let (:user)  {FactoryGirl.create :user}

  render_views

  describe "Search" do
    it "should render succesful" do
      authenticate_user!(user)
      get :search, s: "Baron"
      response.should be_success

      response.should render_template("search")
    end

    it "should render json successful and in the same way (approvals)" do
      Timecop.freeze Time.local(1995, 4, 30, 15, 35, 45)
      FactoryGirl.reload # hack because of fixture in check

      ElasticSearch.stub synchronous: true

      # This channel should not be displayed since it is not valid.
      # Recalc heeft nog niet gedraaid en daarom heeft hij geen top channels.
      channel = FactoryGirl.create(:channel, title: "Baron")
      user = FactoryGirl.create(:user, username: "Baron")
      fact = FactoryGirl.create(:fact, data: FactoryGirl.create(:fact_data, displaystring: "Baron"))

      authenticate_user!(user)
      get :search, s: "Baron", format: :json
      response.should be_success

      response_body = response.body.to_s
      # strip mongo id, since otherwise comparison will always fail
      response_body.gsub!(/"id":\s*"[^"]*"/, '"id": "<STRIPPED>"')
      Approvals.verify(response_body, format: :json, name: 'search#search should keep the same content')
    end
  end
end

{'fraction_non_alphanumeric': 0.10552570990023023, 'fraction_numerical': 0.009976976208749041, 'mean_word_length': 3.4564102564102566, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '2486692', 'n_tokens_mistral': 822, 'n_tokens_neox': 749, 'n_words': 242}