Browse Source

put back org id to the new and removed invalid characters from emails

pull/787/head
JG 3 years ago
parent
commit
b7349b57d0
  1. 2
      app/models/user.rb
  2. 7
      app/views/users/new.html.erb
  3. 8
      spec/requests/users_controller_spec.rb

2
app/models/user.rb

@ -161,7 +161,7 @@ private
if User.exists?(["email LIKE ?", "%#{email}%"])
errors.add :email
else
errors.add :email, I18n.tI18n.t("activerecord.errors.models.user.attributes.email.invalid")
errors.add :email, I18n.t("activerecord.errors.models.user.attributes.email.invalid")
end
end
end

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

@ -28,9 +28,10 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% answer_options = null_option + organisations %>
<% 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,

8
spec/requests/users_controller_spec.rb

@ -1029,7 +1029,7 @@ RSpec.describe UsersController, type: :request do
describe "#index" do
let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "User 2", email: "other@example.com") }
let!(:inactive_user) { FactoryBot.create(:user, organisation: user.organisation, active: false, name: "User 3", email: "inactive@example.com") }
let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "other_org@other_example.com") }
let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "otherorg@otherexample.com") }
before do
sign_in user
@ -1096,7 +1096,7 @@ RSpec.describe UsersController, type: :request do
end
context "when our search term matches an email" do
let(:search_param) { "other_org@other_example.com" }
let(:search_param) { "otherorg@otherexample.com" }
it "returns only matching result" do
expect(page).not_to have_content(user.name)
@ -1108,7 +1108,7 @@ RSpec.describe UsersController, type: :request do
context "when our search term matches an email and a name" do
let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "joe", email: "other@example.com") }
let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@other_example.com") }
let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@otherexample.com") }
let(:search_param) { "joe" }
it "returns any results including joe" do
@ -1620,7 +1620,7 @@ RSpec.describe UsersController, type: :request do
FactoryBot.create(:user, email: "new_user@example.com")
end
it "shows an error" do
it "shows an error messages for all failed validations" do
request
expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.name.blank"))

Loading…
Cancel
Save