<commit_before>require 'rails_helper'

describe StagedPetitionCreator do
  let(:petition_params) { {} }
  let(:move) { '' }
  let(:stage) { '' }
  let(:request) { double(remote_ip: '192.168.0.1') }
  subject { described_class.new(petition_params, request, stage, move) }
  let(:petition) { subject.petition }

  describe '#create_petition' do
    it 'strips trailing whitespace from the petition title' do
      petition_params[:title] = ' woo '
      subject.create_petition
      expect(petition.title).to eq 'woo'
    end

    context 'when creator_signature attributes are present' do
      it 'strips trailing whitespace from the creator signature email' do
        petition_params[:creator_signature_attributes] = { email: ' <EMAIL> ' }
        subject.create_petition
        expect(petition.creator_signature.email).to eq '<EMAIL>'
      end

      it 'assigns the remote_ip of the request to the ip_address of the creator signature' do
        petition_params[:creator_signature_attributes] = { email: ' <EMAIL> ' }
        subject.create_petition
        expect(petition.creator_signature.ip_address).to eq '192.168.0.1'
      end

      it 'assumes that the creator wants notify_by_email to be true' do
        petition_params[:creator_signature_attributes] = { email: ' <EMAIL> ' }
        subject.create_petition
        expect(petition.creator_signature.notify_by_email).to eq true
      end
    end

    context 'when creator_signature attributes are present' do
      it 'does not cause a creator_signature to appear' do
        subject.create_petition
        expect(petition.creator_signature).to be_nil
      end
    end

    describe 'when the stage is "done"' do
      let(:stage) { 'done' }

      it 'tries to save the petition object' do
        expect(petition).to receive(:save)<commit_msg>Fix typo in ``StagedPetitionCreator`` specs<commit_after>require 'rails_helper'

describe StagedPetitionCreator do
  let(:petition_params) { {} }
  let(:move) { '' }
  let(:stage) { '' }
  let(:request) { double(remote_ip: '192.168.0.1') }
  subject { described_class.new(petition_params, request, stage, move) }
  let(:petition) { subject.petition }

  describe '#create_petition' do
    it 'strips trailing whitespace from the petition title' do
      petition_params[:title] = ' woo '
      subject.create_petition
      expect(petition.title).to eq 'woo'
    end

    context 'when creator_signature attributes are present' do
      it 'strips trailing whitespace from the creator signature email' do
        petition_params[:creator_signature_attributes] = { email: ' <EMAIL> ' }
        subject.create_petition
        expect(petition.creator_signature.email).to eq '<EMAIL>'
      end

      it 'assigns the remote_ip of the request to the ip_address of the creator signature' do
        petition_params[:creator_signature_attributes] = { email: ' <EMAIL> ' }
        subject.create_petition
        expect(petition.creator_signature.ip_address).to eq '192.168.0.1'
      end

      it 'assumes that the creator wants notify_by_email to be true' do
        petition_params[:creator_signature_attributes] = { email: ' <EMAIL> ' }
        subject.create_petition
        expect(petition.creator_signature.notify_by_email).to eq true
      end
    end

    context 'when creator_signature attributes are not present' do
      it 'does not cause a creator_signature to appear' do
        subject.create_petition
        expect(petition.creator_signature).to be_nil
      end
    end

    describe 'when the stage is "done"' do
      let(:stage) { 'done' }

      it 'tries to save the petition object' do
        expect(petition).to receive(:save)
{'fraction_non_alphanumeric': 0.09219858156028368, 'fraction_numerical': 0.00872885979268958, 'mean_word_length': 3.2344110854503465, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3423284', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1039, 'n_words': 294}