1

So, I'm writing a service that, being in rails, I'm pretty indifferent about how people connect. I do auth at the http layer, so if people want xml or json, I could care less.

I'm overriding to_json and to_xml, but I'm using the same arguments for both. 'include this', 'don't include that', etc.

How are other people doing this to check that the behavior is the same? Maybe just set one set of arguments and use them in both methods? Or maybe have methods that verify the JSON.from_xml(myobject.to_xml) == myobject.to_json? I'd like to not have to do all my tests twice if I can help it.

John Hinnegan
  • 5,864
  • 2
  • 48
  • 64

1 Answers1

1

So, I'm answering my own question here. Found another one like it. Has a good explanation of what I was looking for. Long story short, I'm overriding serializable_hash

http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html

How to override to_json in Rails?

PS, I'm still interested in what people are doing. Are they testing JSON and XML formats at all? Are you doing integration tests?

Community
  • 1
  • 1
John Hinnegan
  • 5,864
  • 2
  • 48
  • 64