refactor(email): use setter method instead AR callbacks

This commit is contained in:
Semyon Pupkov 2016-05-23 14:19:27 +05:00 committed by Semyon Pupkov
parent a98ad03ba1
commit b1ce2eb1e5
3 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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