Browse Source

Abstract strip whitespaces method and use it for locations too

pull/816/head
Kat 3 years ago
parent
commit
46f1cc7b5b
  1. 5
      app/models/application_record.rb
  2. 1
      app/models/location.rb
  3. 7
      app/models/organisation.rb
  4. 6
      app/models/scheme.rb
  5. 6
      app/models/user.rb

5
app/models/application_record.rb

@ -1,3 +1,8 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def strip_whitespaces
self.service_name = service_name.strip unless !respond_to?("service_name") || service_name.nil?
self.name = name.strip unless !respond_to?("name") || name.nil?
end
end

1
app/models/location.rb

@ -6,6 +6,7 @@ class Location < ApplicationRecord
has_paper_trail
before_save :lookup_postcode!, if: :postcode_changed?
before_validation :strip_whitespaces
attr_accessor :add_another_location

7
app/models/organisation.rb

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

6
app/models/scheme.rb

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

6
app/models/user.rb

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

Loading…
Cancel
Save