<commit_before>require 'spec_helper'

describe SupportingEvidenceController do
  render_views

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

  let (:f1) {FactoryGirl.create(:fact)}
  let (:f2) {FactoryGirl.create(:fact)}
  let (:f3) {FactoryGirl.create(:fact)}

  before do
    @fr = f1.add_evidence(:supporting, f2, user)
  end

  describe :index do
    it "should show" do
      should_check_can :get_evidence, f1

      get 'index', :fact_id => f1.id, :format => 'json'
      response.should be_success
    end

    it "should show the correct evidence" do
      should_check_can :get_evidence, f1

      get 'index', :fact_id => f1.id, :format => 'json'
      parsed_content = JSON.parse(response.body)
      parsed_content[0]["fact_bubble"]["id"].should == f2.id
    end
  end

  describe :create do

    before do
      authenticate_user!(user)
      should_check_can :add_evidence, f1
    end


    context "adding new evidence to a fact" do

      it "should return the new evidence" do
        displaystring = "<NAME>"

        post 'create', fact_id: f1.id, displaystring: displaystring, format: :json
        response.should be_success

        parsed_content = JSON.parse(response.body)
        parsed_content["fact_bubble"]["displaystring"].should == displaystring
      end

    end

    context "adding a new fact as evidence to a fact" do

      it "should return the existing fact as new evidence" do
        post 'create', fact_id: f1.id, evidence_id: f2.id, format: :json

        parsed_content = JSON.parse(response.body)
        parsed_content["fact_bubble"]["fact_id"].should == f2.id<commit_msg>modified test so that in now fails (reproducing the adding new evidence bug)<commit_after>require 'spec_helper'

describe SupportingEvidenceController do
  render_views

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

  let (:f1) {FactoryGirl.create(:fact)}
  let (:f2) {FactoryGirl.create(:fact)}
  let (:f3) {FactoryGirl.create(:fact)}

  before do
    @fr = f1.add_evidence(:supporting, f2, user)
  end

  describe :index do
    it "should show" do
      should_check_can :get_evidence, f1

      get 'index', :fact_id => f1.id, :format => 'json'
      response.should be_success
    end

    it "should show the correct evidence" do
      should_check_can :get_evidence, f1

      get 'index', :fact_id => f1.id, :format => 'json'
      parsed_content = JSON.parse(response.body)
      parsed_content[0]["fact_bubble"]["id"].should == f2.id
    end
  end

  describe :create do

    before do
      authenticate_user!(user)
      should_check_can :add_evidence, f1
    end


    context "adding new evidence to a fact" do

      it "should return the new evidence" do
        displaystring = "<NAME>"

        post 'create', fact_id: f1.id, displaystring: displaystring, format: :json
        response.should be_success

        parsed_content = JSON.parse(response.body)
        parsed_content["fact_bubble"]["displaystring"].should == displaystring

        FactRelation[parsed_content["id"].to_i].fact.id.should == f1.id
      end

    end

    context "adding a new fact as evidence to a fact" do

      it "should return the existing fact as new evidence" do
        post 'create', fact_id: f1.id, evidence_id: f2.id, format: :json

        parsed_content = JSON.parse(response.body)
        parsed_content["fact_bubble"]["fact_id"].should == f2.id
{'fraction_non_alphanumeric': 0.11015439429928742, 'fraction_numerical': 0.009798099762470308, 'mean_word_length': 3.149014778325123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5519911', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1049, 'n_words': 297}