Add serializers
This commit is contained in:
parent
94f83a2e0b
commit
4a901b7751
|
@ -1,5 +1,8 @@
|
|||
require 'action_view'
|
||||
require 'active_model/naming'
|
||||
require 'active_model/serialization'
|
||||
require 'active_model/serializers/json'
|
||||
require 'active_model/serializers/xml'
|
||||
require 'active_support/inflector'
|
||||
require 'active_support/core_ext/hash/keys'
|
||||
require 'active_support/core_ext/hash/reverse_merge'
|
||||
|
|
|
@ -2,7 +2,10 @@ module Draper
|
|||
class Decorator
|
||||
include Draper::ViewHelpers
|
||||
extend Draper::Delegation
|
||||
|
||||
include ActiveModel::Serialization
|
||||
include ActiveModel::Serializers::JSON
|
||||
include ActiveModel::Serializers::Xml
|
||||
|
||||
# @return the object being decorated.
|
||||
attr_reader :source
|
||||
|
|
|
@ -40,6 +40,17 @@ describe PostDecorator do
|
|||
expect(decorator.serializable_hash["updated_at"]).to be :overridden
|
||||
end
|
||||
|
||||
it "serializes to JSON" do
|
||||
json = decorator.to_json
|
||||
expect(json).to match /^{"post":{.+}}$/
|
||||
expect(json).to match /"updated_at":"overridden"/
|
||||
end
|
||||
|
||||
it "serializes to XML" do
|
||||
xml = Capybara.string(decorator.to_xml)
|
||||
expect(xml).to have_css "post > updated-at", text: "overridden"
|
||||
end
|
||||
|
||||
it "uses a test view context from ApplicationController" do
|
||||
expect(Draper::ViewContext.current.controller).to be_an ApplicationController
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue