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

Commit

Permalink
Don't show the CSV download for auctions without bidders
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Harris committed Nov 8, 2016
1 parent dff41d6 commit 127c7fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/view_models/admin/auction_show_view_model.rb
Expand Up @@ -7,7 +7,7 @@ def initialize(auction:, current_user:)
end

def csv_report_partial
if bidding_status.over?
if bidding_status.over? && bids?
'admin/auctions/csv_report'
else
'components/null'
Expand Down Expand Up @@ -120,8 +120,8 @@ def c2_fields
end
end

def bidding_status
BiddingStatus.new(auction)
def bids?
auction.bids.any?
end

def customer
Expand Down
34 changes: 34 additions & 0 deletions spec/view_models/admin/auction_show_view_model_spec.rb
Expand Up @@ -30,4 +30,38 @@
end
end
end

describe "#csv_report_partial" do
it 'should return a partial when the auction is over and has a winner' do
auction = create(:auction, :with_bids, :closed)
user = create(:user)
view_model = Admin::AuctionShowViewModel.new(auction: auction, current_user: user)

expect(view_model.csv_report_partial).to_not eq('components/null')
end

it 'should return a null partial when the auction had no winners' do
auction = create(:auction, :closed)
user = create(:user)
view_model = Admin::AuctionShowViewModel.new(auction: auction, current_user: user)

expect(view_model.csv_report_partial).to eq('components/null')
end

it 'should be a null partial when the auction has not started' do
auction = create(:auction, :future)
user = create(:user)
view_model = Admin::AuctionShowViewModel.new(auction: auction, current_user: user)

expect(view_model.csv_report_partial).to eq('components/null')
end

it 'should be a null partial when the auction is still running' do
auction = create(:auction, :with_bids)
user = create(:user)
view_model = Admin::AuctionShowViewModel.new(auction: auction, current_user: user)

expect(view_model.csv_report_partial).to eq('components/null')
end
end
end

0 comments on commit 127c7fa

Please sign in to comment.