From ddc9e8cd5fc03c67fdf9f4344054dcf0b6ac3ae8 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Wed, 19 Oct 2016 17:50:45 -0400 Subject: [PATCH] Move bids_placed to bids#index This was in response to PR feedback from Jessie. Thanks! --- app/controllers/bids_controller.rb | 4 ++ app/controllers/users_controller.rb | 4 -- .../account_bids_placed_view_model.rb | 4 +- .../{users => bids}/_bids_table.html.erb | 0 .../{users => bids}/_bids_table_none.html.erb | 0 app/views/bids/index.html.erb | 50 +++++-------------- app/views/users/bids_placed.html.erb | 15 ------ config/routes.rb | 2 +- spec/controllers/bids_controller_spec.rb | 30 +++++++++++ spec/controllers/users_controller_spec.rb | 30 ----------- 10 files changed, 50 insertions(+), 89 deletions(-) rename app/views/{users => bids}/_bids_table.html.erb (100%) rename app/views/{users => bids}/_bids_table_none.html.erb (100%) delete mode 100644 app/views/users/bids_placed.html.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 82a758db..51a8fc00 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 179bb84f..b10e3260 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -15,8 +15,4 @@ def update render :edit end end - - def bids_placed - @view_model = AccountBidsPlacedViewModel.new(current_user: current_user) - end end diff --git a/app/view_models/account_bids_placed_view_model.rb b/app/view_models/account_bids_placed_view_model.rb index 4f9c2993..fc7eb7ef 100644 --- a/app/view_models/account_bids_placed_view_model.rb +++ b/app/view_models/account_bids_placed_view_model.rb @@ -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 diff --git a/app/views/users/_bids_table.html.erb b/app/views/bids/_bids_table.html.erb similarity index 100% rename from app/views/users/_bids_table.html.erb rename to app/views/bids/_bids_table.html.erb diff --git a/app/views/users/_bids_table_none.html.erb b/app/views/bids/_bids_table_none.html.erb similarity index 100% rename from app/views/users/_bids_table_none.html.erb rename to app/views/bids/_bids_table_none.html.erb diff --git a/app/views/bids/index.html.erb b/app/views/bids/index.html.erb index 8b49916c..c2365519 100644 --- a/app/views/bids/index.html.erb +++ b/app/views/bids/index.html.erb @@ -1,39 +1,15 @@ -
-
- <%= link_to( - " Back to all auctions".html_safe, - root_path, - class: 'breadcrumb-link') %> + diff --git a/app/views/users/bids_placed.html.erb b/app/views/users/bids_placed.html.erb deleted file mode 100644 index c2365519..00000000 --- a/app/views/users/bids_placed.html.erb +++ /dev/null @@ -1,15 +0,0 @@ - diff --git a/config/routes.rb b/config/routes.rb index 4091ae54..aed56586 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/spec/controllers/bids_controller_spec.rb b/spec/controllers/bids_controller_spec.rb index 58bbdebe..6f028dd3 100644 --- a/spec/controllers/bids_controller_spec.rb +++ b/spec/controllers/bids_controller_spec.rb @@ -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 diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 4f8e6dd8..41a51dc6 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -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