Skip to content

Commit 976c1ab

Browse files
author
Robert Ross
committed
Make sure that people can't use Procs for :format_with and the exposure.
1 parent 19d8a54 commit 976c1ab

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/grape/entity.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def self.expose(*args, &block)
7171
raise ArgumentError, "You may not use block-setting on multi-attribute exposures." if block_given?
7272
end
7373

74+
raise ArgumentError, "You may not use block-setting when also using " if block_given? && options[:format_with].respond_to?(:call)
75+
7476
options[:proc] = block if block_given?
7577

7678
args.each do |attribute|

spec/grape/entity_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
expect{ subject.expose :name, :email, :as => :foo }.to raise_error(ArgumentError)
2525
expect{ subject.expose :name, :as => :foo }.not_to raise_error
2626
end
27+
28+
it 'should make sure that :format_with as a proc can not be used with a block' do
29+
expect { subject.expose :name, :format_with => Proc.new {} do |object,options| end }.to raise_error(ArgumentError)
30+
end
2731
end
2832

2933
context 'with a block' do

0 commit comments

Comments
 (0)