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/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 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