This project is archived and is in readonly mode.
[PATCH] Fix changing ActiveModel include_root_in_json = true to default
Reported by Cody Fauser | January 22nd, 2010 @ 01:06 PM | in 3.0.2
This commit was intended to change the default include_root_in_json setting to true. However, it contained an error and didn't actually set the default to true.
The following IRB session illustrates the issue:
ActiveRecord::Base.include_root_in_json
=> nil
irb(main):002:0> a = Article.new(:title => "AWDWR")
=> #<Article id: nil, title: "AWDWR", created_at: nil, updated_at: nil>
irb(main):003:0> puts a.to_json
{"created_at":null,"title":"AWDWR","updated_at":null}
=> nil
irb(main):004:0> ActiveRecord::Base.include_root_in_json = true
=> true
irb(main):005:0> puts a.to_json
{"article":{"created_at":null,"title":"AWDWR","updated_at":null}}
=> nil
A patch is attached.
Comments and changes to this ticket
-
Christopher Redinger May 14th, 2010 @ 08:16 PM
This patch did not apply cleanly to the current master. Submitting an updated patch that does.
-
Neeraj Singh May 14th, 2010 @ 08:49 PM
@Christopher Looks like you have some end of line settings that is marking all the test lines as changed.
- assert_match %r{^\{"contact":\{}, json - assert_match %r{"name":"Konata Izumi"}, json - assert_match %r{"age":16}, json - assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})) - assert_match %r{"awesome":true}, json - assert_match %r{"preferences":\{"shows":"anime"\}}, json - ensure - Contact.include_root_in_json = false - end + json = @contact.to_json + + assert_match %r{^\{"contact":\{}, json + assert_match %r{"name":"Konata Izumi"}, json + assert_match %r{"age":16}, json + assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})) + assert_match %r{"awesome":true}, json + assert_match %r{"preferences":\{"shows":"anime"\}}, json
Also in json_serialization_test.rb has two tests with Contact.include_root_in_json = true . Can you add one test with Contact.include_root_in_json = false just to make sure that without root things work fine.
-
Christopher Redinger May 15th, 2010 @ 01:39 AM
Neeraj - nope, those are valid changes. They were wrapped in an unnecessary begin/ensure block. I removed the block, and thus outdented the lines.
-
Rizwan Reza May 15th, 2010 @ 06:28 PM
- Milestone cleared.
- Tag changed from serialization active_model json include_root_in_json to activemodel, bugmash, json, serialization
-
Michael Koziarski June 1st, 2010 @ 10:41 PM
- Milestone cleared.
-
Santiago Pastorino June 7th, 2010 @ 08:11 AM
- State changed from new to open
- Assigned user set to Santiago Pastorino
-
Repository June 8th, 2010 @ 12:03 AM
- State changed from open to resolved
(from [a04060fb6fe006b1dbc224263dd6c39525733c6d]) Really make include_root_in_json default to true [#3770 state:resolved] http://github.com/rails/rails/commit/a04060fb6fe006b1dbc224263dd6c3...
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to Low
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3770 [PATCH] Fix changing ActiveModel include_root_in_json = true to default (from [a04060fb6fe006b1dbc224263dd6c39525733c6d]) Really ...
- 5867 ActiveResource is not parsing JSON correct Verified that ActiveResource JSON is not working at all. ...