Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename MissingGroupType and UnsupportedGroupType #2227

Merged
merged 7 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [#2232](https://github.com/ruby-grape/grape/pull/2232): Fix kwargs support in shared params definition - [@dm1try](https://github.com/dm1try).
* [#2229](https://github.com/ruby-grape/grape/pull/2229): Do not collect params in route settings - [@dnesteryuk](https://github.com/dnesteryuk).
* [#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).
* [#2227](https://github.com/ruby-grape/grape/pull/2222): Rename "MissingGroupType" and "UnsupportedGroupType" exceptions - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

### 1.6.2 (2021/12/30)
Expand Down
11 changes: 11 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Upgrading Grape
===============

### Upgrading to >= 1.6.3

#### Exceptions renaming

The following exceptions has been renamed for consistency through exceptions naming :

* `MissingGroupTypeError` => `MissingGroupType`
* `UnsupportedGroupTypeError` => `UnsupportedGroupType`

ericproulx marked this conversation as resolved.
Show resolved Hide resolved
See [#2227](https://github.com/ruby-grape/grape/pull/2227) for more information.

### Upgrading to >= 1.6.0

#### Parameter renaming with :as
Expand Down
4 changes: 2 additions & 2 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ module Exceptions
autoload :UnknownParameter
autoload :InvalidWithOptionForRepresent
autoload :IncompatibleOptionValues
autoload :MissingGroupTypeError, 'grape/exceptions/missing_group_type'
autoload :UnsupportedGroupTypeError, 'grape/exceptions/unsupported_group_type'
autoload :MissingGroupType
autoload :UnsupportedGroupType
autoload :InvalidMessageBody
autoload :InvalidAcceptHeader
autoload :InvalidVersionHeader
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def optional(*attrs, &block)

# check type for optional parameter group
if attrs && block
raise Grape::Exceptions::MissingGroupTypeError.new if type.nil?
raise Grape::Exceptions::UnsupportedGroupTypeError.new unless Grape::Validations::Types.group?(type)
raise Grape::Exceptions::MissingGroupType if type.nil?
raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)
end

if opts[:using]
Expand Down
4 changes: 3 additions & 1 deletion lib/grape/exceptions/missing_group_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

module Grape
module Exceptions
class MissingGroupTypeError < Base
class MissingGroupType < Base
def initialize
super(message: compose_message(:missing_group_type))
end
end
end
end

Grape::Exceptions::MissingGroupTypeError = Grape::Exceptions::MissingGroupType
4 changes: 3 additions & 1 deletion lib/grape/exceptions/unsupported_group_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

module Grape
module Exceptions
class UnsupportedGroupTypeError < Base
class UnsupportedGroupType < Base
def initialize
super(message: compose_message(:unsupported_group_type))
end
end
end
end

Grape::Exceptions::UnsupportedGroupTypeError = Grape::Exceptions::UnsupportedGroupType
4 changes: 2 additions & 2 deletions lib/grape/validations/params_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def new_scope(attrs, optional = false, &block)
# if required params are grouped and no type or unsupported type is provided, raise an error
type = attrs[1] ? attrs[1][:type] : nil
if attrs.first && !optional
raise Grape::Exceptions::MissingGroupTypeError.new if type.nil?
raise Grape::Exceptions::UnsupportedGroupTypeError.new unless Grape::Validations::Types.group?(type)
raise Grape::Exceptions::MissingGroupType if type.nil?
raise Grape::Exceptions::UnsupportedGroupType unless Grape::Validations::Types.group?(type)
end

self.class.new(
Expand Down
15 changes: 15 additions & 0 deletions spec/grape/exceptions/missing_group_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

RSpec.describe Grape::Exceptions::MissingGroupType do
describe '#message' do
subject { described_class.new.message }

it { is_expected.to include 'group type is required' }
end

describe '#alias' do
subject { described_class }

it { is_expected.to eq(Grape::Exceptions::MissingGroupTypeError) }
end
end
17 changes: 17 additions & 0 deletions spec/grape/exceptions/unsupported_group_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe Grape::Exceptions::UnsupportedGroupType do
subject { described_class.new }

describe '#message' do
subject { described_class.new.message }

it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
end

describe '#alias' do
subject { described_class }

it { is_expected.to eq(Grape::Exceptions::UnsupportedGroupTypeError) }
end
end
8 changes: 4 additions & 4 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ def initialize(value)
requires :b
end
end
end.to raise_error Grape::Exceptions::MissingGroupTypeError
end.to raise_error Grape::Exceptions::MissingGroupType

expect do
subject.params do
optional :a do
requires :b
end
end
end.to raise_error Grape::Exceptions::MissingGroupTypeError
end.to raise_error Grape::Exceptions::MissingGroupType
end

it 'allows Hash as type' do
Expand Down Expand Up @@ -324,15 +324,15 @@ def initialize(value)
requires :b
end
end
end.to raise_error Grape::Exceptions::UnsupportedGroupTypeError
end.to raise_error Grape::Exceptions::UnsupportedGroupType

expect do
subject.params do
optional :a, type: Set do
requires :b
end
end
end.to raise_error Grape::Exceptions::UnsupportedGroupTypeError
end.to raise_error Grape::Exceptions::UnsupportedGroupType
end
end

Expand Down