From ab1f03d5ab52b690cf1b82c8b58ddd56808e4619 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Thu, 2 Dec 2021 16:59:25 +0000 Subject: [PATCH] Add role to invite (#140) * Add role to invite * Make role field a radio button * Fix broken specs on main --- app/controllers/users_controller.rb | 2 +- app/views/users/new.html.erb | 4 ++++ spec/features/form/form_navigation_spec.rb | 4 ++-- spec/features/organisation_spec.rb | 2 ++ spec/requests/case_log_controller_spec.rb | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2133b88af..30afa501b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,6 +46,6 @@ private end def user_params - params.require(:user).permit(:email, :name, :password) + params.require(:user).permit(:email, :name, :password, :role) end end diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index f4c5f2b15..3d48e68f6 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -26,6 +26,10 @@ value: @resource.email %> + <%= roles = User::ROLES.map { |key, value| OpenStruct.new(id:key, name: key.humanize) } + f.govuk_collection_radio_buttons :role, roles, :id, :name, legend: { text: "Role", size: "m" } + %> + <%= f.govuk_submit "Continue" %> diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index be86e82f1..c2e29bb5c 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -31,7 +31,7 @@ RSpec.describe "Form Navigation" do visit("/case-logs") click_link("Create new log") id = CaseLog.order(created_at: :desc).first.id - expect(page).to have_content("Tasklist for log #{id}") + expect(page).to have_content("Case log #{id}") end end @@ -55,7 +55,7 @@ RSpec.describe "Form Navigation" do visit("/case-logs/#{id}") visit("/case-logs/#{id}/tenant-code") click_link(text: "Back") - expect(page).to have_content("Tasklist for log #{id}") + expect(page).to have_content("Case log #{id}") end it "go back to tenant code page from tenant age page", js: true do diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index dd6d120e8..4172a1ba4 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -38,8 +38,10 @@ RSpec.describe "User Features" do expect(page).to have_content("Invite user to submit CORE data") fill_in("user[name]", with: "New User") fill_in("user[email]", with: "new_user@example.com") + choose("user-role-data-provider-field") expect { click_button("Continue") }.to change { ActionMailer::Base.deliveries.count }.by(1) expect(page).to have_current_path("/organisations/#{org_id}/users") + expect(User.last.role).to eq("data_provider") end end end diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index 7ee60423a..deeb6840c 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -187,7 +187,7 @@ RSpec.describe CaseLogsController, type: :request do end it "shows the tasklist for case logs you have access to" do - expect(response.body).to match("Tasklist for log") + expect(response.body).to match("Case log") expect(response.body).to match(case_log.id.to_s) end