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
6 changes: 5 additions & 1 deletion app/decorators/device_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ def happened_at

def nice_name
browser = BrowserCache.parse(device.user_agent)
os = browser.platform.name
os_version = browser.platform.version&.split('.')&.first
os = "#{os} #{os_version}" if os_version

I18n.t(
'account.index.device',
browser: "#{browser.name} #{browser.version}",
os: "#{browser.platform.name} #{browser.platform.version.split('.').first}",
os: os,
Copy link
Copy Markdown
Contributor

@aduth aduth Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do something like... ?

Suggested change
os: os,
os: [browser.platform.name, browser.platform.version&.split('.')&.first].compact.join(' '),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would need the null-safe navigator, but otherwise yep

)
end
end
9 changes: 9 additions & 0 deletions spec/decorators/device_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@
it 'gives a shortened os and browser name' do
expect(decorator.nice_name).to eq('Chrome 58 on Windows 10')
end

it 'does not fail if OS version cannot be parsed' do
# This user agent currently does not parse the OS version
user_agent = 'Mozilla/5.0 (X11; CrOS armv7l 11316.165.0) AppleWebKit/537.36 (KHTML, '\
'like Gecko) Chrome/72.0.3626.122 Safari/537.36'
device.user_agent = user_agent

expect(decorator.nice_name).to eq('Chrome 72 on Chrome OS')
end
end
end