Created
May 17, 2017 04:55
-
-
Save ziyan-junaideen/3ee46d4bae168a4390b4d55d2f30984f to your computer and use it in GitHub Desktop.
# ActiveJob::SerializationError: Unsupported argument type: ContactForm# ./app/models/contact_form.rb:22:in `process' # ./spec/models/contact_form_spec.rb:20:in `block (3 levels) in <top (required)>' # ./spec/models/contact_form_spec.rb:23:in `block (3 levels) in <top (required)>'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Form object for contact form | |
class ContactForm | |
include ActiveModel::Model | |
attr_accessor( | |
:name, | |
:email, | |
:phone, | |
:message | |
) | |
validates :name, presence: true | |
validates :email, presence: true | |
validates :phone, presence: true | |
validates :message, presence: true | |
# If the user input is valid, will deliver the details in a message in an email. | |
def process | |
return unless valid? | |
MarketingMailer.contact(self).deliver_later | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'rails_helper' | |
RSpec.describe ContactForm, type: :model do | |
let(:contact_form) { build(:contact_form) } | |
describe '#process' do | |
subject { contact_form.process } | |
it { expect(subject).to change { ActionMailer::Base.deliveries.count }.by(1) } | |
it { expect(subject).to receive(:valid?) } | |
end | |
end | |
# ActiveJob::SerializationError: Unsupported argument type: ContactForm | |
# ./app/models/contact_form.rb:22:in `process' | |
# ./spec/models/contact_form_spec.rb:20:in `block (3 levels) in <top (required)>' | |
# ./spec/models/contact_form_spec.rb:23:in `block (3 levels) in <top (required)>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mailer to handle marketing website requirements | |
class MarketingMailer < ApplicationMailer | |
# Contact form email to admin | |
# @param form [ContactForm] the form object submitted by the user | |
def contact(form) | |
@form = form | |
mail to: '[email protected]', reply_to: form.email, subject: 'TestProject: Contact Submission' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment