From 31f2de0c6dc2ff61a90e5bc53c637f2f3069a3b4 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Tue, 5 May 2015 11:59:38 +0100 Subject: [PATCH 1/2] Update user invite controller * pass office_id to controller * Display users' office on index and details view * improved tests to ensure data sent --- app/controllers/users/invitations_controller.rb | 2 +- app/views/users/index.html.slim | 2 ++ app/views/users/invitations/new.html.slim | 4 ++-- app/views/users/show.html.slim | 4 +++- spec/features/user_invite_spec.rb | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index 1dbd412e7..7547a71c0 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -10,6 +10,6 @@ def invite_resource end def invite_params - params.require(:user).permit(:email, :role, :name) + params.require(:user).permit(:email, :role, :name, :office_id) end end diff --git a/app/views/users/index.html.slim b/app/views/users/index.html.slim index 17adf6de3..b709e897b 100644 --- a/app/views/users/index.html.slim +++ b/app/views/users/index.html.slim @@ -4,6 +4,7 @@ table tr th Name th Role + th Office th colspan="2"   -@users.each do |user| @@ -13,6 +14,7 @@ table =user.name td =user.role + td =user.office.name if user.office.present? td =link_to 'Edit', edit_user_path(user) td =link_to 'Destroy', user_path(user), method: :delete diff --git a/app/views/users/invitations/new.html.slim b/app/views/users/invitations/new.html.slim index caf303cf4..afcc94e23 100644 --- a/app/views/users/invitations/new.html.slim +++ b/app/views/users/invitations/new.html.slim @@ -15,7 +15,7 @@ h2 = f.label(:roles, 'Role') = f.collection_select :role, User::ROLES, :to_s, :humanize .form-group - = f.label(:office, 'Office') - = f.collection_select :office, Office.all, :id, :name + = f.label(:office_id, 'Office') + = f.collection_select :office_id, Office.all, :id, :name p = f.submit t("devise.invitations.new.submit_button"), class: 'button btn tiny' diff --git a/app/views/users/show.html.slim b/app/views/users/show.html.slim index c79cb70b0..d4587109c 100644 --- a/app/views/users/show.html.slim +++ b/app/views/users/show.html.slim @@ -1,4 +1,6 @@ h2 =@user.email div - =@user.role \ No newline at end of file + =@user.role + +div =@user.office.name \ No newline at end of file diff --git a/spec/features/user_invite_spec.rb b/spec/features/user_invite_spec.rb index ecf8a6613..3f7ae71a1 100644 --- a/spec/features/user_invite_spec.rb +++ b/spec/features/user_invite_spec.rb @@ -19,11 +19,12 @@ fill_in 'user_email', with: new_email fill_in 'user_name', with: new_name select('User', from: 'user_role') - select('Bristol', from: 'user_office') + select('Bristol', from: 'user_office_id') click_button 'Send an invitation' expect(page).to have_xpath('//a', text: new_name) + expect(page).to have_xpath('//td', text: offices.name) end end end From c1dbed0bb2f66cf91f40681e73717341ea7ada94 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Tue, 5 May 2015 13:05:31 +0100 Subject: [PATCH 2/2] Updated user factory * added office * fixed office_controller_spec --- spec/controllers/offices_controller_spec.rb | 4 ++-- spec/factories/users.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/controllers/offices_controller_spec.rb b/spec/controllers/offices_controller_spec.rb index 741ad1f70..c319e0338 100644 --- a/spec/controllers/offices_controller_spec.rb +++ b/spec/controllers/offices_controller_spec.rb @@ -71,7 +71,7 @@ it 'assigns all offices as @offices' do office = Office.create! valid_attributes get :index, {}, valid_session - expect(assigns(:offices)).to eq([office]) + expect(assigns(:offices)).to include(office) end end @@ -143,7 +143,7 @@ it 'assigns all offices as @offices' do office = Office.create! valid_attributes get :index, {}, valid_session - expect(assigns(:offices)).to eq([office]) + expect(assigns(:offices)).to include(office) end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 806ec9992..1ef1599f0 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -4,6 +4,7 @@ sequence(:email) { |n| "user_#{n}@digital.justice.gov.uk" } password 'password' name 'user' + association :office factory :admin_user do role 'admin' end