<commit_before>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/facts/votes.rb'

describe Interactors::Facts::Votes do
  include PavlovSupport

  before do
    stub_classes 'Fact'
  end

  describe '#authorized?' do
    it 'should check if the fact can be shown' do
      ability = double
      ability.should_receive(:can?).with(:show, Fact).and_return(false)

      interactor = described_class.new(fact_id: 0, pavlov_options: { ability: ability } )

      expect { interactor.call }
        .to raise_error(Pavlov::AccessDenied)
    end
  end

  describe '#validate' do
    it 'requires fact_id to be a integer string' do
      expect_validating( fact_id: 'a')
        .to fail_validation('fact_id should be an integer.')
    end
  end

  describe '#call' do
    it 'correctly' do
      fact = mock id: 1
      u1, u2, u3 = double, double, double

      pavlov_options = { ability: double(can?: true)}

      Pavlov.stub(:query)
            .with(:'facts/get',
                      id: fact.id.to_s,
                      pavlov_options: pavlov_options)
            .and_return(fact)
<commit_msg>fixed deprecation warning<commit_after>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/facts/votes.rb'

describe Interactors::Facts::Votes do
  include PavlovSupport

  before do
    stub_classes 'Fact'
  end

  describe '#authorized?' do
    it 'should check if the fact can be shown' do
      ability = double
      ability.should_receive(:can?).with(:show, Fact).and_return(false)

      interactor = described_class.new(fact_id: 0, pavlov_options: { ability: ability } )

      expect { interactor.call }
        .to raise_error(Pavlov::AccessDenied)
    end
  end

  describe '#validate' do
    it 'requires fact_id to be a integer string' do
      expect_validating( fact_id: 'a')
        .to fail_validation('fact_id should be an integer.')
    end
  end

  describe '#call' do
    it 'correctly' do
      fact = double id: 1
      u1, u2, u3 = double, double, double

      pavlov_options = { ability: double(can?: true)}

      Pavlov.stub(:query)
            .with(:'facts/get',
                      id: fact.id.to_s,
                      pavlov_options: pavlov_options)
            .and_return(fact)

{'fraction_non_alphanumeric': 0.10877192982456141, 'fraction_numerical': 0.0043859649122807015, 'mean_word_length': 2.525502318392581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6437349', 'n_tokens_mistral': 745, 'n_tokens_neox': 703, 'n_words': 188}