From 8fad8711000cc14f096ff6c8f968ed4f86a0eff2 Mon Sep 17 00:00:00 2001 From: Rahul Date: Fri, 16 Aug 2019 13:38:25 +0530 Subject: [PATCH] add test for bulk action --- .../admin/booths_controller_spec.rb | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/spec/controllers/admin/booths_controller_spec.rb b/spec/controllers/admin/booths_controller_spec.rb index 72d8f234..e4e00e61 100644 --- a/spec/controllers/admin/booths_controller_spec.rb +++ b/spec/controllers/admin/booths_controller_spec.rb @@ -34,12 +34,32 @@ describe Admin::BoothsController do describe 'GET index' do before { get :index, params: { conference_id: conference.short_title } } - it 'assigns attributes for booths' do - expect(assigns(:booths)).to eq([booth]) + context 'only viewing' do + + it 'assigns attributes for booths' do + expect(assigns(:booths)).to eq([booth]) + end + + it 'renders index template' do + expect(response).to render_template('index') + end end - it 'renders index template' do - expect(response).to render_template('index') + context 'changing bulk state' do + before(:example) do + post :create, params: { booth: attributes_for(:booth, title: 'example1'), conference_id: conference.short_title } + post :create, params: { booth: attributes_for(:booth, title: 'example2'), conference_id: conference.short_title } + get :index, params: { conference_id: conference.short_title } + end + + it 'before selecting state' do + expect(Booth.where(title: ['example1', 'example2']).pluck(:state)).to eq(['new', 'new']) + end + + it 'after selecting state' do + post :booths_state, params: { booth: { current_booth_state: 'new', new_booth_state: 'Reject' }, conference_id: conference.short_title } + expect(Booth.where(title: ['example1', 'example2']).pluck(:state)).to eq(['rejected', 'rejected']) + end end end