From 6f6da596c47ee90d8598fbb903f3f484419fdc8c Mon Sep 17 00:00:00 2001 From: JG Date: Tue, 31 May 2022 17:32:32 +0100 Subject: [PATCH] passing feature --- app/controllers/users_controller.rb | 3 +++ app/views/organisations/users.html.erb | 2 +- app/views/users/new.html.erb | 6 +++++- spec/features/organisation_spec.rb | 5 ++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7c52cdc0d..00e28aac0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -62,6 +62,9 @@ class UsersController < ApplicationController end def new + if current_user.data_coordinator? || current_user.support? + @organisation_id = params["organisation_id"] + end @resource = User.new end diff --git a/app/views/organisations/users.html.erb b/app/views/organisations/users.html.erb index 929e08081..082ffb384 100644 --- a/app/views/organisations/users.html.erb +++ b/app/views/organisations/users.html.erb @@ -16,7 +16,7 @@ ) %> <% if current_user.data_coordinator? || current_user.support? %> - <%= govuk_button_link_to "Invite user", new_user_path, html: { method: :get } %> + <%= govuk_button_link_to "Invite user", new_user_path(organisation_id: @organisation.id), html: { method: :get } %> <% end %> <%= render SearchComponent.new(current_user:, search_label: "Search by name or email address", value: @searched) %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 642337fc4..072979710 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -30,13 +30,17 @@ <% null_option = [OpenStruct.new(id: "", name: "Select an option")] %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% answer_options = null_option + organisations %> + <% if @organisation_id %> + <% organisation = Organisation.find(@organisation_id) %> + <% answer_options = [OpenStruct.new(id: organisation.id, name: organisation.name)] %> + <% end %> <%= f.govuk_collection_select :organisation_id, answer_options, :id, :name, label: { text: "Organisation", size: "m" }, - options: { disabled: [""], selected: "" } %> + options: { disabled: [""], selected: @organisation_id ? answer_options : "" } %> <% end %> <% roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %> diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index f745f3095..978850c8e 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -5,6 +5,7 @@ RSpec.describe "User Features" do include Helpers let(:organisation) { user.organisation } let(:org_id) { organisation.id } + let(:org_name) { organisation.name } let(:set_password_template_id) { User::CONFIRMABLE_TEMPLATE_ID } let(:notify_client) { instance_double(Notifications::Client) } let(:confirmation_token) { "MCDH5y6Km-U7CFPgAMVS" } @@ -199,7 +200,9 @@ RSpec.describe "User Features" do before do click_link(text: "Invite user") end - it "pre-fills the organisation details dropdown with specific organisation" do + + it "has only specific organisation name in the dropdown" do + expect(page).to have_select("user-organisation-id-field", options: [org_name]) end end end