Improve OS detection

This commit is contained in:
Marcin Kulik 2016-07-03 08:58:39 +00:00
parent bb63579379
commit 635a607afa
2 changed files with 16 additions and 4 deletions

View File

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

View File

@ -22,6 +22,16 @@ describe AsciicastDecorator do
it { should == 'Linux' } it { should == 'Linux' }
end 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 context 'and the OS is Linux (0.9.9+ client)' do
before do before do
asciicast.user_agent = asciicast.user_agent =