diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-08 13:12:05 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-08 13:12:05 -0300 |
commit | ff83868b10001af74c6f258e878bb29be6425c8d (patch) | |
tree | a49cbce351c97c695532d11dd3d105e0d89d69ef /activerecord/lib | |
parent | 8d1af2b10c02ab5ecd32be0d2a5b1f937ddd25e1 (diff) | |
parent | e3d99e239dd1b59d31ac90f74186ded8b55de599 (diff) | |
download | rails-ff83868b10001af74c6f258e878bb29be6425c8d.tar.gz rails-ff83868b10001af74c6f258e878bb29be6425c8d.tar.bz2 rails-ff83868b10001af74c6f258e878bb29be6425c8d.zip |
Merge pull request #21535 from dmitry/feature/validate-multiple-contexts
Validate multiple contexts on `valid?` and `invalid?` at once
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 74daece4e8..4113ca4561 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -60,7 +60,7 @@ module ActiveRecord # Validations with no <tt>:on</tt> option will run no matter the context. Validations with # some <tt>:on</tt> option will only run in the specified context. def valid?(context = nil) - context ||= (new_record? ? :create : :update) + context ||= default_validation_context output = super(context) errors.empty? && output end @@ -69,6 +69,10 @@ module ActiveRecord protected + def default_validation_context + new_record? ? :create : :update + end + def raise_validation_error raise(RecordInvalid.new(self)) end |