diff --git a/lib/draper/base.rb b/lib/draper/base.rb index b91a1e6..62aebfe 100644 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -105,7 +105,8 @@ module Draper def self.allows(*input_allows) raise ArgumentError, "Specify at least one method (as a symbol) to allow when using allows" if input_allows.empty? raise ArgumentError, "Use either 'allows' or 'denies', but not both." unless (self.denied == DEFAULT_DENIED) - self.allowed = input_allows + self.allowed ||= [] + self.allowed += input_allows end # Initialize a new decorator instance by passing in diff --git a/spec/draper/base_spec.rb b/spec/draper/base_spec.rb index dd71d93..d7e4cb4 100644 --- a/spec/draper/base_spec.rb +++ b/spec/draper/base_spec.rb @@ -515,6 +515,8 @@ describe Draper::Base do describe "a sample usage with allows" do let(:subject_with_allows){ DecoratorWithAllows.new(source) } + let(:subject_with_multiple_allows){ DecoratorWithMultipleAllows.new(source) } + it "should echo the allowed method" do subject_with_allows.should respond_to(:goodnight_moon) end @@ -522,6 +524,15 @@ describe Draper::Base do it "should echo _only_ the allowed method" do subject_with_allows.should_not respond_to(:hello_world) end + + it "should echo the combined allowed methods" do + subject_with_multiple_allows.should respond_to(:goodnight_moon) + subject_with_multiple_allows.should respond_to(:hello_world) + end + + it "should echo _only_ the combined allowed methods" do + subject_with_multiple_allows.should_not respond_to(:title) + end end describe "invalid usages of allows and denies" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d04ab0..8ea84da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ require './spec/support/samples/application_controller.rb' require './spec/support/samples/application_helper.rb' require './spec/support/samples/decorator.rb' require './spec/support/samples/decorator_with_allows.rb' +require './spec/support/samples/decorator_with_multiple_allows.rb' require './spec/support/samples/decorator_with_application_helper.rb' require './spec/support/samples/decorator_with_denies.rb' require './spec/support/samples/namespaced_product.rb'