Commit 3351b1e7 authored by Dallas Reedy's avatar Dallas Reedy

Resolve constant redefinition warning for ReassuranceOrgs Struct

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67382#note_659623967
parent b2c45ffd
...@@ -5,7 +5,14 @@ module TrialRegistrations ...@@ -5,7 +5,14 @@ module TrialRegistrations
LOGO_IMAGE_PATH = "marketing/logos/logo_%<filename>s.svg" LOGO_IMAGE_PATH = "marketing/logos/logo_%<filename>s.svg"
DEFAULT_OPACITY_CSS_CLASS_LEVEL = 5 DEFAULT_OPACITY_CSS_CLASS_LEVEL = 5
Struct.new('ReassuranceOrg', :name, :opacity_level, keyword_init: true) do class ReassuranceOrg
attr_reader :name
def initialize(name:, opacity_level: DEFAULT_OPACITY_CSS_CLASS_LEVEL)
@name = name
@opacity_level = opacity_level
end
def image_alt_text def image_alt_text
s_('InProductMarketing|%{organization_name} logo') % { organization_name: name } s_('InProductMarketing|%{organization_name} logo') % { organization_name: name }
end end
...@@ -15,21 +22,17 @@ module TrialRegistrations ...@@ -15,21 +22,17 @@ module TrialRegistrations
end end
def opacity_css_class def opacity_css_class
"gl-opacity-#{opacity_level}" "gl-opacity-#{@opacity_level}"
end
def opacity_level
self[:opacity_level] || DEFAULT_OPACITY_CSS_CLASS_LEVEL
end end
end end
def reassurance_orgs def reassurance_orgs
[ [
Struct::ReassuranceOrg.new(name: 'Siemens', opacity_level: 6), ReassuranceOrg.new(name: 'Siemens', opacity_level: 6),
Struct::ReassuranceOrg.new(name: 'Chorus'), ReassuranceOrg.new(name: 'Chorus'),
Struct::ReassuranceOrg.new(name: 'KnowBe4', opacity_level: 7), ReassuranceOrg.new(name: 'KnowBe4', opacity_level: 7),
Struct::ReassuranceOrg.new(name: 'Wish'), ReassuranceOrg.new(name: 'Wish'),
Struct::ReassuranceOrg.new(name: 'Hotjar') ReassuranceOrg.new(name: 'Hotjar')
] ]
end end
end end
......
...@@ -8,49 +8,43 @@ RSpec.describe TrialRegistrations::ReassurancesHelper do ...@@ -8,49 +8,43 @@ RSpec.describe TrialRegistrations::ReassurancesHelper do
it 'returns an array of ReassuranceOrg objects' do it 'returns an array of ReassuranceOrg objects' do
expect(reassurance_orgs).to be_an(Array) expect(reassurance_orgs).to be_an(Array)
expect(reassurance_orgs).to all(be_an_instance_of(Struct::ReassuranceOrg)) expect(reassurance_orgs).to all(be_an_instance_of(described_class::ReassuranceOrg))
end end
end end
describe 'Struct::ReassuranceOrg' do describe 'ReassuranceOrg' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:given_opacity_level) { nil } let(:org_name) { 'Foo Bar Baz' }
subject(:org) { Struct::ReassuranceOrg.new(name: 'Foo Bar Baz', opacity_level: given_opacity_level) } subject(:org) { described_class::ReassuranceOrg.new(name: org_name) }
describe '#name' do describe '#name' do
it "returns the organization's name" do it "returns the organization's name" do
expect(org.name).to eq('Foo Bar Baz') expect(org.name).to eq(org_name)
end end
end end
describe '#opacity_level' do describe '#opacity_css_class' do
where(:given_opacity_level, :expected_opacity_level) do context 'when no opacity_level is given' do
nil | 5 it 'returns a gitlab-ui utility CSS class for the default opacity level' do
5 | 5 expect(org.opacity_css_class).to eq('gl-opacity-5')
6 | 6
7 | 7
end
with_them do
it 'returns the given value or the default value' do
expect(org.opacity_level).to eq(expected_opacity_level)
end end
end end
end
describe '#opacity_css_class' do context 'when an opacity_level is given' do
where(:given_opacity_level, :expected_opacity_css_class) do subject(:org) { described_class::ReassuranceOrg.new(name: org_name, opacity_level: given_opacity_level) }
nil | 'gl-opacity-5'
5 | 'gl-opacity-5' where(:given_opacity_level, :expected_opacity_css_class) do
6 | 'gl-opacity-6' 5 | 'gl-opacity-5'
7 | 'gl-opacity-7' 6 | 'gl-opacity-6'
end 7 | 'gl-opacity-7'
end
with_them do with_them do
it 'returns a gitlab-ui utility CSS class for the opacity_level' do it 'returns a gitlab-ui utility CSS class for the opacity_level' do
expect(org.opacity_css_class).to eq(expected_opacity_css_class) expect(org.opacity_css_class).to eq(expected_opacity_css_class)
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment