diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/CHANGELOG.md | 25 | ||||
-rw-r--r-- | activemodel/lib/active_model/callbacks.rb | 11 | ||||
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 17 | ||||
-rwxr-xr-x[-rw-r--r--] | activemodel/lib/active_model/serializers/xml.rb | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | activemodel/test/cases/serializers/xml_serialization_test.rb | 38 |
5 files changed, 85 insertions, 10 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index b9966cb2fa..a8f470397b 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,6 +1,15 @@ ## Rails 4.0.0 (unreleased) ## -* `AM::Validation#validates` ability to pass custom exception to `:strict` option *Bogdan Gusiev* +* `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* * 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. @@ -41,10 +50,24 @@ * 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. + +## Rails 3.2.8 (Aug 9, 2012) ## + +* No changes. + + +## Rails 3.2.7 (Jul 26, 2012) ## + +* `validates_inclusion_of` and `validates_exclusion_of` now accept `:within` option as alias of `:in` as documented. + +* Fix the the backport of the object dup with the ruby 1.9.3p194. + + ## Rails 3.2.6 (Jun 12, 2012) ## * No changes. + ## Rails 3.2.5 (Jun 1, 2012) ## * No changes. diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb index e669113001..e442455a53 100644 --- a/activemodel/lib/active_model/callbacks.rb +++ b/activemodel/lib/active_model/callbacks.rb @@ -38,6 +38,17 @@ module ActiveModel # # Your code here # end # + # When defining an around callback remember to yield to the block, otherwise + # it won't be executed: + # + # around_create :log_status + # + # def log_status + # puts 'going to call the block...' + # yield + # puts 'block successfully called.' + # end + # # You can choose not to have all three callbacks by passing a hash to the # +define_model_callbacks+ method. # diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 7ba439fb3e..c0d93e5d53 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -298,14 +298,15 @@ module ActiveModel model_name_from_record_or_class(record_or_class).param_key end - private - def self.model_name_from_record_or_class(record_or_class) - (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name - end - - def self.convert_to_model(object) - object.respond_to?(:to_model) ? object.to_model : object + def self.model_name_from_record_or_class(record_or_class) #:nodoc: + if record_or_class.respond_to?(:model_name) + record_or_class.model_name + elsif record_or_class.respond_to?(:to_model) + record_or_class.to_model.class.model_name + else + record_or_class.class.model_name end + end + private_class_method :model_name_from_record_or_class end - end diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index 016d821fdf..cf742d0569 100644..100755 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -115,6 +115,10 @@ module ActiveModel merged_options = opts.merge(options.slice(:builder, :indent)) merged_options[:skip_instruct] = true + [:skip_types, :dasherize, :camelize].each do |key| + merged_options[key] = options[key] if merged_options[key].nil? && !options[key].nil? + end + if records.respond_to?(:to_ary) records = records.to_ary diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index a93323a3a8..8c5a3c5efd 100644..100755 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -28,7 +28,7 @@ class Address extend ActiveModel::Naming include ActiveModel::Serializers::Xml - attr_accessor :street, :city, :state, :zip + attr_accessor :street, :city, :state, :zip, :apt_number def attributes instance_values @@ -56,6 +56,7 @@ class XmlSerializationTest < ActiveModel::TestCase @contact.address.city = "Springfield" @contact.address.state = "CA" @contact.address.zip = 11111 + @contact.address.apt_number = 35 @contact.friends = [Contact.new, Contact.new] end @@ -222,4 +223,39 @@ class XmlSerializationTest < ActiveModel::TestCase assert_match %r{<friends>}, xml assert_match %r{<friend>}, xml end + + test "propagates skip-types option to included associations and attributes" do + xml = @contact.to_xml :skip_types => true, :include => :address, :indent => 0 + assert_match %r{<address>}, xml + assert_match %r{<apt-number>}, xml + end + + test "propagates camelize option to included associations and attributes" do + xml = @contact.to_xml :camelize => true, :include => :address, :indent => 0 + assert_match %r{<Address>}, xml + assert_match %r{<AptNumber type="integer">}, xml + end + + test "propagates dasherize option to included associations and attributes" do + xml = @contact.to_xml :dasherize => false, :include => :address, :indent => 0 + assert_match %r{<apt_number type="integer">}, xml + end + + test "don't propagate skip_types if skip_types is defined at the included association level" do + xml = @contact.to_xml :skip_types => true, :include => { :address => { :skip_types => false } }, :indent => 0 + assert_match %r{<address>}, xml + assert_match %r{<apt-number type="integer">}, xml + end + + test "don't propagate camelize if camelize is defined at the included association level" do + xml = @contact.to_xml :camelize => true, :include => { :address => { :camelize => false } }, :indent => 0 + assert_match %r{<address>}, xml + assert_match %r{<apt-number type="integer">}, xml + end + + test "don't propagate dasherize if dasherize is defined at the included association level" do + xml = @contact.to_xml :dasherize => false, :include => { :address => { :dasherize => true } }, :indent => 0 + assert_match %r{<address>}, xml + assert_match %r{<apt-number type="integer">}, xml + end end |