Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/decorators/event_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

EventDecorator = Struct.new(:event) do
def event_type
return if event.event_type.blank?
I18n.t("event_types.#{event.event_type}", app_name: APP_NAME)
end

Expand Down
14 changes: 14 additions & 0 deletions spec/decorators/event_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
subject(:decorator) { EventDecorator.new(event) }

describe '#event_type' do
subject(:event_type) { decorator.event_type }

it 'returns the localized event_type' do
expect(decorator.event_type).to eq t('event_types.email_changed')
end
Expand All @@ -17,6 +19,18 @@
expect(decorator.event_type).to include(APP_NAME)
end
end

context 'for a blank event type' do
# If the database has an event type value which isn't known to the application, it will be
# parsed as nil, which can result in unexpected behavior for retrieving a string label. This
# can happen during deployment of a new event type, where old servers aren't yet aware of the
# new event type, or it can happen if values are erroneously removed from the model enum while
# existing database records still use the value.

let(:event) { build_stubbed(:event, event_type: nil) }

it { is_expected.to be_nil }
end
end

describe '#last_sign_in_location_and_ip' do
Expand Down