Last active
June 22, 2017 03:32
-
-
Save kellysutton/51b88d679e6202e4a74439277434accc to your computer and use it in GitHub Desktop.
Test Vices
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
require 'rails_helper' | |
RSpec.describe FrequentFlierCreator do | |
describe '.create' do | |
subject do | |
described_class.create( | |
customer, | |
starting_balance, | |
status_level | |
) | |
end | |
let(:customer) { double } | |
let(:starting_balance) { double } | |
let(:status_level) { double } | |
context 'there is a promotion' | |
context 'there is no current promotion' | |
context 'the customer is related to an employee' do | |
context 'the starting status is :diamond' | |
context 'the starting status is :platinum' | |
context 'the starting status is :gold' | |
context 'the starting status is something else' | |
end | |
it 'logs a message' | |
it 'sends an email to admins' | |
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
require 'rails_helper' | |
RSpec.describe FrequentFlierCreator do | |
describe '.create' do | |
subject do | |
described_class.create( | |
customer, | |
starting_balance, | |
status_level | |
) | |
end | |
let(:customer) { instance_double(Customer) } | |
let(:starting_balance) { 100 } | |
let(:status_level) { double } | |
let(:generated_account_number) { double } | |
let(:related_to_employee?) { false } | |
before do | |
allow(described_class).to receive(:promotion_starting_balance). | |
and_return(promotion_starting_balance) | |
allow(AccountNumber).to receive(:generate). | |
and_return(generated_account_number) | |
allow(customer).to receive(:related_to_employee?). | |
and_return(related_to_employee?) | |
allow(Rails.logger).to receive(:info) | |
end | |
context 'there is a promotion' do | |
let(:promotion_starting_balance) { double } | |
it do | |
is_expected.to eq({ | |
account_number: generated_account_number, | |
balance: promotion_starting_balance, | |
status_level: status_level | |
}) | |
end | |
end | |
context 'there is no current promotion' do | |
let(:promotion_starting_balance) { nil } | |
it do | |
is_expected.to eq({ | |
account_number: generated_account_number, | |
balance: starting_balance, | |
status_level: status_level | |
}) | |
end | |
end | |
context 'the customer is related to an employee' do | |
let(:related_to_employee?) { true } | |
context 'the starting status is :diamond' do | |
let(:status_level) { :diamond } | |
it do | |
is_expected.to eq({ | |
account_number: generated_account_number, | |
balance: starting_balance + 10_000, | |
status_level: :diamond | |
}) | |
end | |
end | |
context 'the starting status is :platinum' do | |
let(:status_level) { :platinum } | |
it do | |
is_expected.to eq({ | |
account_number: generated_account_number, | |
balance: starting_balance + 10_000, | |
status_level: :platinum | |
}) | |
end | |
end | |
context 'the starting status is :gold' do | |
let(:status_level) { :gold } | |
it do | |
is_expected.to eq({ | |
account_number: generated_account_number, | |
balance: starting_balance + 10_000, | |
status_level: :gold | |
}) | |
end | |
end | |
context 'the starting status is something else' do | |
let(:status_level) { :silver } | |
it do | |
is_expected.to eq({ | |
account_number: generated_account_number, | |
balance: starting_balance + 10_000, | |
status_level: :gold | |
}) | |
end | |
end | |
end | |
it 'logs a message' do | |
subject | |
expect(Rails.logger).to have_received(:info).with( | |
<<~MSG | |
Generating a new frequent flier account | |
for Customer[#{customer.id}] | |
MSG | |
) | |
end | |
it 'sends an email to admins' do | |
mail = double | |
expect(AdminMailer).to receive(:new_frequent_flier_email). | |
with(customer). | |
and_return(mail) | |
expect(mail).to receive(:deliver_now) | |
subject | |
end | |
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
class FrequentFlierCreator | |
def create(customer, starting_balance, status_level) | |
starting_balance = promotion_starting_balance || starting_balance | |
if customer.related_to_employee? | |
starting_balance += 10_000 | |
if ![:diamond, :platinum].include?(status_level) | |
status_level = :gold | |
end | |
end | |
Rails.logger.info( | |
<<~MSG | |
Generating a new frequent flier account | |
for Customer[#{customer.id}] | |
MSG | |
) | |
AdminMailer.new_frequent_flier_email(customer).deliver_now | |
{ | |
account_number: AccountNumber.generate, | |
balance: starting_balance, | |
status_level: status_level | |
} | |
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
require 'rails_helper' | |
RSpec.describe FrequentFlierCreator do | |
describe '.create' do | |
subject do | |
described_class.create( | |
customer, | |
starting_balance, | |
status_level | |
) | |
end | |
let(:customer) { double } | |
let(:starting_balance) { double } | |
let(:status_level) { double } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment