activemodel 4.1.0.beta2 → 4.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activemodel might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -3
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/lib/active_model.rb +3 -3
- data/lib/active_model/attribute_methods.rb +11 -16
- data/lib/active_model/callbacks.rb +1 -1
- data/lib/active_model/conversion.rb +2 -2
- data/lib/active_model/dirty.rb +10 -6
- data/lib/active_model/errors.rb +23 -23
- data/lib/active_model/lint.rb +1 -1
- data/lib/active_model/model.rb +1 -1
- data/lib/active_model/secure_password.rb +12 -12
- data/lib/active_model/serialization.rb +1 -1
- data/lib/active_model/serializers/json.rb +1 -1
- data/lib/active_model/validations.rb +12 -10
- data/lib/active_model/validations/absence.rb +1 -1
- data/lib/active_model/validations/acceptance.rb +2 -4
- data/lib/active_model/validations/callbacks.rb +1 -1
- data/lib/active_model/validations/confirmation.rb +1 -1
- data/lib/active_model/validations/exclusion.rb +1 -5
- data/lib/active_model/validations/format.rb +1 -5
- data/lib/active_model/validations/inclusion.rb +3 -6
- data/lib/active_model/validations/length.rb +1 -1
- data/lib/active_model/validations/numericality.rb +1 -1
- data/lib/active_model/validations/presence.rb +1 -1
- data/lib/active_model/validations/validates.rb +3 -1
- data/lib/active_model/validator.rb +1 -1
- data/lib/active_model/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c2e46709d7f8d23a7f279b60e968ed229340e15
|
4
|
+
data.tar.gz: bdd281762b3380a85ba7bea143e1864aed5cc25f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea32bb3ee8545b82dd63b1975ff79ad1ceaa7546b24170f1782c72539f800ac137dfc99445f617bb9ab8022faa5b6a3c23df2b021935ba0ededd963da113b861
|
7
|
+
data.tar.gz: 31bcdc6c6a1dfdcd06ce6ca967160dfbb388916f66c44e317304074e1d211139a163c76e24eb016239220c9f05517d7333837c6471db8f352f8fd8ab25046fc5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
* `#to_param` returns `nil` if `#to_key` returns `nil`. Fixes #11399.
|
2
|
+
|
3
|
+
*Yves Senn*
|
4
|
+
|
5
|
+
* Ability to specify multiple contexts when defining a validation.
|
6
|
+
|
7
|
+
Example:
|
8
|
+
|
9
|
+
class Person
|
10
|
+
include ActiveModel::Validations
|
11
|
+
|
12
|
+
attr_reader :name
|
13
|
+
validates_presence_of :name, on: [:verify, :approve]
|
14
|
+
end
|
15
|
+
|
16
|
+
person = Person.new
|
17
|
+
person.valid? # => true
|
18
|
+
person.valid?(:verify) # => false
|
19
|
+
person.errors.full_messages_for(:name) # => ["Name can't be blank"]
|
20
|
+
person.valid?(:approve) # => false
|
21
|
+
person.errors.full_messages_for(:name) # => ["Name can't be blank"]
|
22
|
+
|
23
|
+
*Vince Puzzella*
|
24
|
+
|
25
|
+
* `attribute_changed?` now accepts a hash to check if the attribute was
|
26
|
+
changed `:from` and/or `:to` a given value.
|
27
|
+
|
28
|
+
Example:
|
29
|
+
|
30
|
+
model.name_changed?(from: "Pete", to: "Ringo")
|
31
|
+
|
32
|
+
*Tejas Dinkar*
|
33
|
+
|
1
34
|
* Fix `has_secure_password` to honor bcrypt-ruby's cost attribute.
|
2
35
|
|
3
36
|
*T.J. Schuck*
|
@@ -13,8 +46,8 @@
|
|
13
46
|
|
14
47
|
*Bogdan Gusiev*
|
15
48
|
|
16
|
-
* Fix has_secure_password
|
17
|
-
|
49
|
+
* Fix `has_secure_password` not to trigger `password_confirmation` validations
|
50
|
+
if no `password_confirmation` is set.
|
18
51
|
|
19
52
|
*Vladimir Kiselev*
|
20
53
|
|
@@ -27,7 +60,7 @@
|
|
27
60
|
|
28
61
|
*Charles Bergeron*
|
29
62
|
|
30
|
-
* Fix regression in has_secure_password
|
63
|
+
* Fix regression in `has_secure_password`. When a password is set, but a
|
31
64
|
confirmation is an empty string, it would incorrectly save.
|
32
65
|
|
33
66
|
*Steve Klabnik* and *Phillip Calvin*
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -109,7 +109,7 @@ behavior out of the box:
|
|
109
109
|
attr_reader :errors
|
110
110
|
|
111
111
|
def validate!
|
112
|
-
errors.add(:name, "
|
112
|
+
errors.add(:name, "cannot be nil") if name.nil?
|
113
113
|
end
|
114
114
|
|
115
115
|
def self.human_attribute_name(attr, options = {})
|
@@ -118,7 +118,7 @@ behavior out of the box:
|
|
118
118
|
end
|
119
119
|
|
120
120
|
person.errors.full_messages
|
121
|
-
# => ["Name
|
121
|
+
# => ["Name cannot be nil"]
|
122
122
|
|
123
123
|
{Learn more}[link:classes/ActiveModel/Errors.html]
|
124
124
|
|
data/lib/active_model.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2004-
|
2
|
+
# Copyright (c) 2004-2014 David Heinemeier Hansson
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -59,9 +59,9 @@ module ActiveModel
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def eager_load!
|
62
|
+
def self.eager_load!
|
63
63
|
super
|
64
|
-
ActiveModel::
|
64
|
+
ActiveModel::Serializers.eager_load!
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -14,11 +14,11 @@ module ActiveModel
|
|
14
14
|
class MissingAttributeError < NoMethodError
|
15
15
|
end
|
16
16
|
|
17
|
-
# == Active \Model Attribute Methods
|
17
|
+
# == Active \Model \Attribute \Methods
|
18
18
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
19
|
+
# Provides a way to add prefixes and suffixes to your methods as
|
20
|
+
# well as handling the creation of <tt>ActiveRecord::Base</tt>-like
|
21
|
+
# class methods such as +table_name+.
|
22
22
|
#
|
23
23
|
# The requirements to implement <tt>ActiveModel::AttributeMethods</tt> are to:
|
24
24
|
#
|
@@ -27,7 +27,9 @@ module ActiveModel
|
|
27
27
|
# or +attribute_method_prefix+.
|
28
28
|
# * Call +define_attribute_methods+ after the other methods are called.
|
29
29
|
# * Define the various generic +_attribute+ methods that you have declared.
|
30
|
-
# * Define an +attributes+ method
|
30
|
+
# * Define an +attributes+ method which returns a hash with each
|
31
|
+
# attribute name in your model as hash key and the attribute value as hash value.
|
32
|
+
# Hash keys must be strings.
|
31
33
|
#
|
32
34
|
# A minimal implementation could be:
|
33
35
|
#
|
@@ -42,7 +44,7 @@ module ActiveModel
|
|
42
44
|
# attr_accessor :name
|
43
45
|
#
|
44
46
|
# def attributes
|
45
|
-
# {'name' => @name}
|
47
|
+
# { 'name' => @name }
|
46
48
|
# end
|
47
49
|
#
|
48
50
|
# private
|
@@ -59,13 +61,6 @@ module ActiveModel
|
|
59
61
|
# send("#{attr}=", 'Default Name')
|
60
62
|
# end
|
61
63
|
# end
|
62
|
-
#
|
63
|
-
# Note that whenever you include <tt>ActiveModel::AttributeMethods</tt> in
|
64
|
-
# your class, it requires you to implement an +attributes+ method which
|
65
|
-
# returns a hash with each attribute name in your model as hash key and the
|
66
|
-
# attribute value as hash value.
|
67
|
-
#
|
68
|
-
# Hash keys must be strings.
|
69
64
|
module AttributeMethods
|
70
65
|
extend ActiveSupport::Concern
|
71
66
|
|
@@ -173,14 +168,14 @@ module ActiveModel
|
|
173
168
|
# private
|
174
169
|
#
|
175
170
|
# def reset_attribute_to_default!(attr)
|
176
|
-
#
|
171
|
+
# send("#{attr}=", 'Default Name')
|
177
172
|
# end
|
178
173
|
# end
|
179
174
|
#
|
180
175
|
# person = Person.new
|
181
176
|
# person.name # => 'Gem'
|
182
177
|
# person.reset_name_to_default!
|
183
|
-
# person.name # => '
|
178
|
+
# person.name # => 'Default Name'
|
184
179
|
def attribute_method_affix(*affixes)
|
185
180
|
self.attribute_method_matchers += affixes.map! { |affix| AttributeMethodMatcher.new prefix: affix[:prefix], suffix: affix[:suffix] }
|
186
181
|
undefine_attribute_methods
|
@@ -250,7 +245,7 @@ module ActiveModel
|
|
250
245
|
# private
|
251
246
|
#
|
252
247
|
# def clear_attribute(attr)
|
253
|
-
#
|
248
|
+
# send("#{attr}=", nil)
|
254
249
|
# end
|
255
250
|
# end
|
256
251
|
def define_attribute_methods(*attr_names)
|
@@ -30,7 +30,7 @@ module ActiveModel
|
|
30
30
|
# end
|
31
31
|
#
|
32
32
|
# Then in your class, you can use the +before_create+, +after_create+ and
|
33
|
-
# +around_create+ methods, just as you would in an Active Record
|
33
|
+
# +around_create+ methods, just as you would in an Active Record model.
|
34
34
|
#
|
35
35
|
# before_create :action_before_create
|
36
36
|
#
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ActiveModel
|
2
|
-
# == Active \Model Conversion
|
2
|
+
# == Active \Model \Conversion
|
3
3
|
#
|
4
4
|
# Handles default conversions: to_model, to_key, to_param, and to_partial_path.
|
5
5
|
#
|
@@ -62,7 +62,7 @@ module ActiveModel
|
|
62
62
|
# person = Person.create
|
63
63
|
# person.to_param # => "1"
|
64
64
|
def to_param
|
65
|
-
persisted? ?
|
65
|
+
(persisted? && key = to_key) ? key.join('-') : nil
|
66
66
|
end
|
67
67
|
|
68
68
|
# Returns a +string+ identifying the path associated with the object.
|
data/lib/active_model/dirty.rb
CHANGED
@@ -54,6 +54,7 @@ module ActiveModel
|
|
54
54
|
# person.name = 'Bob'
|
55
55
|
# person.changed? # => true
|
56
56
|
# person.name_changed? # => true
|
57
|
+
# person.name_changed?(from: "Uncle Bob", to: "Bob") # => true
|
57
58
|
# person.name_was # => "Uncle Bob"
|
58
59
|
# person.name_change # => ["Uncle Bob", "Bob"]
|
59
60
|
# person.name = 'Bill'
|
@@ -135,7 +136,7 @@ module ActiveModel
|
|
135
136
|
# person.save
|
136
137
|
# person.previous_changes # => {"name" => ["bob", "robert"]}
|
137
138
|
def previous_changes
|
138
|
-
@previously_changed ||=
|
139
|
+
@previously_changed ||= ActiveSupport::HashWithIndifferentAccess.new
|
139
140
|
end
|
140
141
|
|
141
142
|
# Returns a hash of the attributes with unsaved changes indicating their original
|
@@ -149,8 +150,11 @@ module ActiveModel
|
|
149
150
|
end
|
150
151
|
|
151
152
|
# Handle <tt>*_changed?</tt> for +method_missing+.
|
152
|
-
def attribute_changed?(attr)
|
153
|
-
changed_attributes.include?(attr)
|
153
|
+
def attribute_changed?(attr, options = {}) #:nodoc:
|
154
|
+
result = changed_attributes.include?(attr)
|
155
|
+
result &&= options[:to] == __send__(attr) if options.key?(:to)
|
156
|
+
result &&= options[:from] == changed_attributes[attr] if options.key?(:from)
|
157
|
+
result
|
154
158
|
end
|
155
159
|
|
156
160
|
# Handle <tt>*_was</tt> for +method_missing+.
|
@@ -163,13 +167,13 @@ module ActiveModel
|
|
163
167
|
# Removes current changes and makes them accessible through +previous_changes+.
|
164
168
|
def changes_applied
|
165
169
|
@previously_changed = changes
|
166
|
-
@changed_attributes =
|
170
|
+
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
|
167
171
|
end
|
168
172
|
|
169
173
|
# Removes all dirty data: current changes and previous changes
|
170
174
|
def reset_changes
|
171
|
-
@previously_changed =
|
172
|
-
@changed_attributes =
|
175
|
+
@previously_changed = ActiveSupport::HashWithIndifferentAccess.new
|
176
|
+
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
|
173
177
|
end
|
174
178
|
|
175
179
|
# Handle <tt>*_change</tt> for +method_missing+.
|
data/lib/active_model/errors.rb
CHANGED
@@ -7,7 +7,7 @@ module ActiveModel
|
|
7
7
|
# == Active \Model \Errors
|
8
8
|
#
|
9
9
|
# Provides a modified +Hash+ that you can include in your object
|
10
|
-
# for handling error messages and interacting with Action
|
10
|
+
# for handling error messages and interacting with Action View helpers.
|
11
11
|
#
|
12
12
|
# A minimal implementation could be:
|
13
13
|
#
|
@@ -23,7 +23,7 @@ module ActiveModel
|
|
23
23
|
# attr_reader :errors
|
24
24
|
#
|
25
25
|
# def validate!
|
26
|
-
# errors.add(:name, "
|
26
|
+
# errors.add(:name, "cannot be nil") if name == nil
|
27
27
|
# end
|
28
28
|
#
|
29
29
|
# # The following methods are needed to be minimally implemented
|
@@ -51,8 +51,8 @@ module ActiveModel
|
|
51
51
|
# The above allows you to do:
|
52
52
|
#
|
53
53
|
# person = Person.new
|
54
|
-
# person.validate! # => ["
|
55
|
-
# person.errors.full_messages # => ["name
|
54
|
+
# person.validate! # => ["cannot be nil"]
|
55
|
+
# person.errors.full_messages # => ["name cannot be nil"]
|
56
56
|
# # etc..
|
57
57
|
class Errors
|
58
58
|
include Enumerable
|
@@ -80,7 +80,7 @@ module ActiveModel
|
|
80
80
|
|
81
81
|
# Clear the error messages.
|
82
82
|
#
|
83
|
-
# person.errors.full_messages # => ["name
|
83
|
+
# person.errors.full_messages # => ["name cannot be nil"]
|
84
84
|
# person.errors.clear
|
85
85
|
# person.errors.full_messages # => []
|
86
86
|
def clear
|
@@ -90,19 +90,19 @@ module ActiveModel
|
|
90
90
|
# Returns +true+ if the error messages include an error for the given key
|
91
91
|
# +attribute+, +false+ otherwise.
|
92
92
|
#
|
93
|
-
# person.errors.messages # => {:name=>["
|
93
|
+
# person.errors.messages # => {:name=>["cannot be nil"]}
|
94
94
|
# person.errors.include?(:name) # => true
|
95
95
|
# person.errors.include?(:age) # => false
|
96
96
|
def include?(attribute)
|
97
|
-
|
97
|
+
messages[attribute].present?
|
98
98
|
end
|
99
99
|
# aliases include?
|
100
100
|
alias :has_key? :include?
|
101
101
|
|
102
102
|
# Get messages for +key+.
|
103
103
|
#
|
104
|
-
# person.errors.messages # => {:name=>["
|
105
|
-
# person.errors.get(:name) # => ["
|
104
|
+
# person.errors.messages # => {:name=>["cannot be nil"]}
|
105
|
+
# person.errors.get(:name) # => ["cannot be nil"]
|
106
106
|
# person.errors.get(:age) # => nil
|
107
107
|
def get(key)
|
108
108
|
messages[key]
|
@@ -110,7 +110,7 @@ module ActiveModel
|
|
110
110
|
|
111
111
|
# Set messages for +key+ to +value+.
|
112
112
|
#
|
113
|
-
# person.errors.get(:name) # => ["
|
113
|
+
# person.errors.get(:name) # => ["cannot be nil"]
|
114
114
|
# person.errors.set(:name, ["can't be nil"])
|
115
115
|
# person.errors.get(:name) # => ["can't be nil"]
|
116
116
|
def set(key, value)
|
@@ -119,8 +119,8 @@ module ActiveModel
|
|
119
119
|
|
120
120
|
# Delete messages for +key+. Returns the deleted messages.
|
121
121
|
#
|
122
|
-
# person.errors.get(:name) # => ["
|
123
|
-
# person.errors.delete(:name) # => ["
|
122
|
+
# person.errors.get(:name) # => ["cannot be nil"]
|
123
|
+
# person.errors.delete(:name) # => ["cannot be nil"]
|
124
124
|
# person.errors.get(:name) # => nil
|
125
125
|
def delete(key)
|
126
126
|
messages.delete(key)
|
@@ -129,8 +129,8 @@ module ActiveModel
|
|
129
129
|
# When passed a symbol or a name of a method, returns an array of errors
|
130
130
|
# for the method.
|
131
131
|
#
|
132
|
-
# person.errors[:name] # => ["
|
133
|
-
# person.errors['name'] # => ["
|
132
|
+
# person.errors[:name] # => ["cannot be nil"]
|
133
|
+
# person.errors['name'] # => ["cannot be nil"]
|
134
134
|
def [](attribute)
|
135
135
|
get(attribute.to_sym) || set(attribute.to_sym, [])
|
136
136
|
end
|
@@ -175,15 +175,15 @@ module ActiveModel
|
|
175
175
|
|
176
176
|
# Returns all message values.
|
177
177
|
#
|
178
|
-
# person.errors.messages # => {:name=>["
|
179
|
-
# person.errors.values # => [["
|
178
|
+
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
|
179
|
+
# person.errors.values # => [["cannot be nil", "must be specified"]]
|
180
180
|
def values
|
181
181
|
messages.values
|
182
182
|
end
|
183
183
|
|
184
184
|
# Returns all message keys.
|
185
185
|
#
|
186
|
-
# person.errors.messages # => {:name=>["
|
186
|
+
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
|
187
187
|
# person.errors.keys # => [:name]
|
188
188
|
def keys
|
189
189
|
messages.keys
|
@@ -211,7 +211,7 @@ module ActiveModel
|
|
211
211
|
# Returns +true+ if no errors are found, +false+ otherwise.
|
212
212
|
# If the error message is a string it can be empty.
|
213
213
|
#
|
214
|
-
# person.errors.full_messages # => ["name
|
214
|
+
# person.errors.full_messages # => ["name cannot be nil"]
|
215
215
|
# person.errors.empty? # => false
|
216
216
|
def empty?
|
217
217
|
all? { |k, v| v && v.empty? && !v.is_a?(String) }
|
@@ -238,8 +238,8 @@ module ActiveModel
|
|
238
238
|
# object. You can pass the <tt>:full_messages</tt> option. This determines
|
239
239
|
# if the json object should contain full messages or not (false by default).
|
240
240
|
#
|
241
|
-
# person.errors.as_json # => {:name=>["
|
242
|
-
# person.errors.as_json(full_messages: true) # => {:name=>["name
|
241
|
+
# person.errors.as_json # => {:name=>["cannot be nil"]}
|
242
|
+
# person.errors.as_json(full_messages: true) # => {:name=>["name cannot be nil"]}
|
243
243
|
def as_json(options=nil)
|
244
244
|
to_hash(options && options[:full_messages])
|
245
245
|
end
|
@@ -247,8 +247,8 @@ module ActiveModel
|
|
247
247
|
# Returns a Hash of attributes with their error messages. If +full_messages+
|
248
248
|
# is +true+, it will contain full messages (see +full_message+).
|
249
249
|
#
|
250
|
-
# person.errors.to_hash # => {:name=>["
|
251
|
-
# person.errors.to_hash(true) # => {:name=>["name
|
250
|
+
# person.errors.to_hash # => {:name=>["cannot be nil"]}
|
251
|
+
# person.errors.to_hash(true) # => {:name=>["name cannot be nil"]}
|
252
252
|
def to_hash(full_messages = false)
|
253
253
|
if full_messages
|
254
254
|
messages = {}
|
@@ -279,7 +279,7 @@ module ActiveModel
|
|
279
279
|
# If +message+ is a proc, it will be called, allowing for things like
|
280
280
|
# <tt>Time.now</tt> to be used within an error.
|
281
281
|
#
|
282
|
-
# If the <tt>:strict</tt> option is set to true will raise
|
282
|
+
# If the <tt>:strict</tt> option is set to +true+, it will raise
|
283
283
|
# ActiveModel::StrictValidationFailed instead of adding the error.
|
284
284
|
# <tt>:strict</tt> option can also be set to any other exception.
|
285
285
|
#
|
data/lib/active_model/lint.rb
CHANGED
@@ -13,7 +13,7 @@ module ActiveModel
|
|
13
13
|
#
|
14
14
|
# These tests do not attempt to determine the semantic correctness of the
|
15
15
|
# returned values. For instance, you could implement <tt>valid?</tt> to
|
16
|
-
# always return true
|
16
|
+
# always return +true+, and the tests would pass. It is up to you to ensure
|
17
17
|
# that the values are semantically meaningful.
|
18
18
|
#
|
19
19
|
# Objects you pass in are expected to return a compliant object from a call
|
data/lib/active_model/model.rb
CHANGED
@@ -9,7 +9,7 @@ module ActiveModel
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
# Adds methods to set and authenticate against a BCrypt password.
|
12
|
-
# This mechanism requires you to have a password_digest attribute.
|
12
|
+
# This mechanism requires you to have a +password_digest+ attribute.
|
13
13
|
#
|
14
14
|
# Validations for presence of password on create, confirmation of password
|
15
15
|
# (using a +password_confirmation+ attribute) are automatically added. If
|
@@ -57,11 +57,15 @@ module ActiveModel
|
|
57
57
|
include InstanceMethodsOnActivation
|
58
58
|
|
59
59
|
if options.fetch(:validations, true)
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
# This ensures the model has a password by checking whether the password_digest
|
61
|
+
# is present, so that this works with both new and existing records. However,
|
62
|
+
# when there is an error, the message is added to the password attribute instead
|
63
|
+
# so that the error message will make sense to the end-user.
|
64
|
+
validate do |record|
|
65
|
+
record.errors.add(:password, :blank) unless record.password_digest.present?
|
66
|
+
end
|
63
67
|
|
64
|
-
|
68
|
+
validates_confirmation_of :password, if: ->{ password.present? }
|
65
69
|
end
|
66
70
|
|
67
71
|
if respond_to?(:attributes_protected_by_default)
|
@@ -100,7 +104,9 @@ module ActiveModel
|
|
100
104
|
# user.password = 'mUc3m00RsqyRe'
|
101
105
|
# user.password_digest # => "$2a$10$4LEA7r4YmNHtvlAvHhsYAeZmk/xeUVtMTYqwIvYY76EW5GUqDiP4."
|
102
106
|
def password=(unencrypted_password)
|
103
|
-
|
107
|
+
if unencrypted_password.nil?
|
108
|
+
self.password_digest = nil
|
109
|
+
elsif unencrypted_password.present?
|
104
110
|
@password = unencrypted_password
|
105
111
|
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
|
106
112
|
self.password_digest = BCrypt::Password.create(unencrypted_password, cost: cost)
|
@@ -110,12 +116,6 @@ module ActiveModel
|
|
110
116
|
def password_confirmation=(unencrypted_password)
|
111
117
|
@password_confirmation = unencrypted_password
|
112
118
|
end
|
113
|
-
|
114
|
-
private
|
115
|
-
|
116
|
-
def should_confirm_password?
|
117
|
-
password_confirmation && password.present?
|
118
|
-
end
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -4,7 +4,7 @@ require 'active_support/core_ext/hash/except'
|
|
4
4
|
|
5
5
|
module ActiveModel
|
6
6
|
|
7
|
-
# == Active \Model Validations
|
7
|
+
# == Active \Model \Validations
|
8
8
|
#
|
9
9
|
# Provides a full validation framework to your objects.
|
10
10
|
#
|
@@ -66,8 +66,10 @@ module ActiveModel
|
|
66
66
|
# end
|
67
67
|
#
|
68
68
|
# Options:
|
69
|
-
# * <tt>:on</tt> - Specifies the
|
70
|
-
#
|
69
|
+
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
70
|
+
# You can pass a symbol or an array of symbols.
|
71
|
+
# (e.g. <tt>on: :create</tt> or <tt>on: :custom_validation_context</tt> or
|
72
|
+
# <tt>on: [:create, :custom_validation_context]</tt>)
|
71
73
|
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
|
72
74
|
# * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
|
73
75
|
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
@@ -124,10 +126,10 @@ module ActiveModel
|
|
124
126
|
# end
|
125
127
|
#
|
126
128
|
# Options:
|
127
|
-
# * <tt>:on</tt> - Specifies the
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
129
|
+
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
130
|
+
# You can pass a symbol or an array of symbols.
|
131
|
+
# (e.g. <tt>on: :create</tt> or <tt>on: :custom_validation_context</tt> or
|
132
|
+
# <tt>on: [:create, :custom_validation_context]</tt>)
|
131
133
|
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
132
134
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
133
135
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
@@ -143,7 +145,7 @@ module ActiveModel
|
|
143
145
|
options = options.dup
|
144
146
|
options[:if] = Array(options[:if])
|
145
147
|
options[:if].unshift lambda { |o|
|
146
|
-
|
148
|
+
Array(options[:on]).include?(o.validation_context)
|
147
149
|
}
|
148
150
|
end
|
149
151
|
args << options
|
@@ -199,12 +201,12 @@ module ActiveModel
|
|
199
201
|
# # #<StrictValidator:0x007fbff3204a30 @options={strict:true}>
|
200
202
|
# # ]
|
201
203
|
#
|
202
|
-
# If one runs Person.clear_validators
|
204
|
+
# If one runs <tt>Person.clear_validators!</tt> and then checks to see what
|
203
205
|
# validators this class has, you would obtain:
|
204
206
|
#
|
205
207
|
# Person.validators # => []
|
206
208
|
#
|
207
|
-
# Also, the callback set by
|
209
|
+
# Also, the callback set by <tt>validate :cannot_be_robot</tt> will be erased
|
208
210
|
# so that:
|
209
211
|
#
|
210
212
|
# Person._validate_callbacks.empty? # => true
|
@@ -21,7 +21,7 @@ module ActiveModel
|
|
21
21
|
# * <tt>:message</tt> - A custom error message (default is: "must be blank").
|
22
22
|
#
|
23
23
|
# There is also a list of default options supported by every validator:
|
24
|
-
# +:if+, +:unless+, +:on
|
24
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
25
25
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
26
26
|
def validates_absence_of(*attr_names)
|
27
27
|
validates_with AbsenceValidator, _merge_attributes(attr_names)
|
@@ -38,8 +38,6 @@ module ActiveModel
|
|
38
38
|
# Configuration options:
|
39
39
|
# * <tt>:message</tt> - A custom error message (default is: "must be
|
40
40
|
# accepted").
|
41
|
-
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default
|
42
|
-
# is +true+).
|
43
41
|
# * <tt>:accept</tt> - Specifies value that is considered accepted.
|
44
42
|
# The default value is a string "1", which makes it easy to relate to
|
45
43
|
# an HTML checkbox. This should be set to +true+ if you are validating
|
@@ -47,8 +45,8 @@ module ActiveModel
|
|
47
45
|
# before validation.
|
48
46
|
#
|
49
47
|
# There is also a list of default options supported by every validator:
|
50
|
-
# +:if+, +:unless+, +:on
|
51
|
-
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
48
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
49
|
+
# See <tt>ActiveModel::Validation#validates</tt> for more information.
|
52
50
|
def validates_acceptance_of(*attr_names)
|
53
51
|
validates_with AcceptanceValidator, _merge_attributes(attr_names)
|
54
52
|
end
|
@@ -57,7 +57,7 @@ module ActiveModel
|
|
57
57
|
# confirmation").
|
58
58
|
#
|
59
59
|
# There is also a list of default options supported by every validator:
|
60
|
-
# +:if+, +:unless+, +:on
|
60
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
61
61
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
62
62
|
def validates_confirmation_of(*attr_names)
|
63
63
|
validates_with ConfirmationValidator, _merge_attributes(attr_names)
|
@@ -34,13 +34,9 @@ module ActiveModel
|
|
34
34
|
# <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>.
|
35
35
|
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
|
36
36
|
# reserved").
|
37
|
-
# * <tt>:allow_nil</tt> - If set to true, skips this validation if the
|
38
|
-
# attribute is +nil+ (default is +false+).
|
39
|
-
# * <tt>:allow_blank</tt> - If set to true, skips this validation if the
|
40
|
-
# attribute is blank(default is +false+).
|
41
37
|
#
|
42
38
|
# There is also a list of default options supported by every validator:
|
43
|
-
# +:if+, +:unless+, +:on
|
39
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
44
40
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
45
41
|
def validates_exclusion_of(*attr_names)
|
46
42
|
validates_with ExclusionValidator, _merge_attributes(attr_names)
|
@@ -91,10 +91,6 @@ module ActiveModel
|
|
91
91
|
#
|
92
92
|
# Configuration options:
|
93
93
|
# * <tt>:message</tt> - A custom error message (default is: "is invalid").
|
94
|
-
# * <tt>:allow_nil</tt> - If set to true, skips this validation if the
|
95
|
-
# attribute is +nil+ (default is +false+).
|
96
|
-
# * <tt>:allow_blank</tt> - If set to true, skips this validation if the
|
97
|
-
# attribute is blank (default is +false+).
|
98
94
|
# * <tt>:with</tt> - Regular expression that if the attribute matches will
|
99
95
|
# result in a successful validation. This can be provided as a proc or
|
100
96
|
# lambda returning regular expression which will be called at runtime.
|
@@ -107,7 +103,7 @@ module ActiveModel
|
|
107
103
|
# beginning or end of the string. These anchors are <tt>^</tt> and <tt>$</tt>.
|
108
104
|
#
|
109
105
|
# There is also a list of default options supported by every validator:
|
110
|
-
# +:if+, +:unless+, +:on
|
106
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
111
107
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
112
108
|
def validates_format_of(*attr_names)
|
113
109
|
validates_with FormatValidator, _merge_attributes(attr_names)
|
@@ -29,17 +29,14 @@ module ActiveModel
|
|
29
29
|
# * <tt>:in</tt> - An enumerable object of available items. This can be
|
30
30
|
# supplied as a proc, lambda or symbol which returns an enumerable. If the
|
31
31
|
# enumerable is a numerical range the test is performed with <tt>Range#cover?</tt>,
|
32
|
-
# otherwise with <tt>include?</tt>.
|
32
|
+
# otherwise with <tt>include?</tt>. When using a proc or lambda the instance
|
33
|
+
# under validation is passed as an argument.
|
33
34
|
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
34
35
|
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
|
35
36
|
# not included in the list").
|
36
|
-
# * <tt>:allow_nil</tt> - If set to +true+, skips this validation if the
|
37
|
-
# attribute is +nil+ (default is +false+).
|
38
|
-
# * <tt>:allow_blank</tt> - If set to +true+, skips this validation if the
|
39
|
-
# attribute is blank (default is +false+).
|
40
37
|
#
|
41
38
|
# There is also a list of default options supported by every validator:
|
42
|
-
# +:if+, +:unless+, +:on
|
39
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
43
40
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
44
41
|
def validates_inclusion_of(*attr_names)
|
45
42
|
validates_with InclusionValidator, _merge_attributes(attr_names)
|
@@ -110,7 +110,7 @@ module ActiveModel
|
|
110
110
|
# * <tt>:even</tt> - Specifies the value must be an even number.
|
111
111
|
#
|
112
112
|
# There is also a list of default options supported by every validator:
|
113
|
-
# +:if+, +:unless+, +:on
|
113
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
|
114
114
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
115
115
|
#
|
116
116
|
# The following checks can also be supplied with a proc or a symbol which
|
@@ -29,7 +29,7 @@ module ActiveModel
|
|
29
29
|
# * <tt>:message</tt> - A custom error message (default is: "can't be blank").
|
30
30
|
#
|
31
31
|
# There is also a list of default options supported by every validator:
|
32
|
-
# +:if+, +:unless+, +:on
|
32
|
+
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
33
33
|
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
34
34
|
def validates_presence_of(*attr_names)
|
35
35
|
validates_with PresenceValidator, _merge_attributes(attr_names)
|
@@ -83,7 +83,9 @@ module ActiveModel
|
|
83
83
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
84
84
|
# method, proc or string should return or evaluate to a +true+ or
|
85
85
|
# +false+ value.
|
86
|
-
# * <tt>:
|
86
|
+
# * <tt>:allow_nil</tt> - Skip validation if the attribute is +nil+.
|
87
|
+
# * <tt>:allow_blank</tt> - Skip validation if the attribute is blank.
|
88
|
+
# * <tt>:strict</tt> - If the <tt>:strict</tt> option is set to true
|
87
89
|
# will raise ActiveModel::StrictValidationFailed instead of adding the error.
|
88
90
|
# <tt>:strict</tt> option can also be set to any other exception.
|
89
91
|
#
|
data/lib/active_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.0.
|
4
|
+
version: 4.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1.0.
|
19
|
+
version: 4.1.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.1.0.
|
26
|
+
version: 4.1.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: builder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|