Skip to content

Commit

Permalink
Include ActiveModel::Serialization in Draper::Decorator.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiassvedhem committed Nov 20, 2012
1 parent d2e4d21 commit c4b3527
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/draper/decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def initialize(source, options = {})
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)
self.class.send(:include, ActiveModel::Serialization) if defined?(ActiveModel::Serialization)
end

class << self
Expand Down
6 changes: 6 additions & 0 deletions spec/draper/decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
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"}
Expand Down

0 comments on commit c4b3527

Please sign in to comment.