<commit_before>require 'pavlov_helper'

require_relative '../../../../app/interactors/interactors/channels/add_fact'

describe Interactors::Channels::AddFact do
  describe '.execute' do
    it 'correctly' do
      fact = mock
      channel = mock
      user = mock

      Interactors::Channels::AddFact.any_instance.should_receive(:authorized?).and_return true

      interactor = Interactors::Channels::AddFact.new fact, channel

      channel.should_receive(:created_by).and_return(user)

      interactor.should_receive(:command).with(:"channels/add_fact", fact, channel)
      interactor.should_receive(:command).with(:"create_activity", user, :added_fact_to_channel, fact, channel)

      interactor.execute
    end
  end

  describe '.authorized?' do
    it 'returns the passed current_user' do
      current_user = mock
      interactor = Interactors::Channels::AddFact.new mock, mock, current_user: current_user

      expect(interactor.authorized?).to eq current_user
    end

    it 'returns true when the :no_current_user option is true' do
      interactor = Interactors::Channels::AddFact.new mock, mock, no_current_user: true

      expect(interactor.authorized?).to eq true
    end

    it 'returns false when neither :current_user or :no_current_user are passed' do
      expect(lambda { Interactors::Channels::AddFact.new mock, mock }).to raise_error(Pavlov::AccessDenied)
    end
  end
end
<commit_msg>Fixed test for channels/add_fact interactor<commit_after>require 'pavlov_helper'

require_relative '../../../../app/interactors/interactors/channels/add_fact'

describe Interactors::Channels::AddFact do
  describe '.execute' do
    it 'correctly' do
      fact = mock(site: mock(id: 10))
      channel = mock(topic: mock(id: "1a"))
      user = mock

      Interactors::Channels::AddFact.any_instance.should_receive(:authorized?).and_return true

      interactor = Interactors::Channels::AddFact.new fact, channel

      channel.should_receive(:created_by).and_return(user)

      interactor.should_receive(:command).with(:"channels/add_fact", fact, channel)
      interactor.should_receive(:command).with(:"site/add_top_topic", fact.site.id, channel.topic.id)
      interactor.should_receive(:command).with(:"create_activity", user, :added_fact_to_channel, fact, channel)

      interactor.execute
    end
  end

  describe '.authorized?' do
    it 'returns the passed current_user' do
      current_user = mock
      interactor = Interactors::Channels::AddFact.new mock, mock, current_user: current_user

      expect(interactor.authorized?).to eq current_user
    end

    it 'returns true when the :no_current_user option is true' do
      interactor = Interactors::Channels::AddFact.new mock, mock, no_current_user: true

      expect(interactor.authorized?).to eq true
    end

    it 'returns false when neither :current_user or :no_current_user are passed' do
      expect(lambda { Interactors::Channels::AddFact.new mock, mock }).to raise_error(Pavlov::AccessDenied)
    end
  end
end

{'fraction_non_alphanumeric': 0.10746268656716418, 'fraction_numerical': 0.0009950248756218905, 'mean_word_length': 4.043478260869565, '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': '1115094', 'n_tokens_mistral': 925, 'n_tokens_neox': 871, 'n_words': 207}