2013-02-26 11:45:20 -05:00
|
|
|
## Rails 4.0.0 (unreleased) ##
|
|
|
|
|
2013-03-04 12:56:05 -05:00
|
|
|
* `has_secure_password` does not fail the confirmation validation
|
|
|
|
when assigning empty String to `password` and `password_confirmation`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2013-03-09 12:57:10 -05:00
|
|
|
# Given User has_secure_password.
|
2013-03-04 12:56:05 -05:00
|
|
|
@user.password = ""
|
|
|
|
@user.password_confirmation = ""
|
|
|
|
@user.valid?(:update) # used to be false
|
|
|
|
|
2013-03-09 12:57:10 -05:00
|
|
|
*Yves Senn*
|
|
|
|
|
2013-03-04 12:50:56 -05:00
|
|
|
* `validates_confirmation_of` does not override writer methods for
|
|
|
|
the confirmation attribute if no reader is defined.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
class Blog
|
2013-03-09 12:57:10 -05:00
|
|
|
def title=(new_title)
|
|
|
|
@title = new_title.downcase
|
|
|
|
end
|
2013-03-04 12:50:56 -05:00
|
|
|
|
2013-03-09 12:57:10 -05:00
|
|
|
# previously this would override the setter above.
|
|
|
|
validates_confirmation_of :title
|
2013-03-04 12:50:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
*Yves Senn*
|
2013-02-26 11:45:20 -05:00
|
|
|
|
2013-02-25 09:31:50 -05:00
|
|
|
## Rails 4.0.0.beta1 (February 25, 2013) ##
|
2012-12-19 20:08:34 -05:00
|
|
|
|
2012-07-25 11:07:05 -04:00
|
|
|
* Add `ActiveModel::Validations::AbsenceValidator`, a validator to check the
|
|
|
|
absence of attributes.
|
|
|
|
|
2012-12-19 20:03:32 -05:00
|
|
|
class Person
|
|
|
|
include ActiveModel::Validations
|
|
|
|
|
|
|
|
attr_accessor :first_name
|
2012-07-25 11:07:05 -04:00
|
|
|
validates_absence_of :first_name
|
|
|
|
end
|
|
|
|
|
|
|
|
person = Person.new
|
|
|
|
person.first_name = "John"
|
|
|
|
person.valid?
|
2012-12-19 20:03:32 -05:00
|
|
|
# => false
|
|
|
|
person.errors.messages
|
|
|
|
# => {:first_name=>["must be blank"]}
|
2012-07-25 11:07:05 -04:00
|
|
|
|
2012-12-19 20:03:32 -05:00
|
|
|
*Roberto Vasquez Angel*
|
2012-07-25 11:07:05 -04:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* `[attribute]_changed?` now returns `false` after a call to `reset_[attribute]!`.
|
2012-12-01 12:29:49 -05:00
|
|
|
|
|
|
|
*Renato Mascarenhas*
|
|
|
|
|
2012-11-28 21:26:32 -05:00
|
|
|
* Observers was extracted from Active Model as `rails-observers` gem.
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* Specify type of singular association during serialization.
|
2012-10-05 17:07:39 -04:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
*Steve Klabnik*
|
|
|
|
|
|
|
|
* Fixed length validator to correctly handle `nil`. Fixes #7180.
|
2012-08-07 07:39:21 -04:00
|
|
|
|
|
|
|
*Michal Zima*
|
|
|
|
|
2012-11-25 11:08:57 -05:00
|
|
|
* Removed dispensable `require` statements. Make sure to require `active_model` before requiring
|
|
|
|
individual parts of the framework.
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-12-14 17:16:59 -05:00
|
|
|
* Use BCrypt's `MIN_COST` in the test environment for speedier tests when using `has_secure_pasword`.
|
2012-11-14 10:42:54 -05:00
|
|
|
|
|
|
|
*Brian Cardarella + Jeremy Kemper + Trevor Turk*
|
|
|
|
|
2012-09-19 18:10:32 -04:00
|
|
|
* Add `ActiveModel::ForbiddenAttributesProtection`, a simple module to
|
|
|
|
protect attributes from mass assignment when non-permitted attributes are passed.
|
|
|
|
|
|
|
|
*DHH + Guillermo Iguaran*
|
|
|
|
|
|
|
|
* `ActiveModel::MassAssignmentSecurity` has been extracted from Active Model and the
|
|
|
|
`protected_attributes` gem should be added to Gemfile in order to use
|
|
|
|
`attr_accessible` and `attr_protected` macros in your models.
|
|
|
|
|
|
|
|
*Guillermo Iguaran*
|
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* Due to a change in builder, `nil` and empty strings now generate
|
2012-09-07 12:08:30 -04:00
|
|
|
closed tags, so instead of this:
|
|
|
|
|
|
|
|
<pseudonyms nil=\"true\"></pseudonyms>
|
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
it generates this:
|
2012-09-07 12:08:30 -04:00
|
|
|
|
|
|
|
<pseudonyms nil=\"true\"/>
|
|
|
|
|
|
|
|
*Carlos Antonio da Silva*
|
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* Inclusion/exclusion validators accept a method name passed as a symbol to the
|
|
|
|
`:in` option.
|
2012-08-12 16:38:22 -04:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
This allows to use dynamic inclusion/exclusion values using methods, besides
|
|
|
|
the current lambda/proc support.
|
2012-08-12 16:38:22 -04:00
|
|
|
|
|
|
|
*Gabriel Sobrinho*
|
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* `ActiveModel::Validation#validates` ability to pass custom exception to the
|
|
|
|
`:strict` option.
|
2012-08-16 15:59:04 -04:00
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
|
|
|
|
|
|
|
* Changed `ActiveModel::Serializers::Xml::Serializer#add_associations` to by default
|
|
|
|
propagate `:skip_types, :dasherize, :camelize` keys to included associations.
|
2013-03-15 02:25:03 -04:00
|
|
|
It can be overridden on each association by explicitly specifying the option on one
|
2012-08-16 15:59:04 -04:00
|
|
|
or more associations
|
|
|
|
|
|
|
|
*Anthony Alberto*
|
2012-07-27 15:13:05 -04:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* Changed `ActiveModel::Serializers::JSON.include_root_in_json` default value to false.
|
change AMS::JSON.include_root_in_json default value to false
Changes:
* Update `include_root_in_json` default value to false for default value
to false for `ActiveModel::Serializers::JSON`.
* Remove unnecessary change to include_root_in_json option in
wrap_parameters template.
* Update `as_json` documentation.
* Fix JSONSerialization tests.
Problem:
It's confusing that AM serializers behave differently from AR,
even when AR objects include AM serializers module.
class User < ActiveRecord::Base; end
class Person
include ActiveModel::Model
include ActiveModel::AttributeMethods
include ActiveModel::Serializers::JSON
attr_accessor :name, :age
def attributes
instance_values
end
end
user.as_json
=> {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
# root is not included
person.as_json
=> {"person"=>{"name"=>"Francesco", "age"=>22}}
# root is included
ActiveRecord::Base.include_root_in_json
=> false
Person.include_root_in_json
=> true
# different default values for include_root_in_json
Proposal:
Change the default value of AM serializers to false, update
the misleading documentation and remove unnecessary change
to false of include_root_in_json option with AR objects.
class User < ActiveRecord::Base; end
class Person
include ActiveModel::Model
include ActiveModel::AttributeMethods
include ActiveModel::Serializers::JSON
attr_accessor :name, :age
def attributes
instance_values
end
end
user.as_json
=> {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
# root is not included
person.as_json
=> {"name"=>"Francesco", "age"=>22}
# root is not included
ActiveRecord::Base.include_root_in_json
=> false
Person.include_root_in_json
=> false
# same behaviour, more consistent
Fixes #6578.
2012-06-06 02:11:39 -04:00
|
|
|
Now, AM Serializers and AR objects have the same default behaviour. Fixes #6578.
|
|
|
|
|
|
|
|
class User < ActiveRecord::Base; end
|
|
|
|
|
|
|
|
class Person
|
|
|
|
include ActiveModel::Model
|
|
|
|
include ActiveModel::AttributeMethods
|
|
|
|
include ActiveModel::Serializers::JSON
|
|
|
|
|
|
|
|
attr_accessor :name, :age
|
|
|
|
|
|
|
|
def attributes
|
|
|
|
instance_values
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
user.as_json
|
|
|
|
=> {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
|
|
|
|
# root is not included
|
|
|
|
|
|
|
|
person.as_json
|
|
|
|
=> {"name"=>"Francesco", "age"=>22}
|
|
|
|
# root is not included
|
|
|
|
|
|
|
|
*Francesco Rodriguez*
|
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* Passing false hash values to `validates` will no longer enable the corresponding validators.
|
|
|
|
|
|
|
|
*Steve Purcell*
|
|
|
|
|
|
|
|
* `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute`.
|
|
|
|
|
|
|
|
*Brian Cardarella*
|
|
|
|
|
|
|
|
* Added `ActiveModel::Model`, a mixin to make Ruby objects work with AP out of box.
|
Don't enable validations when passing false hash values to ActiveModel.validates
Passing a falsey option value for a validator currently causes that validator to
be enabled, just like "true":
ActiveModel.validates :foo, :presence => false
This is rather counterintuitive, and makes it inconvenient to wrap `validates` in
methods which may conditionally enable different validators.
As an example, one is currently forced to write:
def has_slug(source_field, options={:unique => true})
slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
before_validation slugger
validations = { :presence => true, :slug => true }
if options[:unique]
validations[:uniqueness] = true
end
validates :slug, validations
end
because the following reasonable-looking alternative fails to work as expected:
def has_slug(source_field, options={:unique => true})
slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
before_validation slugger
validates :slug, :presence => true, :slug => true, :uniqueness => options[:unique]
end
(This commit includes a test, and all activemodel and activerecord tests pass as before.)
2012-05-28 09:39:09 -04:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
*Guillermo Iguaran*
|
|
|
|
|
|
|
|
* `AM::Errors#to_json`: support `:full_messages` parameter.
|
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
2012-04-23 21:30:24 -04:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* Trim down Active Model API by removing `valid?` and `errors.full_messages`.
|
2012-03-02 23:20:17 -05:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
*José Valim*
|
2012-02-17 05:12:10 -05:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
* When `^` or `$` are used in the regular expression provided to `validates_format_of`
|
|
|
|
and the `:multiline` option is not set to true, an exception will be raised. This is
|
|
|
|
to prevent security vulnerabilities when using `validates_format_of`. The problem is
|
|
|
|
described in detail in the Rails security guide.
|
2012-02-07 17:10:14 -05:00
|
|
|
|
2013-02-24 14:37:05 -05:00
|
|
|
*Jan Berdajs + Egor Homakov*
|
2012-06-07 18:08:51 -04:00
|
|
|
|
2012-08-28 15:15:12 -04:00
|
|
|
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activemodel/CHANGELOG.md) for previous changes.
|