Skip to content

Commit 8f180c5

Browse files
author
Tobias Bielohlawek
committed
Raise a warning when desc is called with options hash and block
fixes #920
1 parent d7718f0 commit 8f180c5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
* [#1109](https://github.com/ruby-grape/grape/pull/1109): Memoize Virtus attribute and fix memory leak - [@marshall-lee](https://github.com/marshall-lee).
1111
* [#1101](https://github.com/intridea/grape/pull/1101): Fix: Incorrect media-type `Accept` header now correctly returns 406 with `strict: true` - [@elliotlarson](https://github.com/elliotlarson).
12+
* [#1108](https://github.com/ruby-grape/grape/pull/1039): Raise a warning when `desc` is called with options hash and block - [@rngtng](https://github.com/rngtng).
1213

1314
0.13.0 (8/10/2015)
1415
==================

lib/grape/dsl/configuration.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def desc(description, options = {}, &config_block)
6464
end
6565

6666
config_class.configure(&config_block)
67+
unless options.empty?
68+
warn '[DEPRECATION] Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.'
69+
end
6770
options = config_class.settings
6871
else
6972
options = options.merge(description: description)

spec/grape/dsl/configuration_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ class Dummy
7070
expect(subject.namespace_setting(:description)).to eq(expected_options)
7171
expect(subject.route_setting(:description)).to eq(expected_options)
7272
end
73+
74+
it 'can be set with options and a block' do
75+
expect(subject).to receive(:warn).with('[DEPRECATION] Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.')
76+
77+
desc_text = 'The description'
78+
detail_text = 'more details'
79+
options = { message: 'none' }
80+
subject.desc desc_text, options do
81+
detail detail_text
82+
end
83+
expect(subject.namespace_setting(:description)).to eq(description: desc_text, detail: detail_text)
84+
expect(subject.route_setting(:description)).to eq(description: desc_text, detail: detail_text)
85+
end
7386
end
7487
end
7588
end

0 commit comments

Comments
 (0)