<commit_before>require 'spec_helper'

describe FactsController do
  include Devise::TestHelpers
  include ControllerMethods
  render_views

  def create_fact_relation
    @fact     = FactoryGirl.create(:fact)
    @evidence = FactoryGirl.create(:fact)
    @fr       = @fact.add_evidence(:supporting, @evidence,@user)
  end

  before do
    @user = FactoryGirl.create(:user)
  end

  describe :show do
    it "should render succesful" do
      @fact = FactoryGirl.create(:fact)
      get :show, :id => @fact.id
      response.should be_succes
    end
    
    it "should escape html in fields" do
      @site = FactoryGirl.create(:site)
      
      @fact = Fact.create(
        :created_by => @user.graph_user,
        :site => @site
      )
      @fact.data.displaystring = "baas<xss> of niet"
      @fact.data.title = "baas<xss> of niet"
      @fact.data.save
      
      get :show, :id => @fact.id
      
      response.body.should_not match(/<xss>/)
    end
  end

  describe :intermediate do
    it "should have the correct assignments" do
      post :intermediate, :the_action => "prepare"
      response.code.should eq("200")
    end
  end

  describe :create do
    it "should work" do
      authenticate_user!(@user)
      post 'create', :url => "http://example.org/",  :displaystring => "Facity Fact", :title => "Title"
      response.should redirect_to(created_fact_path(Fact.all.to_a.last.id))
    end
    
    it "should work with json" do
      authenticate_user!(@user)
      post 'create', :format => :json, :url => "http://example.org/",  :displaystring => "Facity Fact", :title => "Title"
      response.code.should eq("201")
    end
  end

  describe :add_supporting_evidence do
    it "should respond to XHR" do
      authenticate_user!(@user)
      xhr :get, :add_supporting_evidence,
        :id => FactoryGirl.create(:fact).id,
        :evidence_id => FactoryGirl.create(:fact).id

      response.code.should eq("200")
    end
    
  end

  describe :add_weakening_evidence do
    it "should respond to XHR" do
      authenticate_user!(@user)
      xhr :get, :add_supporting_evidence,
        :id => FactoryGirl.create(:fact).id,
        :evidence_id => FactoryGirl.create(:fact).id

      response.code.should eq("200")
    end
  end




end<commit_msg>use let to define the user<commit_after>require 'spec_helper'

describe FactsController do
  include Devise::TestHelpers
  include ControllerMethods
  render_views

  def create_fact_relation
    @fact     = FactoryGirl.create(:fact)
    @evidence = FactoryGirl.create(:fact)
    @fr       = @fact.add_evidence(:supporting, @evidence,user)
  end

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

  describe :show do
    it "should render succesful" do
      @fact = FactoryGirl.create(:fact)
      get :show, :id => @fact.id
      response.should be_succes
    end
    
    it "should escape html in fields" do
      @site = FactoryGirl.create(:site)
      
      @fact = Fact.create(
        :created_by => user.graph_user,
        :site => @site
      )
      @fact.data.displaystring = "baas<xss> of niet"
      @fact.data.title = "baas<xss> of niet"
      @fact.data.save
      
      get :show, :id => @fact.id
      
      response.body.should_not match(/<xss>/)
    end
  end

  describe :intermediate do
    it "should have the correct assignments" do
      post :intermediate, :the_action => "prepare"
      response.code.should eq("200")
    end
  end

  describe :create do
    it "should work" do
      authenticate_user!(user)
      post 'create', :url => "http://example.org/",  :displaystring => "Facity Fact", :title => "Title"
      response.should redirect_to(created_fact_path(Fact.all.to_a.last.id))
    end
    
    it "should work with json" do
      authenticate_user!(user)
      post 'create', :format => :json, :url => "http://example.org/",  :displaystring => "Facity Fact", :title => "Title"
      response.code.should eq("201")
    end
  end

  describe :add_supporting_evidence do
    it "should respond to XHR" do
      authenticate_user!(user)
      xhr :get, :add_supporting_evidence,
        :id => FactoryGirl.create(:fact).id,
        :evidence_id => FactoryGirl.create(:fact).id

      response.code.should eq("200")
    end
    
  end

  describe :add_weakening_evidence do
    it "should respond to XHR" do
      authenticate_user!(user)
      xhr :get, :add_supporting_evidence,
        :id => FactoryGirl.create(:fact).id,
        :evidence_id => FactoryGirl.create(:fact).id

      response.code.should eq("200")
    end
  end




end
{'fraction_non_alphanumeric': 0.12115215479331574, 'fraction_numerical': 0.005277044854881266, 'mean_word_length': 2.686385737439222, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '4618192', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1441, 'n_words': 355}