Skip to content

Instantly share code, notes, and snippets.

@johno
Last active December 17, 2015 06:59
Show Gist options
  • Save johno/5569725 to your computer and use it in GitHub Desktop.
Save johno/5569725 to your computer and use it in GitHub Desktop.
Each of these are found in spec/mailers/accounts_mailer/
require 'spec_helper'
describe AccountsMailer do
let(:user) { FactoryGirl.create :user, account: GUEST_ACCOUNT }
describe "confirm_guest" do
it "shouldn't raise an error" do
lambda { AccountsMailer.confirm_guest(user) }.should_not raise_error
end
context "when sent" do
before(:each) { AccountsMailer.confirm_guest(user).deliver }
it "should have sent an email" do
last_email.should be
end
it "should be to the correct email" do
last_email.to.first.should == user.email
end
it "should be from the correct email" do
last_email.from.first.should == '[email protected]'
end
it "should contain the correct subject" do
last_email.subject.should == DefaultEmails::GuestConfirmation.default_subject
end
it "should contain the correct confirmation_token" do
last_email.body.should have_content user.confirmation_token
end
it "shouldn't contain the support email" do
last_email.body.encoded.should_not match('[email protected]')
end
end
end
end
require 'spec_helper'
describe AccountsMailer do
let(:user) { FactoryGirl.create :user }
describe "confirm_user" do
it "shouldn't raise an error" do
lambda { AccountsMailer.confirm_user(user) }.should_not raise_error
end
context "when sent" do
before(:each) { AccountsMailer.confirm_user(user).deliver }
it "should have sent an email" do
last_email.should be
end
it "should be to the correct email" do
last_email.to.first.should == user.email
end
it "should be from the correct email" do
last_email.from.first.should == '[email protected]'
end
it "should contain the correct subject" do
last_email.subject.should == DefaultEmails::UserConfirmation.default_subject
end
it "should contain the correct confirmation_token" do
last_email.body.should have_content user.confirmation_token
end
it "shouldn't contain the support email" do
last_email.body.encoded.should_not match('[email protected]')
end
end
end
end
require 'spec_helper'
describe CustomEmail do
let(:account) { FactoryGirl.create :account }
let(:user) { FactoryGirl.create :user, account: account }
let(:email) { FactoryGirl.build :custom_email }
subject { email }
it { should be_valid }
it { should respond_to(:body) }
it { should respond_to(:subject) }
it { should respond_to(:show_logo) }
it { should respond_to(:email_type) }
it { should respond_to(:account_id) }
it "shouldn't be valid without an account" do
email.account = nil
email.should_not be_valid
end
it "shouldn't be valid without a body" do
email.body = nil
email.should_not be_valid
end
it "shouldn't be valid without a mustache (for the link)" do
email.body = "text without a mustache"
email.should_not be_valid
end
it "shouldn't be valid without a subject" do
email.subject = nil
email.should_not be_valid
end
it "shouldn't be valid with invalid email types" do
[4,5,6].each do |invalid|
email.email_type = invalid
email.should_not be_valid
end
end
it "should be valid with the proper email types" do
CustomEmail::TYPES.each do |key,value|
email.email_type = value
email.should be_valid
end
end
it "should replace the mustaches properly" do
url = :awesome_url
link_name = :awesome_link
email.body = "{{#{ link_name }}}"
email.replace_mustaches_with_link(url).should == "<a href='#{ url }'>#{ link_name }</a>"
end
it "should return the correct string from type" do
email.email_type_as_string.should == 'confirm_user'
end
context "of type confirm_user" do
let(:confirm_user_email) { FactoryGirl.create :confirm_user, account: account }
before do
reset_email
confirm_user_email
AccountsMailer.confirm_user(user).deliver
end
it "should have sent an email" do
last_email.should be
end
it "should have the custom content" do
last_email.body.should have_content "confirm_user"
end
it "should have the custom link" do
last_email.body.should have_link "confirm_user_link"
end
end
context "for guests" do
let(:guest) { FactoryGirl.create :user, account: GUEST_ACCOUNT }
before { account.guests << guest }
context "of type confirm_guest" do
let(:confirm_guest_email) { FactoryGirl.create :confirm_guest, account: account }
before do
reset_email
confirm_guest_email
AccountsMailer.confirm_guest(guest).deliver
end
it "should have sent an email" do
last_email.should be
end
it "should have the custom content" do
last_email.body.should have_content "confirm_user"
end
it "should have the custom link" do
last_email.body.should have_link "confirm_guest_link"
end
end
context "of type instruct_guest" do
let(:instruct_guest_email) { FactoryGirl.create :instruct_guest, account: account }
before do
reset_email
instruct_guest_email
AccountsMailer.instruct_guest(guest).deliver
end
it "should have sent an email" do
last_email.should be
end
it "should have the custom content" do
last_email.body.should have_content "instruct_guest"
end
it "should have the custom link" do
last_email.body.should have_content "instruct_guest_link"
end
end
end
end
require "spec_helper"
describe AccountsMailer do
let(:user) { FactoryGirl.create :user }
describe "welcome_email" do
it "shouldn't raise an error" do
lambda { AccountsMailer.welcome_email(user) }.should_not raise_error
end
context "when sent" do
before(:each) { AccountsMailer.welcome_email(user).deliver }
it "should have sent an email" do
last_email.should be
end
it "should be to the correct email" do
last_email.to.first.should == user.email
end
it "should be from the correct email" do
last_email.from.first.should == '[email protected]'
end
it "should contain the correct subject" do
last_email.subject.should == DefaultEmails::WelcomeEmail.subject(user)
end
it "should contain the correct name" do
last_email.body.encoded.should match(user.name)
end
it "should contain the support email" do
last_email.body.encoded.should match('[email protected]')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment