Improve OS detection

rails
Marcin Kulik 8 years ago
parent bb63579379
commit 635a607afa

@ -77,10 +77,12 @@ class AsciicastDecorator < ApplicationDecorator
private
def os_from_user_agent
os_part = user_agent.split(' ')[2]
os = os_part.split('/').first
guess_os(os)
if user_agent =~ %r{^asciinema/\d(\.\d+)+ [^/\s]+/[^/\s]+ (.+)$}
os = $2.sub('-', '/').split('/').first.sub(/[dD]arwin/, 'OS X')
os[0].upcase + os[1..-1]
else
'unknown'
end
end
def os_from_uname

@ -22,6 +22,16 @@ describe AsciicastDecorator do
it { should == 'Linux' }
end
context 'and the OS is *BSD (pre-0.9.9 client)' do
before do
asciicast.user_agent =
"asciinema/0.9.8 CPython/2.7.5 " \
"FreeBSD/10.0-RELEASE-p7-amd64-64bit-ELF"
end
it { should == 'FreeBSD' }
end
context 'and the OS is Linux (0.9.9+ client)' do
before do
asciicast.user_agent =

Loading…
Cancel
Save