Change serialization spec

This commit is contained in:
Andrew Haines 2012-11-21 00:57:35 +00:00
parent 87bf0d8c76
commit a1e8dff94b
5 changed files with 18 additions and 7 deletions

View File

@ -27,7 +27,7 @@ module Draper
source.to_a if source.respond_to?(:to_a) # forces evaluation of a lazy query from AR
@source = source
@options = options
handle_multiple_decoration if source.is_a?(Draper::Decorator)
handle_multiple_decoration if source.is_a?(Draper::Decorator)
end
class << self

View File

@ -11,12 +11,6 @@ describe Draper::Decorator do
subject.source.should be source
end
if defined?(ActiveModel::Serialization)
it "includes ActiveModel::Serialization if present" do
subject.should respond_to(:serializable_hash)
end
end
it "stores options" do
decorator = decorator_class.new(source, some: "options")
decorator.options.should == {some: "options"}
@ -488,4 +482,12 @@ describe Draper::Decorator do
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

View File

@ -8,6 +8,7 @@ require 'action_controller/test_case'
Bundler.require
require './spec/support/active_model'
require './spec/support/active_record'
require './spec/support/action_controller'

View File

@ -0,0 +1,7 @@
module ActiveModel
module Serialization
def serializable_hash
{overridable: send(:overridable)}
end
end
end

View File

@ -1,5 +1,6 @@
class Product < ActiveRecord::Base
include Draper::Decoratable
include ActiveModel::Serialization
def self.find_by_name(name)
@@dummy ||= Product.new