From 58b8181050c2a9a86f54660e7bb6bfefa5fd0b64 Mon Sep 17 00:00:00 2001 From: Andrew Haines Date: Sun, 7 Jul 2013 15:10:02 +0100 Subject: [PATCH] Delegate `to_s` to object Closes #560 --- lib/draper/decorator.rb | 2 ++ spec/draper/decorator_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/draper/decorator.rb b/lib/draper/decorator.rb index bb12b964..28241724 100755 --- a/lib/draper/decorator.rb +++ b/lib/draper/decorator.rb @@ -188,6 +188,8 @@ def instance_of?(klass) super || object.instance_of?(klass) end + delegate :to_s + # In case object is nil delegate :present?, :blank? diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index e317b361..cef15f81 100755 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -441,6 +441,14 @@ module Draper end end + describe "#to_s" do + it "delegates to the object" do + decorator = Decorator.new(double(to_s: :delegated)) + + expect(decorator.to_s).to be :delegated + end + end + describe "#attributes" do it "returns only the object's attributes that are implemented by the decorator" do decorator = Decorator.new(double(attributes: {foo: "bar", baz: "qux"}))