Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #903 from 18F/unpublished-auctions-are-unavailable
Browse files Browse the repository at this point in the history
Unpublished auctions should not be available
  • Loading branch information
jessieay committed Jul 19, 2016
2 parents 01b742f + 3a93603 commit d0ee314
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 121 deletions.
6 changes: 5 additions & 1 deletion app/models/auction_status.rb
Expand Up @@ -4,7 +4,7 @@ def initialize(auction)
end

def available?
started_in_past? && ends_in_future?
published? && started_in_past? && ends_in_future?
end

def over?
Expand All @@ -23,6 +23,10 @@ def expiring?

attr_reader :auction

def published?
auction.published?
end

def ends_in_future?
auction.ended_at > Time.current
end
Expand Down
200 changes: 80 additions & 120 deletions spec/models/auction_status_spec.rb
@@ -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

0 comments on commit d0ee314

Please sign in to comment.