diff --git a/Gemfile b/Gemfile index 168ace7af..e995bb7e0 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,7 @@ gem "redis" gem "sentry-rails" gem "sentry-ruby" # Possessives in strings +gem "auto_strip_attributes" gem "possessive" group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 4bcfa6266..2239fcdf5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,8 @@ GEM addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) + auto_strip_attributes (2.6.0) + activerecord (>= 4.0) aws-eventstream (1.2.0) aws-partitions (1.609.0) aws-sdk-core (3.131.3) @@ -428,6 +430,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + auto_strip_attributes aws-sdk-s3 bootsnap (>= 1.4.4) bundler-audit diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 5078d4de5..10a4cba84 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,7 +1,3 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true - - def strip_whitespaces - fields_to_strip.each { |field| self[field] = self[field].strip if field.present? } - end end diff --git a/app/models/location.rb b/app/models/location.rb index 3a9069e56..03d14d865 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -6,11 +6,8 @@ class Location < ApplicationRecord has_paper_trail before_save :lookup_postcode!, if: :postcode_changed? - before_validation :strip_whitespaces - def fields_to_strip - %w[name] - end + auto_strip_attributes :name attr_accessor :add_another_location diff --git a/app/models/organisation.rb b/app/models/organisation.rb index bc69ceacf..e02d5be19 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -12,11 +12,7 @@ class Organisation < ApplicationRecord has_paper_trail - before_validation :strip_whitespaces - - def fields_to_strip - %w[name] - end + auto_strip_attributes :name PROVIDER_TYPE = { LA: 1, diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 807627a76..45f09d4a5 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -19,11 +19,7 @@ class Scheme < ApplicationRecord validate :validate_confirmed - before_validation :strip_whitespaces - - def fields_to_strip - %w[service_name] - end + auto_strip_attributes :service_name SENSITIVE = { No: 0, diff --git a/app/models/user.rb b/app/models/user.rb index 1d92b10f5..f9ed4a0e9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -27,11 +27,7 @@ class User < ApplicationRecord has_one_time_password(encrypted: true) - before_validation :strip_whitespaces - - def fields_to_strip - %w[name] - end + auto_strip_attributes :name ROLES = { data_provider: 1,