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.
Merge pull request #903 from 18F/unpublished-auctions-are-unavailable
Unpublished auctions should not be available
- Loading branch information
Showing
2 changed files
with
85 additions
and
121 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 |
---|---|---|
@@ -1,155 +1,115 @@ | ||
require "rails_helper" | ||
require 'rails_helper' | ||
|
||
describe AuctionStatus do | ||
describe "#available?" do | ||
context "start datetime in past, end datetime in future" do | ||
it "is true" do | ||
auction = FactoryGirl.build(:auction, started_at: yesterday, ended_at: tomorrow) | ||
|
||
describe '#available?' do | ||
context 'start datetime in past, end datetime in future' do | ||
it 'is true' do | ||
auction = FactoryGirl.build(:auction, :available) | ||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).to be_available | ||
end | ||
|
||
context "start datetime in past, end datetime in past" do | ||
it "is false" do | ||
auction = FactoryGirl.build(:auction, started_at: yesterday, ended_at: yesterday) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_available | ||
end | ||
end | ||
|
||
context "start datetime in future, end datetime in future" do | ||
it "is false" do | ||
auction = FactoryGirl.build(:auction, started_at: tomorrow, ended_at: tomorrow) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_available | ||
end | ||
end | ||
end | ||
|
||
describe "#over?" do | ||
context "end datetime is in past" do | ||
it "is true" do | ||
auction = FactoryGirl.build(:auction, ended_at: yesterday) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).to be_over | ||
end | ||
context 'start datetime in past, end datetime in past' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :closed) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_available | ||
end | ||
end | ||
|
||
context "end datetime is in future" do | ||
it "is false" do | ||
auction = FactoryGirl.build(:auction, ended_at: tomorrow) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_over | ||
end | ||
context 'start datetime in future, end datetime in future' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :future) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_available | ||
end | ||
end | ||
|
||
context "end datetime is nil" do | ||
it "is false" do | ||
auction = FactoryGirl.build(:auction, ended_at: nil) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_over | ||
end | ||
context 'the auction is not published' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :available, published: false) | ||
status = AuctionStatus.new(auction) | ||
expect(status).to_not be_available | ||
end | ||
end | ||
end | ||
|
||
describe "#future?" do | ||
context "start datetime is in future" do | ||
it "is true" do | ||
auction = FactoryGirl.build(:auction, started_at: tomorrow) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).to be_future | ||
end | ||
describe '#over?' do | ||
context 'end datetime is in past' do | ||
it 'is true' do | ||
auction = FactoryGirl.build(:auction, :closed) | ||
status = AuctionStatus.new(auction) | ||
expect(status).to be_over | ||
end | ||
end | ||
|
||
context "start datetime is in past" do | ||
it "is false" do | ||
auction = FactoryGirl.build(:auction, started_at: yesterday) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_future | ||
end | ||
context 'end datetime is in future' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :future) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_over | ||
end | ||
end | ||
|
||
context "start datetime is nil" do | ||
it "is true" do | ||
auction = FactoryGirl.build(:auction, started_at: nil) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).to be_future | ||
end | ||
context 'end datetime is nil' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, ended_at: nil) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_over | ||
end | ||
end | ||
end | ||
|
||
describe "expiring?" do | ||
context "auction in progress and expiring in less than 12 hours" do | ||
it "is true" do | ||
auction = FactoryGirl.build( | ||
:auction, | ||
started_at: yesterday, | ||
ended_at: one_hour_from_now | ||
) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).to be_expiring | ||
end | ||
describe '#future?' do | ||
context 'start datetime is in future' do | ||
it 'is true' do | ||
auction = FactoryGirl.build(:auction, :future) | ||
status = AuctionStatus.new(auction) | ||
expect(status).to be_future | ||
end | ||
end | ||
|
||
context "auction not started and expiring in less than 12 hours" do | ||
it "is false" do | ||
auction = FactoryGirl.build( | ||
:auction, | ||
started_at: tomorrow, | ||
ended_at: one_hour_from_now | ||
) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_expiring | ||
end | ||
context 'start datetime is in past' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :available) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_future | ||
end | ||
end | ||
|
||
context "auction in progress and expiring in more than 12 hours" do | ||
it "is false" do | ||
auction = FactoryGirl.build( | ||
:auction, | ||
started_at: yesterday, | ||
ended_at: tomorrow | ||
) | ||
|
||
status = AuctionStatus.new(auction) | ||
|
||
expect(status).not_to be_expiring | ||
end | ||
context 'start datetime is nil' do | ||
it 'is true' do | ||
auction = FactoryGirl.build(:auction, started_at: nil) | ||
status = AuctionStatus.new(auction) | ||
expect(status).to be_future | ||
end | ||
end | ||
end | ||
|
||
def yesterday | ||
@_yesterday ||= Time.current - 1.day | ||
describe 'expiring?' do | ||
context 'auction in progress and expiring in less than 12 hours' do | ||
it 'is true' do | ||
auction = FactoryGirl.build(:auction, :expiring) | ||
status = AuctionStatus.new(auction) | ||
expect(status).to be_expiring | ||
end | ||
end | ||
|
||
def tomorrow | ||
@_tomorrow ||= Time.current + 1.day | ||
context 'auction not started and expiring in less than 12 hours' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :future) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_expiring | ||
end | ||
end | ||
|
||
def one_hour_from_now | ||
@_one_hour_from_now ||= Time.current + 1.hour | ||
context 'auction in progress and expiring in more than 12 hours' do | ||
it 'is false' do | ||
auction = FactoryGirl.build(:auction, :available) | ||
status = AuctionStatus.new(auction) | ||
expect(status).not_to be_expiring | ||
end | ||
end | ||
end | ||
end |