1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

21 commits

Author SHA1 Message Date
Yves Senn
eeba679470 rewrite tests to have no side-effects on include_root_in_json. 2013-03-04 21:18:40 +01:00
Carlos Antonio da Silva
8b173f3bc5 Fix serializable_hash with xml generation and default :except option
When generating xml with a custom implementation of serializable_hash,
if using the :except option, it was being overriden by the default AR
implementation that attempts to ignore the inheritance column from STI
automatically. So, if you have an implementation like this:

    def serializable_hash(options={})
      super({ except: %w(some_attr) }.merge!(options))
    end

The :except option was correctly being used for :json generation, but
not for :xml, because the options hash already contained the :except
key with the inheritance column, thus overriding the customization.

This commit fixes this problem by removing the :except logic from the
xml serializer, that happened before calling serializable_hash. Since
serializable_hash also does the same check for inheritance column, this
logic was duplicated in both places, thus it's safe to remove it from
xml serializer (see ActiveRecord::Serialization#serializable_hash).

This is an attempt to solve issue #2498, that claims for a
"Single transformation API for both xml and json representations".
2012-06-22 08:28:26 -03:00
Carlos Antonio da Silva
965b779eb2 Add some coverage for AR serialization with serializable_hash
ActiveRecord json/xml serialization should use as base
serializable_hash, provided by ActiveModel. Add some more coverage
around options :only and :except for both json and xml serialization.
2012-06-22 08:28:03 -03:00
Aaron Patterson
61774e0d49 please use ruby -I lib:test path/to/test.rb, or export RUBY_OPT 2011-06-06 15:47:13 -07:00
Jon Leighton
253bb6b926 Refactor Active Record test connection setup. Please see the RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases. 2011-06-04 23:47:03 +01:00
John Mileham
294e2a8c2e Failing test - JSON serialization shouldn't merge base opts into include opts. 2011-05-26 11:24:25 -04:00
Jon Leighton
1f7415ab3a Fix broken test 2010-10-19 16:26:35 +01:00
Jon Leighton
43711083dd Fix the tests (I have actually verified that these are also the 'right' fixes, rather than just making the tests pass again) 2010-10-03 11:56:32 +01:00
Jakub Suder
2524cf404c fixed some issues with JSON encoding
- as_json in ActiveModel should return a hash
  and handle :only/:except/:methods options
- Array and Hash should call as_json on their elements
- json methods should not modify options argument

[#5374 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-09-07 11:33:10 -07:00
Santiago Pastorino
b451de0d6d Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
Mislav Marohnić
571cb1ddc6 enable AS::JSON.encode to encode AR::Relation by providing as_json method
[#5073 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-13 08:09:28 +02:00
José Valim
a04060fb6f Really make include_root_in_json default to true [#3770 state:resolved] 2010-06-08 01:02:45 +02:00
Evan Phoenix
4f5de7f89a Reset class attribute after changing it 2010-03-22 10:00:04 -07:00
Jeremy Kemper
6e73cf6bdf Fix AR json encoding 2009-06-08 19:37:51 -07:00
rick
3c4c6bd0df * Add pluggable JSON backends with support for the JSON gem. [rick]
Example: ActiveSupport::JSON.backend = "JSONGem"

  All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode().  Use of #to_json is not recommended, as it may clash with other libraries that overwrite it.  However, you can recover Rails specific functionality
  if you really want to use #to_json.

    gem 'json'
    ActiveSupport::JSON.backend = "JSONGem"

    class ActiveRecord::Base
      alias to_json rails_to_json
    end
2009-04-23 00:08:40 -07:00
Michael Koziarski
f2ee3f20df Fix the AR json serialization tests to comply with the earlier change to quote keys correctly 2009-01-16 17:57:45 +13:00
Rick Olson
d450ac4459 Tweak ActiveRecord::Base#to_json to include a root value in the returned hash: {post: {title: ...}} [rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9202 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-04-01 20:09:45 +00:00
Jeremy Kemper
39814fcce0 Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8681 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-21 17:20:51 +00:00
Jeremy Kemper
16b129a68c belongs_to supports :dependent => :destroy and :delete. Closes #10592.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8675 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-19 05:30:42 +00:00
Jeremy Kemper
1e70928014 Fix paths
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8661 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-18 07:31:37 +00:00
Jeremy Kemper
42b39ae3f2 Move tests to cases
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8660 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-01-18 07:30:42 +00:00
Renamed from activerecord/test/json_serialization_test.rb (Browse further)