Skip to content

Commit

Permalink
Fix payment mailer specs, add eald spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster committed Mar 24, 2024
1 parent dc0cce7 commit 4a9588a
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
--color
--order rand
--profile 5
--require spec_helper
--require rails_helper
1 change: 1 addition & 0 deletions app/classes/fnf/event_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'newrelic_rpm'
require 'singleton'

module FnF
class EventReporter
class << self
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create
return redirect_to root_path unless @payment.can_view?(current_user)

if @payment.save_and_charge!
PaymentMailer.payment_received(@payment).deliver_now
PaymentReceivedMailer.payment_received(@payment).deliver_now
@payment.ticket_request.mark_complete
redirect_to @payment, notice: 'Payment was successfully received.'
else
Expand Down Expand Up @@ -83,7 +83,7 @@ def mark_received
if @payment
@payment.mark_received
@payment.ticket_request.mark_complete
PaymentMailer.payment_received(@payment).deliver_now
PaymentReceivedMailer.payment_received(@payment).deliver_now
redirect_to :back
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
DEFAULT_SENDER_EMAIL = '[email protected]'
DEFAULT_REPLY_TO_EMAIL = '[email protected]'

layout 'email'

abstract!
end
27 changes: 5 additions & 22 deletions app/mailers/eald_payment_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
# frozen_string_literal: true

class EaldPaymentMailer < ActionMailer::Base
DEFAULT_SENDER_EMAIL = '[email protected]'
DEFAULT_REPLY_TO_EMAIL = '[email protected]'

helper PaymentsHelper

layout 'email'

def eald_payment_received(eald_payment)
@eald_payment = eald_payment
@event = @eald_payment.event
mail to: "#{@eald_payment.name} <#{@eald_payment.email}>",
class EaldPaymentMailer < PaymentReceivedMailer
def eald_payment_received(payment)
@payment = payment
@event = @payment.event
mail to: "#{@payment.name} <#{@payment.email}>",
from: from_email,
reply_to: reply_to_email,
subject: "Your payment for #{@event.name} Early Arrival/Late Departure passes has been received"
end

private

def from_email
"#{@event.name} <#{DEFAULT_SENDER_EMAIL}>"
end

def reply_to_email
"#{@event.name} Ticketing <#{DEFAULT_REPLY_TO_EMAIL}>"
end
end
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# frozen_string_literal: true

class PaymentMailer < ActionMailer::Base
DEFAULT_SENDER_EMAIL = '[email protected]'
DEFAULT_REPLY_TO_EMAIL = '[email protected]'

helper PaymentsHelper

layout 'email'

class PaymentReceivedMailer < ApplicationMailer
def payment_received(payment)
@payment = payment
@ticket_request = @payment.ticket_request
@event = @ticket_request.event
@user = @ticket_request.user
self.payment = payment

mail to: "#{@user.name} <#{@user.email}>",
from: from_email,
reply_to: reply_to_email,
Expand All @@ -28,4 +19,11 @@ def from_email
def reply_to_email
"#{@event.name} Ticketing <#{DEFAULT_REPLY_TO_EMAIL}>"
end

def payment=(payment)
@payment = payment
@ticket_request = @payment.ticket_request
@event = @ticket_request&.event
@user = @ticket_request&.user
end
end
3 changes: 0 additions & 3 deletions app/mailers/ticket_request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
require 'awesome_print'

class TicketRequestMailer < ActionMailer::Base
DEFAULT_SENDER_EMAIL = '[email protected]'
DEFAULT_REPLY_TO_EMAIL = '[email protected]'

layout 'email'

def request_received(ticket_request)
Expand Down
10 changes: 6 additions & 4 deletions app/models/eald_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class EaldPayment < ApplicationRecord

attr_accessible :event_id, :name, :email, :early_arrival_passes, :late_departure_passes, :stripe_card_token

validates :early_arrival_passes, presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :early_arrival_passes,
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }

validates :late_departure_passes, presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :late_departure_passes,
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }

attr_accessor :stripe_card_token

Expand Down
11 changes: 5 additions & 6 deletions app/views/eald_payment_mailer/eald_payment_received.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%p
Hi #{@eald_payment.name},
Hi #{@payment.name},

%p
Your payment of
%b= number_to_currency(@eald_payment.amount_charged_cents.to_f / 100)
%b= number_to_currency(@payment.amount_charged_cents.to_f / 100)
for
%b= @eald_payment.early_arrival_passes
%b= @payment.early_arrival_passes
early arrival passes and
%b= @eald_payment.late_departure_passes
%b= @payment.late_departure_passes
late departure passes for
%b= @event.name
was received. Thank you!
Expand All @@ -23,5 +23,4 @@

%p
More information can be found at:
= link_to 'Early Arrival / Late Departure Policy',
'https://fnf.page.link/eald-policy'
= link_to 'Early Arrival / Late Departure Policy', 'https://fnf.page.link/eald-policy'
13 changes: 13 additions & 0 deletions spec/factories/eald_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

FactoryBot.define do
factory :eald_payment do
event
name { Faker::Name.name }
early_arrival_passes { 10 }
amount_charged_cents { 1000 }
late_departure_passes { 5 }
email { Faker::Internet.email }
stripe_charge_id { Faker::Alphanumeric.alphanumeric(number: 10) }
end
end
2 changes: 1 addition & 1 deletion spec/lib/fnf/event_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'fnf/csv_reader'
require 'rails_helper'

module FnF
RSpec.describe EventReporter do
Expand Down
20 changes: 20 additions & 0 deletions spec/mailers/eald_payment_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'rails_helper'

describe EaldPaymentMailer do
let(:payment) { create(:eald_payment) }
let(:event) { payment.event }

describe '#eald_payment_received' do
subject(:mail) { described_class.eald_payment_received(payment) }

let(:expected_subject) { "Your payment for #{event.name} Early Arrival/Late Departure passes has been received" }

its(:subject) { is_expected.to eql(expected_subject) }

its(:to) { is_expected.to eql([payment.email]) }

its('body.encoded') { is_expected.to match(event.name) }
end
end
35 changes: 0 additions & 35 deletions spec/mailers/payment_mailer_spec.rb

This file was deleted.

24 changes: 24 additions & 0 deletions spec/mailers/payment_received_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'rails_helper'

describe PaymentReceivedMailer do
let(:ticket_request) { create(:ticket_request) }
let(:user) { ticket_request.user }
let(:event) { ticket_request.event }
let(:payment) { create(:payment, ticket_request:) }

describe '#payment_received' do
subject(:mail) { described_class.payment_received(payment) }

let(:expected_subject) { "Your payment for #{event.name} has been received" }

its(:subject) { is_expected.to eql(expected_subject) }

its(:to) { is_expected.to eql([user.email]) }

its('body.encoded') { is_expected.to match(user.first_name) }

its('body.encoded') { is_expected.to match(event.name) }
end
end

0 comments on commit 4a9588a

Please sign in to comment.