Skip to content
Snippets Groups Projects
Commit 5bd4bee0 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'remove-callback' into 'master'

This MR removes AR before_validation callback in favor setter.

## Why was this MR needed?

Because setters is good practice to normalize model attributes instead AR callbacks. Because new object should be valid right after initialization. 
If it MR interested I can try to find other places where we can use setters.

See merge request !6763
parents ed256037 b1ce2eb1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment