From 72897451bb0f14392dd90987dc88892656f84b8d Mon Sep 17 00:00:00 2001 From: eproulx Date: Mon, 3 Jan 2022 14:38:36 +0100 Subject: [PATCH 1/6] Rename MissingGroupType and UnsupportedGroupType --- lib/grape.rb | 4 ++-- lib/grape/dsl/parameters.rb | 4 ++-- lib/grape/exceptions/missing_group_type.rb | 2 +- lib/grape/exceptions/unsupported_group_type.rb | 2 +- lib/grape/validations/params_scope.rb | 4 ++-- spec/grape/validations/params_scope_spec.rb | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/grape.rb b/lib/grape.rb index 5c091a5378..832bbbacd0 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -72,8 +72,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 diff --git a/lib/grape/dsl/parameters.rb b/lib/grape/dsl/parameters.rb index 81a30b1683..f74da986a8 100644 --- a/lib/grape/dsl/parameters.rb +++ b/lib/grape/dsl/parameters.rb @@ -150,8 +150,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] diff --git a/lib/grape/exceptions/missing_group_type.rb b/lib/grape/exceptions/missing_group_type.rb index 398113ff83..eac7ddb8db 100644 --- a/lib/grape/exceptions/missing_group_type.rb +++ b/lib/grape/exceptions/missing_group_type.rb @@ -2,7 +2,7 @@ module Grape module Exceptions - class MissingGroupTypeError < Base + class MissingGroupType < Base def initialize super(message: compose_message(:missing_group_type)) end diff --git a/lib/grape/exceptions/unsupported_group_type.rb b/lib/grape/exceptions/unsupported_group_type.rb index 9cbc7aac27..dff4d38ff4 100644 --- a/lib/grape/exceptions/unsupported_group_type.rb +++ b/lib/grape/exceptions/unsupported_group_type.rb @@ -2,7 +2,7 @@ module Grape module Exceptions - class UnsupportedGroupTypeError < Base + class UnsupportedGroupType < Base def initialize super(message: compose_message(:unsupported_group_type)) end diff --git a/lib/grape/validations/params_scope.rb b/lib/grape/validations/params_scope.rb index 7b57ba42cd..b7051847fc 100644 --- a/lib/grape/validations/params_scope.rb +++ b/lib/grape/validations/params_scope.rb @@ -206,8 +206,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( diff --git a/spec/grape/validations/params_scope_spec.rb b/spec/grape/validations/params_scope_spec.rb index 87b9bb962f..0b7919a7c3 100644 --- a/spec/grape/validations/params_scope_spec.rb +++ b/spec/grape/validations/params_scope_spec.rb @@ -336,7 +336,7 @@ 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 @@ -344,7 +344,7 @@ def initialize(value) 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 @@ -404,7 +404,7 @@ 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 @@ -412,7 +412,7 @@ def initialize(value) requires :b end end - end.to raise_error Grape::Exceptions::UnsupportedGroupTypeError + end.to raise_error Grape::Exceptions::UnsupportedGroupType end end From 323224fab7aea45ad2423ce52b36c711b6dbfd0b Mon Sep 17 00:00:00 2001 From: eproulx Date: Mon, 3 Jan 2022 14:39:57 +0100 Subject: [PATCH 2/6] Add CHANGELOG.md AND UPGRADING.md entries --- CHANGELOG.md | 1 + UPGRADING.md | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6975805131..9c0c6e6168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ #### Fixes * [#2222](https://github.com/ruby-grape/grape/pull/2222): Autoload types and validators - [@ericproulx](https://github.com/ericproulx). +* [#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) diff --git a/UPGRADING.md b/UPGRADING.md index 8dc77ea677..5fc57a1b7c 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,15 @@ Upgrading Grape =============== +### Upgrading to >= 1.6.3 + +#### Exceptions renaming + +The following exceptions has been renamed for consistency through exceptions naming : + +* `MissingGroupTypeError` => `MissingGroupType` +* `UnsupportedGroupTypeError` => `UnsupportedGroupType` + ### Upgrading to >= 1.6.0 #### Parameter renaming with :as From 99c651408e9c1fca7fc0f5941e2e552efc702bde Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Thu, 20 Jan 2022 10:46:21 +0100 Subject: [PATCH 3/6] Quote classes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0c6e6168..bdb9f6d8c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ #### Fixes * [#2222](https://github.com/ruby-grape/grape/pull/2222): Autoload types and validators - [@ericproulx](https://github.com/ericproulx). -* [#2227](https://github.com/ruby-grape/grape/pull/2222): Rename MissingGroupType and UnsupportedGroupType exceptions - [@ericproulx](https://github.com/ericproulx). +* [#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) From 1851fb01d9186bd66cd96b92c34dd9c7d9159e32 Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Thu, 20 Jan 2022 10:49:24 +0100 Subject: [PATCH 4/6] Add for more information --- UPGRADING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index 5fc57a1b7c..969fc1347c 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -10,6 +10,8 @@ The following exceptions has been renamed for consistency through exceptions nam * `MissingGroupTypeError` => `MissingGroupType` * `UnsupportedGroupTypeError` => `UnsupportedGroupType` +See [#2227](https://github.com/ruby-grape/grape/pull/2227) for more information. + ### Upgrading to >= 1.6.0 #### Parameter renaming with :as From 48309a7260a9dbf9bb2512237939b106a01e830a Mon Sep 17 00:00:00 2001 From: eproulx Date: Sun, 13 Feb 2022 18:33:38 +0100 Subject: [PATCH 5/6] Add alias for MissingGroupType and UnsupportedGroupeType --- lib/grape/exceptions/missing_group_type.rb | 2 ++ lib/grape/exceptions/unsupported_group_type.rb | 2 ++ .../grape/exceptions/missing_group_type_spec.rb | 15 +++++++++++++++ .../exceptions/unsupported_group_type_spec.rb | 17 +++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 spec/grape/exceptions/missing_group_type_spec.rb create mode 100644 spec/grape/exceptions/unsupported_group_type_spec.rb diff --git a/lib/grape/exceptions/missing_group_type.rb b/lib/grape/exceptions/missing_group_type.rb index eac7ddb8db..d400424b4e 100644 --- a/lib/grape/exceptions/missing_group_type.rb +++ b/lib/grape/exceptions/missing_group_type.rb @@ -9,3 +9,5 @@ def initialize end end end + +Grape::Exceptions::MissingGroupTypeError = Grape::Exceptions::MissingGroupType diff --git a/lib/grape/exceptions/unsupported_group_type.rb b/lib/grape/exceptions/unsupported_group_type.rb index dff4d38ff4..3fb6160b79 100644 --- a/lib/grape/exceptions/unsupported_group_type.rb +++ b/lib/grape/exceptions/unsupported_group_type.rb @@ -9,3 +9,5 @@ def initialize end end end + +Grape::Exceptions::UnsupportedGroupTypeError = Grape::Exceptions::UnsupportedGroupType diff --git a/spec/grape/exceptions/missing_group_type_spec.rb b/spec/grape/exceptions/missing_group_type_spec.rb new file mode 100644 index 0000000000..aa71f1408e --- /dev/null +++ b/spec/grape/exceptions/missing_group_type_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/grape/exceptions/unsupported_group_type_spec.rb b/spec/grape/exceptions/unsupported_group_type_spec.rb new file mode 100644 index 0000000000..4ee7e562a2 --- /dev/null +++ b/spec/grape/exceptions/unsupported_group_type_spec.rb @@ -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 \ No newline at end of file From 085b8c29e055ae376e4de068d3ce52944ba9c9a8 Mon Sep 17 00:00:00 2001 From: eproulx Date: Sun, 13 Feb 2022 18:34:29 +0100 Subject: [PATCH 6/6] Add Final newline missing. --- spec/grape/exceptions/missing_group_type_spec.rb | 2 +- spec/grape/exceptions/unsupported_group_type_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/grape/exceptions/missing_group_type_spec.rb b/spec/grape/exceptions/missing_group_type_spec.rb index aa71f1408e..509f823f2c 100644 --- a/spec/grape/exceptions/missing_group_type_spec.rb +++ b/spec/grape/exceptions/missing_group_type_spec.rb @@ -12,4 +12,4 @@ it { is_expected.to eq(Grape::Exceptions::MissingGroupTypeError) } end -end \ No newline at end of file +end diff --git a/spec/grape/exceptions/unsupported_group_type_spec.rb b/spec/grape/exceptions/unsupported_group_type_spec.rb index 4ee7e562a2..167755aefd 100644 --- a/spec/grape/exceptions/unsupported_group_type_spec.rb +++ b/spec/grape/exceptions/unsupported_group_type_spec.rb @@ -14,4 +14,4 @@ it { is_expected.to eq(Grape::Exceptions::UnsupportedGroupTypeError) } end -end \ No newline at end of file +end