Browse Source

almost done

pull/627/head
JG 3 years ago
parent
commit
ecdcea77a1
  1. 4
      app/controllers/users_controller.rb
  2. 2
      app/views/users/new.html.erb
  3. 2
      spec/features/organisation_spec.rb
  4. 29
      spec/requests/users_controller_spec.rb

4
app/controllers/users_controller.rb

@ -62,9 +62,7 @@ class UsersController < ApplicationController
end
def new
if current_user.data_coordinator? || current_user.support?
@organisation_id = params["organisation_id"]
end
@organisation_id = params["organisation_id"]
@resource = User.new
end

2
app/views/users/new.html.erb

@ -40,7 +40,7 @@
:id,
:name,
label: { text: "Organisation", size: "m" },
options: { disabled: [""], selected: @organisation_id ? answer_options : "" } %>
options: { disabled: [""], selected: @organisation_id ? answer_options.first : "" } %>
<% end %>
<% roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>

2
spec/features/organisation_spec.rb

@ -199,7 +199,7 @@ RSpec.describe "User Features" do
context "when I click on Invite user and there are multiple organisations in the database" do
before do
FactoryBot.create_list(:organisation, 5)
click_link(text: "Invite user")
click_link(text: "Invite user")
end
it "has only specific organisation name in the dropdown" do

29
spec/requests/users_controller_spec.rb

@ -1593,16 +1593,31 @@ RSpec.describe UsersController, type: :request do
describe "#new" do
before do
sign_in user
FactoryBot.create(:organisation, name: "other org")
end
it "can assign support role to the new user" do
get "/users/new"
expect(page).to have_field("user-role-support-field")
end
context "when support user" do
it "can assign support role to the new user" do
get "/users/new"
expect(page).to have_field("user-role-support-field")
end
it "can assign organisation to the new user" do
get "/users/new"
expect(page).to have_field("user-organisation-id-field")
it "can assign organisation to the new user" do
get "/users/new"
expect(page).to have_field("user-organisation-id-field")
end
it "has all organisation names in the dropdown" do
get "/users/new"
expect(page).to have_select("user-organisation-id-field", options: Organisation.pluck(:name))
end
context "when organisation id is present in params in there are multiple organisations in the database" do
it "has only specific organisation name in the dropdown" do
get "/users/new", params: {organisation_id: user.organisation.id}
expect(page).to have_select("user-organisation-id-field", options: [user.organisation.name])
end
end
end
end
end

Loading…
Cancel
Save