diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-31 06:49:56 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-31 06:52:11 -0700 |
commit | 3d9c28af9331feb279053113677af2633e4b8e91 (patch) | |
tree | fa2c81f63c6a10e32dd0b2787f833889d855cd1f | |
parent | af9b1ffa75c8bb4e6e80d9d5cd2ad34487c0446c (diff) | |
download | gitlab-ce-3d9c28af9331feb279053113677af2633e4b8e91.tar.gz |
Fix first-time contributor notes not renderingsh-fix-special-role-error-500
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31117 enabled the
HashInefficientHash Rubocop rule that was fooled by the special
implementation of `SpecialRole`. We fix this by introducing a
`value?` method and adding unit tests.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/65383
-rw-r--r-- | app/models/note.rb | 4 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-special-role-error-500.yml | 5 | ||||
-rw-r--r-- | spec/models/note_spec.rb | 16 |
3 files changed, 25 insertions, 0 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 3f182c1f099..a12d1eb7243 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -27,6 +27,10 @@ class Note < ApplicationRecord def values constants.map {|const| self.const_get(const)} end + + def value?(val) + values.include?(val) + end end end diff --git a/changelogs/unreleased/sh-fix-special-role-error-500.yml b/changelogs/unreleased/sh-fix-special-role-error-500.yml new file mode 100644 index 00000000000..9aed0710da3 --- /dev/null +++ b/changelogs/unreleased/sh-fix-special-role-error-500.yml @@ -0,0 +1,5 @@ +--- +title: Fix first-time contributor notes not rendering +merge_request: 31340 +author: +type: fixed diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 03003e3dd7d..bfd0e5f0558 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -913,6 +913,22 @@ describe Note do end end + describe '#special_role=' do + let(:role) { Note::SpecialRole::FIRST_TIME_CONTRIBUTOR } + + it 'assigns role' do + subject.special_role = role + + expect(subject.special_role).to eq(role) + end + + it 'does not assign unknown role' do + expect { subject.special_role = :bogus }.to raise_error(/Role is undefined/) + + expect(subject.special_role).to be_nil + end + end + describe '#parent' do it 'returns project for project notes' do project = create(:project) |