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

Commit

Permalink
Move bids_placed to bids#index
Browse files Browse the repository at this point in the history
This was in response to PR feedback from Jessie. Thanks!
  • Loading branch information
Jacob Harris committed Oct 19, 2016
1 parent f186c39 commit ddc9e8c
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 89 deletions.
4 changes: 4 additions & 0 deletions app/controllers/bids_controller.rb
Expand Up @@ -12,4 +12,8 @@ def create

redirect_to auction_path(@bid.auction)
end

def index
@view_model = AccountBidsPlacedViewModel.new(current_user: current_user)
end
end
4 changes: 0 additions & 4 deletions app/controllers/users_controller.rb
Expand Up @@ -15,8 +15,4 @@ def update
render :edit
end
end

def bids_placed
@view_model = AccountBidsPlacedViewModel.new(current_user: current_user)
end
end
4 changes: 2 additions & 2 deletions app/view_models/account_bids_placed_view_model.rb
Expand Up @@ -7,9 +7,9 @@ def initialize(current_user:)

def bids_table_partial
if auctions.empty?
'users/bids_table_none'
'bids/bids_table_none'
else
'users/bids_table'
'bids/bids_table'
end
end

Expand Down
File renamed without changes.
50 changes: 13 additions & 37 deletions app/views/bids/index.html.erb
@@ -1,39 +1,15 @@
<div class="usa-grid">
<div>
<%= link_to(
"<icon class='fa fa-angle-double-left'></icon> Back to all auctions".html_safe,
root_path,
class: 'breadcrumb-link') %>
<div class="user-profile">
<div class="user-header-wrapper">
<div class="usa-grid">
<div class="user-header-title">
<h1><%= t 'labels.vendor.account.title' %></h1>
</div>
<%= render partial: 'users/subnav', locals: {active: :bids_placed} %>
</div>
</div>
<div class="user-body-wrapper">
<div class="usa-grid">
<%= render partial: @view_model.bids_table_partial, locals: {view_model: @view_model} %>
</div>
</div>

<h1>My Bids</h1>

<table>
<thead>
<tr>
<th scope="col">Auction</th>
<th scope="col">Auction type</th>
<th scope="col">Auction running?</th>
<th scope="col">Amount</th>
<th scope="col">Winning bid?</th>
<th scope="col">Auction start time</th>
<th scope="col">Auction end time</th>
<th scope="col">Auction delivery deadline</th>
</tr>
</thead>
<tbody>
<% @bids.each do |bid| %>
<tr>
<td><%= link_to(bid.auction_title, auction_path(bid.auction)) %></td>
<td><%= bid.formatted_type %></td>
<td><%= bid.availability %></td>
<td><%= bid.amount %></td>
<td><%= bid.winning_status %></td>
<td><%= bid.started_at %></td>
<td><%= bid.ended_at %></td>
<td><%= bid.delivery_due_at %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
15 changes: 0 additions & 15 deletions app/views/users/bids_placed.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -58,7 +58,7 @@

resources :users, only: [:update]
get 'account/profile', to: 'users#edit', as: 'profile'
get 'account/bids_placed', to: 'users#bids_placed', as: 'bids_placed'
get 'account/bids', to: 'bids#index', as: 'bids_placed'

resources :insights, only: [:index]

Expand Down
30 changes: 30 additions & 0 deletions spec/controllers/bids_controller_spec.rb
Expand Up @@ -4,6 +4,36 @@
let(:current_bidder) { create(:user, sam_status: :sam_accepted) }
let(:auction) { create(:auction) }

describe '#index' do
context 'when logged in' do
it 'should assign auctions that current user have bidded on, presented' do
current_bidder = create(:user, sam_status: :sam_accepted)
auction = create(:auction)
bid = create(:bid, bidder: current_bidder, auction: auction)
expect(bid).to be_valid

get :index, { }, user_id: current_bidder.id

view_model = assigns(:view_model)
expect(view_model).to_not be_nil
expect(view_model.auctions).to_not be_empty
end

it 'should not assign auctions that the current user has not bidded on' do
current_bidder = create(:user, sam_status: :sam_accepted)
auction = create(:auction)
other_person = create(:user)
create(:bid, bidder: other_person, auction: auction)

get :index, { }, user_id: current_bidder.id

view_model = assigns(:view_model)
expect(view_model).to_not be_nil
expect(view_model.auctions).to be_empty
end
end
end

describe '#create' do
context 'when not logged in' do
it 'redirects to authenticate' do
Expand Down
30 changes: 0 additions & 30 deletions spec/controllers/users_controller_spec.rb
Expand Up @@ -27,36 +27,6 @@
end
end

describe '#bids_placed' do
context 'when logged in' do
it 'should assign auctions that current user have bidded on, presented' do
current_bidder = create(:user, sam_status: :sam_accepted)
auction = create(:auction)
bid = create(:bid, bidder: current_bidder, auction: auction)
expect(bid).to be_valid

get :bids_placed, { }, user_id: current_bidder.id

view_model = assigns(:view_model)
expect(view_model).to_not be_nil
expect(view_model.auctions).to_not be_empty
end

it 'should not assign auctions that the current user has not bidded on' do
current_bidder = create(:user, sam_status: :sam_accepted)
auction = create(:auction)
other_person = create(:user)
create(:bid, bidder: other_person, auction: auction)

get :bids_placed, { }, user_id: current_bidder.id

view_model = assigns(:view_model)
expect(view_model).to_not be_nil
expect(view_model.auctions).to be_empty
end
end
end

def user
@_user ||= create(:user)
end
Expand Down

0 comments on commit ddc9e8c

Please sign in to comment.