Skip to content

Commit e93d278

Browse files
authored
Rename MissingGroupType and UnsupportedGroupType (#2227)
* Rename MissingGroupType and UnsupportedGroupType * Add CHANGELOG.md AND UPGRADING.md entries * Quote classes * Add for more information * Add alias for MissingGroupType and UnsupportedGroupeType * Add Final newline missing.
1 parent ed04e2c commit e93d278

10 files changed

+60
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [#2232](https://github.com/ruby-grape/grape/pull/2232): Fix kwargs support in shared params definition - [@dm1try](https://github.com/dm1try).
1313
* [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
1414
* [#2234](https://github.com/ruby-grape/grape/pull/2234): Remove non-utf-8 characters from format before generating JSON error - [@bschmeck](https://github.com/bschmeck).
15+
* [#2227](https://github.com/ruby-grape/grape/pull/2222): Rename "MissingGroupType" and "UnsupportedGroupType" exceptions - [@ericproulx](https://github.com/ericproulx).
1516
* Your contribution here.
1617

1718
### 1.6.2 (2021/12/30)

UPGRADING.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Upgrading Grape
22
===============
33

4+
### Upgrading to >= 1.6.3
5+
6+
#### Exceptions renaming
7+
8+
The following exceptions has been renamed for consistency through exceptions naming :
9+
10+
* `MissingGroupTypeError` => `MissingGroupType`
11+
* `UnsupportedGroupTypeError` => `UnsupportedGroupType`
12+
13+
See [#2227](https://github.com/ruby-grape/grape/pull/2227) for more information.
14+
415
### Upgrading to >= 1.6.0
516

617
#### Parameter renaming with :as

lib/grape.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ module Exceptions
7373
autoload :UnknownParameter
7474
autoload :InvalidWithOptionForRepresent
7575
autoload :IncompatibleOptionValues
76-
autoload :MissingGroupTypeError, 'grape/exceptions/missing_group_type'
77-
autoload :UnsupportedGroupTypeError, 'grape/exceptions/unsupported_group_type'
76+
autoload :MissingGroupType
77+
autoload :UnsupportedGroupType
7878
autoload :InvalidMessageBody
7979
autoload :InvalidAcceptHeader
8080
autoload :InvalidVersionHeader

lib/grape/dsl/parameters.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def optional(*attrs, &block)
148148

149149
# check type for optional parameter group
150150
if attrs && block
151-
raise Grape::Exceptions::MissingGroupTypeError.new if type.nil?
152-
raise Grape::Exceptions::UnsupportedGroupTypeError.new unless Grape::Validations::Types.group?(type)
151+
raise Grape::Exceptions::MissingGroupType if type.nil?
152+
raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)
153153
end
154154

155155
if opts[:using]

lib/grape/exceptions/missing_group_type.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
module Grape
44
module Exceptions
5-
class MissingGroupTypeError < Base
5+
class MissingGroupType < Base
66
def initialize
77
super(message: compose_message(:missing_group_type))
88
end
99
end
1010
end
1111
end
12+
13+
Grape::Exceptions::MissingGroupTypeError = Grape::Exceptions::MissingGroupType

lib/grape/exceptions/unsupported_group_type.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
module Grape
44
module Exceptions
5-
class UnsupportedGroupTypeError < Base
5+
class UnsupportedGroupType < Base
66
def initialize
77
super(message: compose_message(:unsupported_group_type))
88
end
99
end
1010
end
1111
end
12+
13+
Grape::Exceptions::UnsupportedGroupTypeError = Grape::Exceptions::UnsupportedGroupType

lib/grape/validations/params_scope.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def new_scope(attrs, optional = false, &block)
208208
# if required params are grouped and no type or unsupported type is provided, raise an error
209209
type = attrs[1] ? attrs[1][:type] : nil
210210
if attrs.first && !optional
211-
raise Grape::Exceptions::MissingGroupTypeError.new if type.nil?
212-
raise Grape::Exceptions::UnsupportedGroupTypeError.new unless Grape::Validations::Types.group?(type)
211+
raise Grape::Exceptions::MissingGroupType if type.nil?
212+
raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)
213213
end
214214

215215
self.class.new(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Grape::Exceptions::MissingGroupType do
4+
describe '#message' do
5+
subject { described_class.new.message }
6+
7+
it { is_expected.to include 'group type is required' }
8+
end
9+
10+
describe '#alias' do
11+
subject { described_class }
12+
13+
it { is_expected.to eq(Grape::Exceptions::MissingGroupTypeError) }
14+
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Grape::Exceptions::UnsupportedGroupType do
4+
subject { described_class.new }
5+
6+
describe '#message' do
7+
subject { described_class.new.message }
8+
9+
it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
10+
end
11+
12+
describe '#alias' do
13+
subject { described_class }
14+
15+
it { is_expected.to eq(Grape::Exceptions::UnsupportedGroupTypeError) }
16+
end
17+
end

spec/grape/validations/params_scope_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@ def initialize(value)
256256
requires :b
257257
end
258258
end
259-
end.to raise_error Grape::Exceptions::MissingGroupTypeError
259+
end.to raise_error Grape::Exceptions::MissingGroupType
260260

261261
expect do
262262
subject.params do
263263
optional :a do
264264
requires :b
265265
end
266266
end
267-
end.to raise_error Grape::Exceptions::MissingGroupTypeError
267+
end.to raise_error Grape::Exceptions::MissingGroupType
268268
end
269269

270270
it 'allows Hash as type' do
@@ -324,15 +324,15 @@ def initialize(value)
324324
requires :b
325325
end
326326
end
327-
end.to raise_error Grape::Exceptions::UnsupportedGroupTypeError
327+
end.to raise_error Grape::Exceptions::UnsupportedGroupType
328328

329329
expect do
330330
subject.params do
331331
optional :a, type: Set do
332332
requires :b
333333
end
334334
end
335-
end.to raise_error Grape::Exceptions::UnsupportedGroupTypeError
335+
end.to raise_error Grape::Exceptions::UnsupportedGroupType
336336
end
337337
end
338338

0 commit comments

Comments
 (0)