Change serialization spec
This commit is contained in:
parent
87bf0d8c76
commit
a1e8dff94b
|
@ -27,7 +27,7 @@ module Draper
|
||||||
source.to_a if source.respond_to?(:to_a) # forces evaluation of a lazy query from AR
|
source.to_a if source.respond_to?(:to_a) # forces evaluation of a lazy query from AR
|
||||||
@source = source
|
@source = source
|
||||||
@options = options
|
@options = options
|
||||||
handle_multiple_decoration if source.is_a?(Draper::Decorator)
|
handle_multiple_decoration if source.is_a?(Draper::Decorator)
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
|
@ -11,12 +11,6 @@ describe Draper::Decorator do
|
||||||
subject.source.should be source
|
subject.source.should be source
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(ActiveModel::Serialization)
|
|
||||||
it "includes ActiveModel::Serialization if present" do
|
|
||||||
subject.should respond_to(:serializable_hash)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "stores options" do
|
it "stores options" do
|
||||||
decorator = decorator_class.new(source, some: "options")
|
decorator = decorator_class.new(source, some: "options")
|
||||||
decorator.options.should == {some: "options"}
|
decorator.options.should == {some: "options"}
|
||||||
|
@ -488,4 +482,12 @@ describe Draper::Decorator do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#serializable_hash" do
|
||||||
|
let(:decorator_class) { ProductDecorator }
|
||||||
|
|
||||||
|
it "serializes overridden attributes" do
|
||||||
|
subject.serializable_hash[:overridable].should be :overridden
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,7 @@ require 'action_controller/test_case'
|
||||||
|
|
||||||
Bundler.require
|
Bundler.require
|
||||||
|
|
||||||
|
require './spec/support/active_model'
|
||||||
require './spec/support/active_record'
|
require './spec/support/active_record'
|
||||||
require './spec/support/action_controller'
|
require './spec/support/action_controller'
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
module ActiveModel
|
||||||
|
module Serialization
|
||||||
|
def serializable_hash
|
||||||
|
{overridable: send(:overridable)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
include Draper::Decoratable
|
include Draper::Decoratable
|
||||||
|
include ActiveModel::Serialization
|
||||||
|
|
||||||
def self.find_by_name(name)
|
def self.find_by_name(name)
|
||||||
@@dummy ||= Product.new
|
@@dummy ||= Product.new
|
||||||
|
|
Loading…
Reference in New Issue