activemodel 4.0.13 → 4.1.0.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6480d698a29a2bde39643553d36ef1017845079e
4
- data.tar.gz: 71864592fffd7b46b44ee17297db425e35d9c220
3
+ metadata.gz: 8ec99997b26ba6f42f0d52870e26c68b014b0ab2
4
+ data.tar.gz: 6d5a2a13605bfd0a34896e84e96aa36d96b702db
5
5
  SHA512:
6
- metadata.gz: a9ba2cb78d6dcb7c2fe7da280c12441a6ba6f0a5d0288e54816c2599d928f54b5a436fab7481e43d0d324e4194683a2086a3780520484e7040cde28ae8faacae
7
- data.tar.gz: 23d61ef3a44826c8f8cc38916a199e62d6b2d567b6ed7d2487dad93058e10e46804eae20ecff69b34852b784fc4c7a24afc6c7ce26a129d63f32d691f9c0364c
6
+ metadata.gz: c5275f490cc27d9bf4ba5b34378e7b61592aa0475826d6f69571ad2d4f76eb4966d50443f7342506c75b79c471c3c41fec24b829edd66bdc3c58dc217183f911
7
+ data.tar.gz: 13696e83d837d03bb99c0393f536fc35064aa08090b460c4adaa094c3d1854b8b54743bf54f95e0b3d9f8791c175c311fdcf51e093d72a644d44e62369d59ad7
data/CHANGELOG.md CHANGED
@@ -1,300 +1,39 @@
1
- ## Rails 4.0.13 (January 6, 2015) ##
2
-
3
- *No changes*
4
-
5
-
6
- ## Rails 4.0.12 (November 16, 2014) ##
7
-
8
- *No changes*
9
-
10
-
11
- ## Rails 4.0.11.1 (November 19, 2014) ##
12
-
13
- *No changes*
14
-
15
-
16
- ## Rails 4.0.11 (September 11, 2014) ##
17
-
18
- *No changes*
19
-
20
-
21
- ## Rails 4.0.10 (September 11, 2014) ##
22
-
23
- *No changes*
24
-
25
-
26
- ## Rails 4.0.9 (August 18, 2014) ##
27
-
28
- *No changes*
29
-
30
-
31
- ## Rails 4.0.8 (July 2, 2014) ##
32
-
33
- *No changes*
34
-
35
-
36
- ## Rails 4.0.7 (July 2, 2014) ##
37
-
38
- *No changes*
39
-
40
-
41
- ## Rails 4.0.6 (June 26, 2014) ##
42
-
43
- *No changes*
44
-
45
-
46
- ## Rails 4.0.5 (May 6, 2014) ##
47
-
48
- *No changes*
49
-
50
-
51
- ## Rails 4.0.4 (March 14, 2014) ##
52
-
53
- * `#to_param` returns `nil` if `#to_key` returns `nil`. Fixes #11399.
54
-
55
- *Yves Senn*
56
-
57
-
58
- ## Rails 4.0.3 (February 18, 2014) ##
1
+ * Fix `has_secure_password` to honor bcrypt-ruby's cost attribute.
59
2
 
60
- *No changes*
3
+ *T.J. Schuck*
61
4
 
5
+ * Updated the `ActiveModel::Dirty#changed_attributes` method to be indifferent between using
6
+ symbols and strings as keys.
62
7
 
63
- ## Rails 4.0.2 (December 02, 2013) ##
8
+ *William Myers*
64
9
 
65
- *No changes*
10
+ * Added new API methods `reset_changes` and `changes_applied` to `ActiveModel::Dirty`
11
+ that control changes state. Previsously you needed to update internal
12
+ instance variables, but now API methods are available.
66
13
 
14
+ *Bogdan Gusiev*
67
15
 
68
- ## Rails 4.0.1 (November 01, 2013) ##
16
+ * Fix has_secure_password. `password_confirmation` validations are triggered
17
+ even if no `password_confirmation` is set.
69
18
 
70
- * Fix `has_secure_password` to honor bcrypt-ruby's cost attribute.
71
-
72
- *T.J. Schuck*
19
+ *Vladimir Kiselev*
73
20
 
74
21
  * `inclusion` / `exclusion` validations with ranges will only use the faster
75
22
  `Range#cover` for numerical ranges, and the more accurate `Range#include?`
76
23
  for non-numerical ones.
77
24
 
78
25
  Fixes range validations like `:a..:f` that used to pass with values like `:be`.
79
-
80
26
  Fixes #10593.
81
27
 
82
28
  *Charles Bergeron*
83
29
 
84
-
85
- ## Rails 4.0.0 (June 25, 2013) ##
86
-
87
30
  * Fix regression in has_secure_password. When a password is set, but a
88
31
  confirmation is an empty string, it would incorrectly save.
89
32
 
90
33
  *Steve Klabnik* and *Phillip Calvin*
91
34
 
92
- * Add `ActiveModel::Errors#full_messages_for`, to return all the error messages
93
- for a given attribute.
94
-
95
- Example:
96
-
97
- class Person
98
- include ActiveModel::Validations
99
-
100
- attr_reader :name, :email
101
- validates_presence_of :name, :email
102
- end
103
-
104
- person = Person.new
105
- person.valid? # => false
106
- person.errors.full_messages_for(:name) # => ["Name can't be blank"]
107
-
108
- *Volodymyr Shatsky*
109
-
110
- * Added a method so that validations can be easily cleared on a model.
111
- For example:
112
-
113
- class Person
114
- include ActiveModel::Validations
115
-
116
- validates_uniqueness_of :first_name
117
- validate :cannot_be_robot
118
-
119
- def cannot_be_robot
120
- errors.add(:base, 'A person cannot be a robot') if person_is_robot
121
- end
122
- end
123
-
124
- Now, if someone runs `Person.clear_validators!`, then the following occurs:
125
-
126
- Person.validators # => []
127
- Person._validate_callbacks.empty? # => true
128
-
129
- *John Wang*
130
-
131
- * `has_secure_password` does not fail the confirmation validation
132
- when assigning empty String to `password` and `password_confirmation`.
133
- Fixes #9535.
134
-
135
- Example:
136
-
137
- # Given User has_secure_password.
138
- @user.password = ""
139
- @user.password_confirmation = ""
140
- @user.valid?(:update) # used to be false
141
-
142
- *Yves Senn*
143
-
144
- * `validates_confirmation_of` does not override writer methods for
145
- the confirmation attribute if no reader is defined.
146
-
147
- Example:
148
-
149
- class Blog
150
- def title=(new_title)
151
- @title = new_title.downcase
152
- end
153
-
154
- # previously this would override the setter above.
155
- validates_confirmation_of :title
156
- end
157
-
158
- *Yves Senn*
159
-
160
- * Add `ActiveModel::Validations::AbsenceValidator`, a validator to check the
161
- absence of attributes.
162
-
163
- class Person
164
- include ActiveModel::Validations
165
-
166
- attr_accessor :first_name
167
- validates_absence_of :first_name
168
- end
169
-
170
- person = Person.new
171
- person.first_name = "John"
172
- person.valid?
173
- # => false
174
- person.errors.messages
175
- # => {:first_name=>["must be blank"]}
176
-
177
- *Roberto Vasquez Angel*
178
-
179
- * `[attribute]_changed?` now returns `false` after a call to `reset_[attribute]!`.
180
-
181
- *Renato Mascarenhas*
182
-
183
- * Observers was extracted from Active Model as `rails-observers` gem.
184
-
185
- *Rafael Mendonça França*
186
-
187
- * Specify type of singular association during serialization.
188
-
189
- *Steve Klabnik*
190
-
191
- * Fixed length validator to correctly handle `nil`. Fixes #7180.
192
-
193
- *Michal Zima*
194
-
195
- * Removed dispensable `require` statements. Make sure to require `active_model` before requiring
196
- individual parts of the framework.
197
-
198
- *Yves Senn*
199
-
200
- * Use BCrypt's `MIN_COST` in the test environment for speedier tests when using `has_secure_password`.
201
-
202
- *Brian Cardarella + Jeremy Kemper + Trevor Turk*
203
-
204
- * Add `ActiveModel::ForbiddenAttributesProtection`, a simple module to
205
- protect attributes from mass assignment when non-permitted attributes are passed.
206
-
207
- *DHH + Guillermo Iguaran*
208
-
209
- * `ActiveModel::MassAssignmentSecurity` has been extracted from Active Model and the
210
- `protected_attributes` gem should be added to Gemfile in order to use
211
- `attr_accessible` and `attr_protected` macros in your models.
212
-
213
- *Guillermo Iguaran*
214
-
215
- * Due to a change in builder, `nil` and empty strings now generate
216
- closed tags, so instead of this:
217
-
218
- <pseudonyms nil=\"true\"></pseudonyms>
219
-
220
- it generates this:
221
-
222
- <pseudonyms nil=\"true\"/>
223
-
224
- *Carlos Antonio da Silva*
225
-
226
- * Inclusion/exclusion validators accept a method name passed as a symbol to the
227
- `:in` option.
228
-
229
- This allows to use dynamic inclusion/exclusion values using methods, besides
230
- the current lambda/proc support.
231
-
232
- *Gabriel Sobrinho*
233
-
234
- * `ActiveModel::Validation#validates` ability to pass custom exception to the
235
- `:strict` option.
236
-
237
- *Bogdan Gusiev*
238
-
239
- * Changed `ActiveModel::Serializers::Xml::Serializer#add_associations` to by default
240
- propagate `:skip_types, :dasherize, :camelize` keys to included associations.
241
- It can be overridden on each association by explicitly specifying the option on one
242
- or more associations
243
-
244
- *Anthony Alberto*
245
-
246
- * Changed `ActiveModel::Serializers::JSON.include_root_in_json` default value to false.
247
- Now, AM Serializers and AR objects have the same default behaviour. Fixes #6578.
248
-
249
- class User < ActiveRecord::Base; end
250
-
251
- class Person
252
- include ActiveModel::Model
253
- include ActiveModel::AttributeMethods
254
- include ActiveModel::Serializers::JSON
255
-
256
- attr_accessor :name, :age
257
-
258
- def attributes
259
- instance_values
260
- end
261
- end
262
-
263
- user.as_json
264
- => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
265
- # root is not included
266
-
267
- person.as_json
268
- => {"name"=>"Francesco", "age"=>22}
269
- # root is not included
270
-
271
- *Francesco Rodriguez*
272
-
273
- * Passing false hash values to `validates` will no longer enable the corresponding validators.
274
-
275
- *Steve Purcell*
276
-
277
- * `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute`.
278
-
279
- *Brian Cardarella*
280
-
281
- * Added `ActiveModel::Model`, a mixin to make Ruby objects work with AP out of box.
282
-
283
- *Guillermo Iguaran*
284
-
285
- * `AM::Errors#to_json`: support `:full_messages` parameter.
286
-
287
- *Bogdan Gusiev*
288
-
289
- * Trim down Active Model API by removing `valid?` and `errors.full_messages`.
290
-
291
- *José Valim*
292
-
293
- * When `^` or `$` are used in the regular expression provided to `validates_format_of`
294
- and the `:multiline` option is not set to true, an exception will be raised. This is
295
- to prevent security vulnerabilities when using `validates_format_of`. The problem is
296
- described in detail in the Rails security guide.
35
+ * Deprecate `Validator#setup`. This should be done manually now in the validator's constructor.
297
36
 
298
- *Jan Berdajs + Egor Homakov*
37
+ *Nick Sutterer*
299
38
 
300
- Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activemodel/CHANGELOG.md) for previous changes.
39
+ Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activemodel/CHANGELOG.md) for previous changes.
data/README.rdoc CHANGED
@@ -227,7 +227,7 @@ The latest version of Active Model can be installed with RubyGems:
227
227
 
228
228
  Source code can be downloaded as part of the Rails project on GitHub
229
229
 
230
- * https://github.com/rails/rails/tree/4-0-stable/activemodel
230
+ * https://github.com/rails/rails/tree/master/activemodel
231
231
 
232
232
 
233
233
  == License
data/lib/active_model.rb CHANGED
@@ -37,7 +37,6 @@ module ActiveModel
37
37
  autoload :ForbiddenAttributesProtection
38
38
  autoload :Lint
39
39
  autoload :Model
40
- autoload :DeprecatedMassAssignmentSecurity
41
40
  autoload :Name, 'active_model/naming'
42
41
  autoload :Naming
43
42
  autoload :SecurePassword
@@ -49,7 +48,6 @@ module ActiveModel
49
48
 
50
49
  eager_autoload do
51
50
  autoload :Errors
52
- autoload :StrictValidationFailed, 'active_model/errors'
53
51
  end
54
52
 
55
53
  module Serializers
@@ -61,9 +59,9 @@ module ActiveModel
61
59
  end
62
60
  end
63
61
 
64
- def self.eager_load!
62
+ def eager_load!
65
63
  super
66
- ActiveModel::Serializers.eager_load!
64
+ ActiveModel::Serializer.eager_load!
67
65
  end
68
66
  end
69
67
 
@@ -219,6 +219,16 @@ module ActiveModel
219
219
  end
220
220
  end
221
221
 
222
+ # Is +new_name+ an alias?
223
+ def attribute_alias?(new_name)
224
+ attribute_aliases.key? new_name.to_s
225
+ end
226
+
227
+ # Returns the original name for the alias +name+
228
+ def attribute_alias(name)
229
+ attribute_aliases[name.to_s]
230
+ end
231
+
222
232
  # Declares the attributes that should be prefixed and suffixed by
223
233
  # ActiveModel::AttributeMethods.
224
234
  #
@@ -323,7 +333,6 @@ module ActiveModel
323
333
  attribute_method_matchers_cache.clear
324
334
  end
325
335
 
326
- # Returns true if the attribute methods defined have been generated.
327
336
  def generated_attribute_methods #:nodoc:
328
337
  @generated_attribute_methods ||= Module.new {
329
338
  extend Mutex_m
@@ -340,13 +349,13 @@ module ActiveModel
340
349
  # invoked often in a typical rails, both of which invoke the method
341
350
  # +match_attribute_method?+. The latter method iterates through an
342
351
  # array doing regular expression matches, which results in a lot of
343
- # object creations. Most of the times it returns a +nil+ match. As the
352
+ # object creations. Most of the time it returns a +nil+ match. As the
344
353
  # match result is always the same given a +method_name+, this cache is
345
354
  # used to alleviate the GC, which ultimately also speeds up the app
346
355
  # significantly (in our case our test suite finishes 10% faster with
347
356
  # this cache).
348
357
  def attribute_method_matchers_cache #:nodoc:
349
- @attribute_method_matchers_cache ||= ThreadSafe::Cache.new(:initial_capacity => 4)
358
+ @attribute_method_matchers_cache ||= ThreadSafe::Cache.new(initial_capacity: 4)
350
359
  end
351
360
 
352
361
  def attribute_method_matcher(method_name) #:nodoc:
@@ -391,14 +400,6 @@ module ActiveModel
391
400
  AttributeMethodMatch = Struct.new(:target, :attr_name, :method_name)
392
401
 
393
402
  def initialize(options = {})
394
- if options[:prefix] == '' || options[:suffix] == ''
395
- message = "Specifying an empty prefix/suffix for an attribute method is no longer " \
396
- "necessary. If the un-prefixed/suffixed version of the method has not been " \
397
- "defined when `define_attribute_methods` is called, it will be defined " \
398
- "automatically."
399
- ActiveSupport::Deprecation.warn message
400
- end
401
-
402
403
  @prefix, @suffix = options.fetch(:prefix, ''), options.fetch(:suffix, '')
403
404
  @regex = /^(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})$/
404
405
  @method_missing_target = "#{@prefix}attribute#{@suffix}"
@@ -100,10 +100,10 @@ module ActiveModel
100
100
  def define_model_callbacks(*callbacks)
101
101
  options = callbacks.extract_options!
102
102
  options = {
103
- :terminator => "result == false",
104
- :skip_after_callbacks_if_terminated => true,
105
- :scope => [:kind, :name],
106
- :only => [:before, :around, :after]
103
+ terminator: ->(_,result) { result == false },
104
+ skip_after_callbacks_if_terminated: true,
105
+ scope: [:kind, :name],
106
+ only: [:before, :around, :after]
107
107
  }.merge!(options)
108
108
 
109
109
  types = Array(options.delete(:only))
@@ -120,30 +120,27 @@ module ActiveModel
120
120
  private
121
121
 
122
122
  def _define_before_model_callback(klass, callback) #:nodoc:
123
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
124
- def self.before_#{callback}(*args, &block)
125
- set_callback(:#{callback}, :before, *args, &block)
126
- end
127
- CALLBACK
123
+ klass.define_singleton_method("before_#{callback}") do |*args, &block|
124
+ set_callback(:"#{callback}", :before, *args, &block)
125
+ end
128
126
  end
129
127
 
130
128
  def _define_around_model_callback(klass, callback) #:nodoc:
131
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
132
- def self.around_#{callback}(*args, &block)
133
- set_callback(:#{callback}, :around, *args, &block)
134
- end
135
- CALLBACK
129
+ klass.define_singleton_method("around_#{callback}") do |*args, &block|
130
+ set_callback(:"#{callback}", :around, *args, &block)
131
+ end
136
132
  end
137
133
 
138
134
  def _define_after_model_callback(klass, callback) #:nodoc:
139
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
140
- def self.after_#{callback}(*args, &block)
141
- options = args.extract_options!
142
- options[:prepend] = true
143
- options[:if] = Array(options[:if]) << "value != false"
144
- set_callback(:#{callback}, :after, *(args << options), &block)
145
- end
146
- CALLBACK
135
+ klass.define_singleton_method("after_#{callback}") do |*args, &block|
136
+ options = args.extract_options!
137
+ options[:prepend] = true
138
+ conditional = ActiveSupport::Callbacks::Conditionals::Value.new { |v|
139
+ v != false
140
+ }
141
+ options[:if] = Array(options[:if]) << conditional
142
+ set_callback(:"#{callback}", :after, *(args << options), &block)
143
+ end
147
144
  end
148
145
  end
149
146
  end