This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AuctionEnded | ||
def initialize(auction) | ||
@auction = auction | ||
end | ||
|
||
def perform | ||
WinningBidderEmailSender.new(auction).perform | ||
LosingBidderEmailSender.new(auction).perform | ||
end | ||
|
||
private | ||
|
||
attr_reader :auction | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class CreateAuction | ||
class BuildAuction | ||
attr_reader :auction | ||
|
||
def initialize(params, user) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class SaveAuction | ||
def initialize(auction) | ||
@auction = auction | ||
end | ||
|
||
def perform | ||
saved = auction.save | ||
|
||
if should_schedule_auction_ended_job?(saved) | ||
AuctionEnded | ||
.new(auction) | ||
.delay(run_at: auction.ended_at) | ||
.perform | ||
end | ||
|
||
saved | ||
end | ||
|
||
private | ||
|
||
attr_reader :auction | ||
|
||
def should_schedule_auction_ended_job?(saved) | ||
saved && !auction.ended_at.nil? | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'rails_helper' | ||
|
||
describe AuctionEnded do | ||
describe '#perform' do | ||
context 'an auction ends' do | ||
it 'sends the winning bidder email' do | ||
auction = create(:auction) | ||
|
||
winning_bidder_email_sender_double = instance_double("WinningBidderEmailSender") | ||
allow(winning_bidder_email_sender_double).to receive(:perform) | ||
allow(WinningBidderEmailSender).to receive(:new) | ||
.with(any_args) | ||
.and_return(winning_bidder_email_sender_double) | ||
|
||
expect(winning_bidder_email_sender_double).to receive(:perform) | ||
|
||
AuctionEnded.new(auction).perform | ||
end | ||
|
||
it 'sends the losing bidders email' do | ||
auction = create(:auction) | ||
|
||
auction = create(:auction, :closed, :with_bidders) | ||
|
||
losing_bidder_email_sender_double = instance_double("LosingBidderEmailSender") | ||
allow(losing_bidder_email_sender_double).to receive(:perform) | ||
allow(LosingBidderEmailSender).to receive(:new) | ||
.with(any_args) | ||
.and_return(losing_bidder_email_sender_double) | ||
|
||
expect(losing_bidder_email_sender_double).to receive(:perform) | ||
|
||
AuctionEnded.new(auction).perform | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'rails_helper' | ||
|
||
describe BuildAuction do | ||
describe '#perform' do | ||
context 'building with all valid params' do | ||
it 'builds the auction object' do | ||
user = create(:user) | ||
params = { auction: FactoryGirl.attributes_for(:auction) } | ||
|
||
auction = BuildAuction.new(params, user).perform | ||
|
||
expect(auction).to be_an(Auction) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'rails_helper' | ||
|
||
describe SaveAuction do | ||
describe '#perform' do | ||
context 'given a valid auction' do | ||
it 'saves the auction' do | ||
auction = build(:auction) | ||
SaveAuction.new(auction).perform | ||
|
||
expect(auction).to be_persisted | ||
end | ||
|
||
it 'returns true' do | ||
auction = build(:auction) | ||
saved = SaveAuction.new(auction).perform | ||
|
||
expect(saved).to eq true | ||
end | ||
end | ||
|
||
context 'given an invalid auction' do | ||
it 'does not save the auction' do | ||
auction = build(:auction, title: nil) | ||
|
||
expect { SaveAuction.new(auction).perform } | ||
.not_to change { Auction.count } | ||
end | ||
|
||
it 'is not persisted' do | ||
auction = build(:auction, title: nil) | ||
SaveAuction.new(auction).perform | ||
|
||
expect(auction).to_not be_persisted | ||
end | ||
|
||
it 'returns false' do | ||
auction = build(:auction, title: nil) | ||
saved = SaveAuction.new(auction).perform | ||
|
||
expect(saved).to be(false) | ||
end | ||
end | ||
end | ||
end |