diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-26 11:21:05 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-26 11:21:05 -0700 |
commit | d341d166774dba12508abbfb848bcde49d3cdf07 (patch) | |
tree | e4e8bdf3c9eb58c779599ac2084de15cb8af0e14 | |
parent | 5083d70f6f0041fe7ee8b662ecc58db2c15580e3 (diff) | |
parent | 043b6243901aea2e7f604e1d4ce655cfe595ceb7 (diff) | |
download | rails-d341d166774dba12508abbfb848bcde49d3cdf07.tar.gz rails-d341d166774dba12508abbfb848bcde49d3cdf07.tar.bz2 rails-d341d166774dba12508abbfb848bcde49d3cdf07.zip |
Merge pull request #1344 from jmileham/serialization_includes
AR Serialization shouldn't fall back to base opts for includes
-rw-r--r-- | activerecord/lib/active_record/serialization.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/json_serialization_test.rb | 9 |
2 files changed, 11 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index be4354ce6a..e3185a9c5a 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -31,9 +31,6 @@ module ActiveRecord #:nodoc: def serializable_add_includes(options = {}) return unless include_associations = options.delete(:include) - base_only_or_except = { :except => options[:except], - :only => options[:only] } - include_has_options = include_associations.is_a?(Hash) associations = include_has_options ? include_associations.keys : Array.wrap(include_associations) @@ -46,9 +43,8 @@ module ActiveRecord #:nodoc: end if records - association_options = include_has_options ? include_associations[association] : base_only_or_except - opts = options.merge(association_options) - yield(association, records, opts) + association_options = include_has_options ? include_associations[association] : {} + yield(association, records, association_options) end end diff --git a/activerecord/test/cases/json_serialization_test.rb b/activerecord/test/cases/json_serialization_test.rb index 8664d63e8f..d9e350abc0 100644 --- a/activerecord/test/cases/json_serialization_test.rb +++ b/activerecord/test/cases/json_serialization_test.rb @@ -161,6 +161,15 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase assert_match %r{"tag":\{"name":"General"\}}, json end + def test_includes_doesnt_merge_opts_from_base + json = @david.to_json( + :only => :id, + :include => :posts + ) + + assert_match %{"title":"Welcome to the weblog"}, json + end + def test_should_not_call_methods_on_associations_that_dont_respond def @david.favorite_quote; "Constraints are liberating"; end json = @david.to_json(:include => :posts, :methods => :favorite_quote) |