Allow multiple allows
This commit is contained in:
parent
50e5adf216
commit
53586b8a38
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue