Commit 6e173b56 authored by Thong Kuah's avatar Thong Kuah

Restrict method to only attributes

Rather than having the ability to call any method on this class.

As failed_pipeline and fixed_pipeline override the attribute methods, we
add special handling for these two cases.
parent de35014f
...@@ -97,7 +97,11 @@ class NotificationSetting < ApplicationRecord ...@@ -97,7 +97,11 @@ class NotificationSetting < ApplicationRecord
alias_method :fixed_pipeline?, :fixed_pipeline alias_method :fixed_pipeline?, :fixed_pipeline
def event_enabled?(event) def event_enabled?(event)
respond_to?(event) && !!public_send(event) # rubocop:disable GitlabSecurity/PublicSend # We override these two attributes, so we can't use read_attribute
return failed_pipeline if event.to_sym == :failed_pipeline
return fixed_pipeline if event.to_sym == :fixed_pipeline
has_attribute?(event) && !!read_attribute(event)
end end
def owns_notification_email def owns_notification_email
......
...@@ -118,6 +118,46 @@ RSpec.describe NotificationSetting do ...@@ -118,6 +118,46 @@ RSpec.describe NotificationSetting do
expect(subject.event_enabled?(:foo_event)).to be(false) expect(subject.event_enabled?(:foo_event)).to be(false)
end end
end end
describe 'for failed_pipeline' do
using RSpec::Parameterized::TableSyntax
where(:column, :expected) do
nil | true
true | true
false | false
end
with_them do
before do
subject.update!(failed_pipeline: column)
end
it do
expect(subject.event_enabled?(:failed_pipeline)).to eq(expected)
end
end
end
describe 'for fixed_pipeline' do
using RSpec::Parameterized::TableSyntax
where(:column, :expected) do
nil | true
true | true
false | false
end
with_them do
before do
subject.update!(fixed_pipeline: column)
end
it do
expect(subject.event_enabled?(:fixed_pipeline)).to eq(expected)
end
end
end
end end
describe '.email_events' do describe '.email_events' do
......
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