<commit_before>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/comments/set_opinion.rb'


describe Interactors::Comments::SetOpinion do
  include PavlovSupport

  it 'initializes correctly' do
    user = mock()
    interactor = Interactors::Comments::SetOpinion.new '1', 'believes', current_user: user
    interactor.should_not be_nil
  end

  it 'without current user gives an unauthorized exception' do
    expect { Interactors::Comments::SetOpinion.new '1', 'believes'}.
      to raise_error(Pavlov::AccessDenied, 'Unauthorized')
  end

  it 'with a invalid comment_id doesn''t validate' do
    expect { Interactors::Comments::SetOpinion.new 'g', 'believes'}.
      to raise_error(Pavlov::ValidationError, 'comment_id should be an hexadecimal string.')
  end

  it 'with a invalid opinion doesn''t validate' do
    expect { Interactors::Comments::SetOpinion.new '1', 'dunno'}.
      to raise_error(Pavlov::ValidationError, 'opinion should be on of these values: ["believes", "disbelieves", "doubts"].')
  end

  describe '.execute' do
    before do
      stub_classes 'Commands::Comments::SetOpinion'
    end

    it 'does stuff' do
      opinion = 'believes'
      user = mock()
      comment = mock(id: '123abc456def')
      authority_string = '1.0'

      interactor = Interactors::Comments::SetOpinion.new comment.id, opinion, current_user: user

      interactor.should_receive(:command).with('comment/set_opinion', comment.id, opinion)

      interactor.execute
    end
  end
end
<commit_msg>Fix set opinion spec<commit_after>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/comments/set_opinion.rb'


describe Interactors::Comments::SetOpinion do
  include PavlovSupport

  it 'initializes correctly' do
    user = mock()
    interactor = Interactors::Comments::SetOpinion.new '1', 'believes', current_user: user
    interactor.should_not be_nil
  end

  it 'without current user gives an unauthorized exception' do
    expect { Interactors::Comments::SetOpinion.new '1', 'believes'}.
      to raise_error(Pavlov::AccessDenied, 'Unauthorized')
  end

  it 'with a invalid comment_id doesn''t validate' do
    expect { Interactors::Comments::SetOpinion.new 'g', 'believes'}.
      to raise_error(Pavlov::ValidationError, 'comment_id should be an hexadecimal string.')
  end

  it 'with a invalid opinion doesn''t validate' do
    expect { Interactors::Comments::SetOpinion.new '1', 'dunno'}.
      to raise_error(Pavlov::ValidationError, 'opinion should be on of these values: ["believes", "disbelieves", "doubts"].')
  end

  describe '.execute' do
    before do
      stub_classes 'Commands::Comments::SetOpinion'
    end

    it 'does stuff' do
      opinion = 'believes'
      user = mock()
      comment = mock(id: '123abc456def')
      authority_string = '1.0'

      interactor = Interactors::Comments::SetOpinion.new comment.id, opinion, current_user: user

      interactor.should_receive(:command).with('comments/set_opinion', comment.id, opinion)

      interactor.execute
    end
  end
end

{'fraction_non_alphanumeric': 0.11760883690708251, 'fraction_numerical': 0.007147498375568551, 'mean_word_length': 3.9983766233766236, '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': '1918679', 'n_tokens_mistral': 1022, 'n_tokens_neox': 925, 'n_words': 245}