Commit b1ce2eb1 authored by Semyon Pupkov's avatar Semyon Pupkov Committed by Semyon Pupkov

refactor(email): use setter method instead AR callbacks

parent a98ad03b
......@@ -10,6 +10,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Use MergeRequestsClosingIssues cache data on Issue#closed_by_merge_requests method
- Fix documents and comments on Build API `scope`
- Refactor email, use setter method instead AR callbacks for email attribute (Semyon Pupkov)
## 8.13.1 (unreleased)
- Fix error in generating labels
......
......@@ -7,10 +7,8 @@ class Email < ActiveRecord::Base
validates :email, presence: true, uniqueness: true, email: true
validate :unique_email, if: ->(email) { email.email_changed? }
before_validation :cleanup_email
def cleanup_email
self.email = self.email.downcase.strip
def email=(value)
write_attribute(:email, value.downcase.strip)
end
def unique_email
......
......@@ -6,4 +6,9 @@ describe Email, models: true do
subject { build(:email) }
end
end
it 'normalize email value' do
expect(described_class.new(email: ' inFO@exAMPLe.com ').email)
.to eq 'info@example.com'
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment