Fix first-time contributor notes not rendering
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
This commit is contained in:
parent
af9b1ffa75
commit
3d9c28af93
3 changed files with 25 additions and 0 deletions
|
@ -27,6 +27,10 @@ class Note < ApplicationRecord
|
||||||
def values
|
def values
|
||||||
constants.map {|const| self.const_get(const)}
|
constants.map {|const| self.const_get(const)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value?(val)
|
||||||
|
values.include?(val)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
5
changelogs/unreleased/sh-fix-special-role-error-500.yml
Normal file
5
changelogs/unreleased/sh-fix-special-role-error-500.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix first-time contributor notes not rendering
|
||||||
|
merge_request: 31340
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -913,6 +913,22 @@ describe Note do
|
||||||
end
|
end
|
||||||
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
|
describe '#parent' do
|
||||||
it 'returns project for project notes' do
|
it 'returns project for project notes' do
|
||||||
project = create(:project)
|
project = create(:project)
|
||||||
|
|
Loading…
Reference in a new issue