2012-03-08 20:52:17 +00:00
## Rails 4.0.0 (unreleased) ##
2012-08-12 20:38:22 +00:00
* Changed inclusion and exclusion validators to accept a symbol for `:in` option.
This allows to use dynamic inclusion/exclusion values using methods, besides the current lambda/proc support.
*Gabriel Sobrinho*
2012-08-16 19:59:04 +00:00
* `AM::Validation#validates` ability to pass custom exception to `:strict` option.
*Bogdan Gusiev*
* Changed `ActiveModel::Serializers::Xml::Serializer#add_associations` to by default
propagate `:skip_types, :dasherize, :camelize` keys to included associations.
It can be overriden on each association by explicitly specifying the option on one
or more associations
*Anthony Alberto*
2012-07-27 19:13:05 +00:00
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 06:11:39 +00:00
* Changed `AM::Serializers::JSON.include_root_in_json' default value to false.
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*
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 13:39:09 +00:00
* Passing false hash values to `validates` will no longer enable the corresponding validators *Steve Purcell*
2012-04-24 01:30:24 +00:00
* `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute` *Brian Cardarella*
2012-03-03 04:20:17 +00:00
* Added ActiveModel::Model, a mixin to make Ruby objects work with AP out of box *Guillermo Iguaran*
2012-02-17 10:12:10 +00:00
* `AM::Errors#to_json` : support `:full_messages` parameter *Bogdan Gusiev*
2012-02-07 22:10:14 +00:00
* Trim down Active Model API by removing `valid?` and `errors.full_messages` *José Valim*
2012-06-07 22:08:51 +00: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-08-28 19:15:12 +00:00
Please check [3-2-stable ](https://github.com/rails/rails/blob/3-2-stable/activemodel/CHANGELOG.md ) for previous changes.