<commit_before>require 'spec_helper'

describe Griddler::EmailsController, :type => :controller do
  before(:each) do
    fake_adapter = double(normalize_params: normalized_params)
    Griddler.adapter_registry.register(:one_that_works, fake_adapter)
    Griddler.configuration.email_service = :one_that_works
  end

  describe 'POST create', type: :controller do
    it 'is successful' do
      post :create, email_params

      expect(response).to be_success
    end

    it 'creates a new Griddler::Email with the given params' do
      email = double
      expect(Griddler::Email).to receive(:new).
        with(hash_including(to: ['<EMAIL>'])).
        and_return(email)

      post :create, { to: '<EMAIL>' }
    end

    it 'calls process on the custom processor class' do
      my_handler = double(process: nil)
      expect(my_handler).to receive(:new).and_return(my_handler)
      allow(Griddler.configuration).to receive_messages(processor_class: my_handler)

      post :create, email_params
    end

    it 'calls the custom processor method on the processor class' do
      allow(Griddler.configuration).to receive_messages(processor_method: :perform)
      fake_processor = double(perform: nil)

      expect(EmailProcessor).to receive(:new).and_return(fake_processor)
      expect(fake_processor).to receive(:perform)

      post :create, email_params
    end
  end

  def email_params
    {
      headers: 'Received: by 127.0.0.1 with SMTP...',
      to: 'thoughtbot <<EMAIL>>',
      cc: 'CC <<EMAIL>>',
      from: '<NAME> <<EMAIL>>',
      subject: 'hello there',
      text: 'this is an email message',
      html: '<p>this is an email message</p>',
      charsets: '{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}',
      SPF: "pass"
    }
  end

  def normalized_params
    {
      to: ['<EMAIL>'],
      from: '<EMAIL>',
      cc: [],
    }
  end
end
<commit_msg>Change to Rails 5.1 required params<commit_after>require 'spec_helper'

describe Griddler::EmailsController, :type => :controller do
  before(:each) do
    fake_adapter = double(normalize_params: normalized_params)
    Griddler.adapter_registry.register(:one_that_works, fake_adapter)
    Griddler.configuration.email_service = :one_that_works
  end

  describe 'POST create', type: :controller do
    it 'is successful' do
      post :create, params: email_params

      expect(response).to be_success
    end

    it 'creates a new Griddler::Email with the given params' do
      email = double
      expect(Griddler::Email).to receive(:new).
        with(hash_including(to: ['<EMAIL>'])).
        and_return(email)

      post :create, params: { to: '<EMAIL>' }
    end

    it 'calls process on the custom processor class' do
      my_handler = double(process: nil)
      expect(my_handler).to receive(:new).and_return(my_handler)
      allow(Griddler.configuration).to receive_messages(processor_class: my_handler)

      post :create, params: email_params
    end

    it 'calls the custom processor method on the processor class' do
      allow(Griddler.configuration).to receive_messages(processor_method: :perform)
      fake_processor = double(perform: nil)

      expect(EmailProcessor).to receive(:new).and_return(fake_processor)
      expect(fake_processor).to receive(:perform)

      post :create, params: email_params
    end
  end

  def email_params
    {
      headers: 'Received: by 127.0.0.1 with SMTP...',
      to: 'thoughtbot <<EMAIL>>',
      cc: 'CC <<EMAIL>>',
      from: '<NAME> <<EMAIL>>',
      subject: 'hello there',
      text: 'this is an email message',
      html: '<p>this is an email message</p>',
      charsets: '{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}',
      SPF: "pass"
    }
  end

  def normalized_params
    {
      to: ['<EMAIL>'],
      from: '<EMAIL>',
      cc: [],
    }
  end
end

{'fraction_non_alphanumeric': 0.1312691914022518, 'fraction_numerical': 0.01023541453428864, 'mean_word_length': 3.2721311475409838, 'pattern_counts': {'":': 10, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2646396', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1211, 'n_words': 305}