Skip to content

Commit

Permalink
Delegate to_s to object
Browse files Browse the repository at this point in the history
Closes #560
  • Loading branch information
haines committed Jul 7, 2013
1 parent 78e1af4 commit 58b8181
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/draper/decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
8 changes: 8 additions & 0 deletions spec/draper/decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}))
Expand Down

0 comments on commit 58b8181

Please sign in to comment.