<commit_before>require 'spec_helper'

def others(opinion)
  others = [:believes, :doubts, :disbelieves]
  others.delete(opinion)
  others
end


def expect_opinion(subject,opinion)
  subject.class[subject.id].get_user_opinion.should == opinion
end


def user_fact_opinion(user, opinion, fact)
  authority = Authority.on(fact, for: user).to_f + 1
  Opinion.for_type(opinion,authority)
end

describe Basefact do

  let(:user) {FactoryGirl.create(:user).graph_user}
  let(:user2) {FactoryGirl.create(:user).graph_user}
  let(:user3) {FactoryGirl.create(:user).graph_user}
  let(:user4) {FactoryGirl.create(:user).graph_user}
  let(:user5) {FactoryGirl.create(:user).graph_user}
  let(:user6) {FactoryGirl.create(:user).graph_user}

  subject {FactoryGirl.create(:basefact)}
  let(:fact2) {FactoryGirl.create(:basefact)}

  context "initially" do
    [:believes, :doubts, :disbelieves].each do |opinion|
      it { subject.opiniated(opinion).count.should == 0 }
      it { subject.opiniated(opinion).all.should == [] }
      it { expect_opinion(subject,Opinion.identity)}
    end
  end

  describe "#created_by" do
    context "after setting it" do
      before do
        subject.created_by = user
        subject.save
      end

      it "should have the created_by set" do
        subject.created_by.should == user
      end

      it "should have the created_by persisted" do
        Basefact[subject.id].created_by.should == user
      end

      it "should be findable via find" do
        Basefact.find(:created_by_id => user.id).all.should include(subject)
      end
      it { expect_opinion(subject,Opinion.identity)}
    end<commit_msg>improved test speed with 3 seconds<commit_after>require 'spec_helper'

def others(opinion)
  others = [:believes, :doubts, :disbelieves]
  others.delete(opinion)
  others
end


def expect_opinion(subject,opinion)
  subject.class[subject.id].get_user_opinion.should == opinion
end


def user_fact_opinion(user, opinion, fact)
  authority = Authority.on(fact, for: user).to_f + 1
  Opinion.for_type(opinion,authority)
end

describe Basefact do

  let(:user)  {create(:graph_user)}
  let(:user2) {create(:graph_user)}
  let(:user3) {create(:graph_user)}
  let(:user4) {create(:graph_user)}
  let(:user5) {create(:graph_user)}
  let(:user6) {create(:graph_user)}

  subject {create(:basefact)}
  let(:fact2) {create(:basefact)}

  context "initially" do
    [:believes, :doubts, :disbelieves].each do |opinion|
      it { subject.opiniated(opinion).count.should == 0 }
      it { subject.opiniated(opinion).all.should == [] }
      it { expect_opinion(subject,Opinion.identity)}
    end
  end

  describe "#created_by" do
    context "after setting it" do
      before do
        subject.created_by = user
        subject.save
      end

      it "should have the created_by set" do
        subject.created_by.should == user
      end

      it "should have the created_by persisted" do
        Basefact[subject.id].created_by.should == user
      end

      it "should be findable via find" do
        Basefact.find(:created_by_id => user.id).all.should include(subject)
      end
      it { expect_opinion(subject,Opinion.identity)}
    end
{'fraction_non_alphanumeric': 0.12138364779874214, 'fraction_numerical': 0.005345911949685534, 'mean_word_length': 3.671071953010279, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5270089', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1015, 'n_words': 226}