Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Minor patch to solve to_json over-escaping #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/dm-serializer/to_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Serializer
# @since 1.0.1
#
def as_json(options = {})
return as_hash(options) if respond_to?(:as_hash)

options = {} if options.nil?
result = {}

Expand Down
13 changes: 13 additions & 0 deletions spec/fixtures/magician.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

class BoringGuy
include DataMapper::Resource

property :id, Integer, :key => true
property :name, String, :default => 'Bob'
end

class Magician < BoringGuy
def as_hash(options)
{ :name => 'The Magical Maestro' }
end
end
5 changes: 5 additions & 0 deletions spec/public/to_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ def deserialize(result)
it "serializes Discriminator types as strings" do
Motorcycle.new.as_json[:type].should == "Motorcycle"
end

it "should use #as_hash when available" do
BoringGuy.new.as_json[:name].should == "Bob"
Magician.new.as_json[:name].should == "The Magical Maestro"
end
end