Browse Source

Stip whitespaces from names before saving organisation, scheme or a user

pull/816/head
Kat 3 years ago
parent
commit
29055730e5
  1. 6
      app/models/organisation.rb
  2. 6
      app/models/scheme.rb
  3. 6
      app/models/user.rb
  4. 2
      spec/requests/organisations_controller_spec.rb
  5. 10
      spec/requests/users_controller_spec.rb

6
app/models/organisation.rb

@ -12,6 +12,8 @@ class Organisation < ApplicationRecord
has_paper_trail has_paper_trail
before_validation :strip_whitespace
PROVIDER_TYPE = { PROVIDER_TYPE = {
LA: 1, LA: 1,
PRP: 2, PRP: 2,
@ -74,4 +76,8 @@ class Organisation < ApplicationRecord
{ name: "data_protection_agreement", value: data_protection_agreement_string, editable: false }, { name: "data_protection_agreement", value: data_protection_agreement_string, editable: false },
] ]
end end
def strip_whitespace
self.name = name.strip unless name.nil?
end
end end

6
app/models/scheme.rb

@ -19,6 +19,8 @@ class Scheme < ApplicationRecord
validate :validate_confirmed validate :validate_confirmed
before_validation :strip_whitespace
SENSITIVE = { SENSITIVE = {
No: 0, No: 0,
Yes: 1, Yes: 1,
@ -228,4 +230,8 @@ class Scheme < ApplicationRecord
end end
end end
end end
def strip_whitespace
self.service_name = service_name.strip unless service_name.nil?
end
end end

6
app/models/user.rb

@ -27,6 +27,8 @@ class User < ApplicationRecord
has_one_time_password(encrypted: true) has_one_time_password(encrypted: true)
before_validation :strip_whitespace
ROLES = { ROLES = {
data_provider: 1, data_provider: 1,
data_coordinator: 2, data_coordinator: 2,
@ -165,4 +167,8 @@ private
end end
end end
end end
def strip_whitespace
self.name = name.strip unless name.nil?
end
end end

2
spec/requests/organisations_controller_spec.rb

@ -993,7 +993,7 @@ RSpec.describe OrganisationsController, type: :request do
it "sets the organisation attributes correctly" do it "sets the organisation attributes correctly" do
request request
organisation = Organisation.find_by(housing_registration_no:) organisation = Organisation.find_by(housing_registration_no:)
expect(organisation.name).to eq(name) expect(organisation.name).to eq("Unique new org name")
expect(organisation.address_line1).to eq(address_line1) expect(organisation.address_line1).to eq(address_line1)
expect(organisation.address_line2).to eq(address_line2) expect(organisation.address_line2).to eq(address_line2)
expect(organisation.postcode).to eq(postcode) expect(organisation.postcode).to eq(postcode)

10
spec/requests/users_controller_spec.rb

@ -850,7 +850,7 @@ RSpec.describe UsersController, type: :request do
let(:personalisation) do let(:personalisation) do
{ {
name: params[:user][:name], name: "new user",
email: params[:user][:email], email: params[:user][:email],
organisation: user.organisation.name, organisation: user.organisation.name,
link: include("/account/confirmation?confirmation_token="), link: include("/account/confirmation?confirmation_token="),
@ -871,6 +871,14 @@ RSpec.describe UsersController, type: :request do
request request
end end
it "creates a new scheme for user organisation with valid params" do
request
expect(User.last.name).to eq("new user")
expect(User.last.email).to eq("new_user@example.com")
expect(User.last.role).to eq("data_coordinator")
end
it "redirects back to organisation users page" do it "redirects back to organisation users page" do
request request
expect(response).to redirect_to("/organisations/#{user.organisation.id}/users") expect(response).to redirect_to("/organisations/#{user.organisation.id}/users")

Loading…
Cancel
Save