Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created November 1, 2017 16:32
Show Gist options
  • Save staycreativedesign/e506b73edde23f22f813c6e70cae3420 to your computer and use it in GitHub Desktop.
Save staycreativedesign/e506b73edde23f22f813c6e70cae3420 to your computer and use it in GitHub Desktop.
UserMailer
send email to administrators
sends welcome email to new user (FAILED - 1)
Failures:
1) UserMailer send email to administrators sends welcome email to new user
Failure/Error: expect(mail.to).to eq([ref.email])
expected: ["[email protected]"]
got: ["[email protected]", "[email protected]", "[email protected]"]
(compared using ==)
# ./spec/mailers/user_mailer_spec.rb:21:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
Finished in 0.13705 seconds (files took 51 minutes 45 seconds to load)
1 example, 1 failure
require 'rails_helper'
RSpec.describe UserMailer, type: :mailer do
let(:team_leader) { create(:user, role: Role::TEAM_LEADER) }
let(:ref) { create(:user, role: Role::ADMIN) }
let(:team) { create(:team, coach: ref, leader: team_leader) }
let(:user) { create(:user, team_id: team.id, referrer: ref) }
describe 'welcome_email' do
let(:mail) { UserMailer.welcome_email(user) }
it 'sends welcome email to new user' do
expect(mail.to).to eq([user.email])
end
end
describe 'send email to administrators' do
binding.pry
let(:mail) { UserMailer.send_email_to_administrators }
it 'sends welcome email to new user' do
expect(mail.to).to eq([ref.email])
end
end
describe 'send email to coach and team_leader' do
let(:mail) { UserMailer.send_email_to_coach_and_team_leader(user) }
it 'sends welcome email to new user' do
expect(mail.to).to eq([ref.email, team_leader.email])
end
end
end
class UserMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
def welcome_email(user)
@user = user
mail(to: @user.email, subject: 'Welcome to Bold!', body: 'Bold is great')
end
def send_email_to_administrators
users = User.where(role: Role::ADMIN)
emails = users.collect(&:email).join(",")
mail(to: emails, subject: 'A new trial member has joined Bold Networking', body: 'Bold is great')
end
def send_email_to_coach_and_team_leader(user)
@user = user
mail(to: [ @user.team.coach.email, @user.team.leader.email ], subject: 'A new trial member has joined Bold Networking', body: 'Bold is great')
end
end
require 'rails_helper'
RSpec.describe UserMailer, type: :mailer do
let(:team_leader) { create(:user, role: Role::TEAM_LEADER) }
let(:ref) { create(:user, role: Role::ADMIN) }
let(:team) { create(:team, coach: ref, leader: team_leader) }
let(:user) { create(:user, team_id: team.id, referrer: ref) }
describe 'welcome_email' do
let(:mail) { UserMailer.welcome_email(user) }
it 'sends welcome email to new user' do
expect(mail.to).to eq([user.email])
end
end
describe 'send email to administrators' do
binding.pry
let(:mail) { UserMailer.send_email_to_administrators }
it 'sends welcome email to new user' do
expect(mail.to).to eq([ref.email])
end
end
describe 'send email to coach and team_leader' do
let(:mail) { UserMailer.send_email_to_coach_and_team_leader(user) }
it 'sends welcome email to new user' do
expect(mail.to).to eq([ref.email, team_leader.email])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment