mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
parent
bb8c1b723b
commit
94f83a2e0b
2 changed files with 16 additions and 1 deletions
|
@ -187,8 +187,14 @@ module Draper
|
|||
self
|
||||
end
|
||||
|
||||
# @return [Hash] the source's attributes, sliced to only include those
|
||||
# implemented by the decorator.
|
||||
def attributes
|
||||
source.attributes.select {|attribute, _| respond_to?(attribute) }
|
||||
end
|
||||
|
||||
# ActiveModel compatibility
|
||||
delegate :attributes, :to_param, :to_partial_path
|
||||
delegate :to_param, :to_partial_path
|
||||
|
||||
# ActiveModel compatibility
|
||||
singleton_class.delegate :model_name, to: :source_class
|
||||
|
|
|
@ -345,6 +345,15 @@ module Draper
|
|||
end
|
||||
end
|
||||
|
||||
describe "#attributes" do
|
||||
it "returns only the source's attributes that are implemented by the decorator" do
|
||||
decorator = Decorator.new(double(attributes: {foo: "bar", baz: "qux"}))
|
||||
decorator.stub(:foo)
|
||||
|
||||
expect(decorator.attributes).to eq({foo: "bar"})
|
||||
end
|
||||
end
|
||||
|
||||
describe ".model_name" do
|
||||
it "delegates to the source class" do
|
||||
Decorator.stub source_class: double(model_name: :delegated)
|
||||
|
|
Loading…
Reference in a new issue