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
LOGO_IMAGE_PATH = "marketing/logos/logo_%<filename>s.svg"
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
s_('InProductMarketing|%{organization_name} logo') % { organization_name: name }
end
......@@ -15,21 +22,17 @@ module TrialRegistrations
end
def opacity_css_class
"gl-opacity-#{opacity_level}"
end
def opacity_level
self[:opacity_level] || DEFAULT_OPACITY_CSS_CLASS_LEVEL
"gl-opacity-#{@opacity_level}"
end
end
def reassurance_orgs
[
Struct::ReassuranceOrg.new(name: 'Siemens', opacity_level: 6),
Struct::ReassuranceOrg.new(name: 'Chorus'),
Struct::ReassuranceOrg.new(name: 'KnowBe4', opacity_level: 7),
Struct::ReassuranceOrg.new(name: 'Wish'),
Struct::ReassuranceOrg.new(name: 'Hotjar')
ReassuranceOrg.new(name: 'Siemens', opacity_level: 6),
ReassuranceOrg.new(name: 'Chorus'),
ReassuranceOrg.new(name: 'KnowBe4', opacity_level: 7),
ReassuranceOrg.new(name: 'Wish'),
ReassuranceOrg.new(name: 'Hotjar')
]
end
end
......
......@@ -8,49 +8,43 @@ RSpec.describe TrialRegistrations::ReassurancesHelper do
it 'returns an array of ReassuranceOrg objects' do
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
describe 'Struct::ReassuranceOrg' do
describe 'ReassuranceOrg' do
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
it "returns the organization's name" do
expect(org.name).to eq('Foo Bar Baz')
expect(org.name).to eq(org_name)
end
end
describe '#opacity_level' do
where(:given_opacity_level, :expected_opacity_level) do
nil | 5
5 | 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)
describe '#opacity_css_class' do
context 'when no opacity_level is given' do
it 'returns a gitlab-ui utility CSS class for the default opacity level' do
expect(org.opacity_css_class).to eq('gl-opacity-5')
end
end
end
describe '#opacity_css_class' do
where(:given_opacity_level, :expected_opacity_css_class) do
nil | 'gl-opacity-5'
5 | 'gl-opacity-5'
6 | 'gl-opacity-6'
7 | 'gl-opacity-7'
end
context 'when an opacity_level is given' do
subject(:org) { described_class::ReassuranceOrg.new(name: org_name, opacity_level: given_opacity_level) }
where(:given_opacity_level, :expected_opacity_css_class) do
5 | 'gl-opacity-5'
6 | 'gl-opacity-6'
7 | 'gl-opacity-7'
end
with_them 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)
with_them 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)
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