From d10365551c2704100aa61d57ba287eb9f382f153 Mon Sep 17 00:00:00 2001 From: Michael Fairley Date: Sat, 19 Nov 2011 15:02:04 -0800 Subject: [PATCH] Add decorates_associations to decorate multiple associations --- lib/draper/base.rb | 8 ++++++++ spec/draper/base_spec.rb | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/draper/base.rb b/lib/draper/base.rb index 6b9a1c8..bafa144 100644 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -69,6 +69,14 @@ module Draper end end + # A convenience method for decorating multiple associations. Calls + # decorates_association on each of the given symbols. + # + # @param [Symbols*] name of associations to decorate + def self.decorates_associations(*association_symbols) + association_symbols.each{ |sym| decorates_association(sym) } + end + # Specifies a black list of methods which may *not* be proxied to # to the wrapped object. # diff --git a/spec/draper/base_spec.rb b/spec/draper/base_spec.rb index 87b5c44..64132af 100644 --- a/spec/draper/base_spec.rb +++ b/spec/draper/base_spec.rb @@ -95,6 +95,16 @@ describe Draper::Base do end end + context('.decorates_associations') do + subject { Decorator } + it "decorates each of the associations" do + subject.should_receive(:decorates_association).with(:similar_products) + subject.should_receive(:decorates_association).with(:previous_version) + + subject.decorates_associations :similar_products, :previous_version + end + end + context(".model / .to_model") do it "should return the wrapped object" do subject.to_model.should == source