<commit_before>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/sub_comments/create'
require_relative '../../../../app/interactors/backend/sub_comments.rb'

describe Interactors::SubComments::Create do
  include PavlovSupport

  before do
    stub_classes 'Comment', 'SubComment', 'Commands::SubComments::CreateXxx'
  end

  it '.authorized denied the user cannot show the comment' do
    comment = double
    ability = double
    ability.stub(:can?).with(:show, comment).and_return(false)
    Comment.should_receive(:find).and_return(comment)

    interactor = described_class.new comment_id: '2a', content: 'hoi',
                                     pavlov_options: { current_user: nil, ability: ability }

    expect { interactor.call }
     .to raise_error Pavlov::AccessDenied, 'Unauthorized'
  end

  describe '.validate' do
    it 'without comment_id doesn''t validate' do
      expect_validating(comment_id: nil, content: 'hoi')
        .to fail_validation('comment_id should be an hexadecimal string.')
    end

    it 'without content doesn''t validate' do<commit_msg>Removed unused stub<commit_after>require 'pavlov_helper'
require_relative '../../../../app/interactors/interactors/sub_comments/create'
require_relative '../../../../app/interactors/backend/sub_comments.rb'

describe Interactors::SubComments::Create do
  include PavlovSupport

  before do
    stub_classes 'Comment', 'SubComment'
  end

  it '.authorized denied the user cannot show the comment' do
    comment = double
    ability = double
    ability.stub(:can?).with(:show, comment).and_return(false)
    Comment.should_receive(:find).and_return(comment)

    interactor = described_class.new comment_id: '2a', content: 'hoi',
                                     pavlov_options: { current_user: nil, ability: ability }

    expect { interactor.call }
     .to raise_error Pavlov::AccessDenied, 'Unauthorized'
  end

  describe '.validate' do
    it 'without comment_id doesn''t validate' do
      expect_validating(comment_id: nil, content: 'hoi')
        .to fail_validation('comment_id should be an hexadecimal string.')
    end

    it 'without content doesn''t validate' do
{'fraction_non_alphanumeric': 0.1162260711030082, 'fraction_numerical': 0.0009115770282588879, 'mean_word_length': 3.4613821138211383, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6990328', 'n_tokens_mistral': 647, 'n_tokens_neox': 624, 'n_words': 162}