Update OS detection for 0.9.9 client's User-Agent format

This commit is contained in:
Marcin Kulik 2014-11-05 13:40:27 +00:00
parent 68f0907526
commit 3207c4a65f
2 changed files with 36 additions and 6 deletions

View File

@ -74,12 +74,12 @@ class AsciicastDecorator < ApplicationDecorator
end end
def guess_os(text) def guess_os(text)
if text =~ /Linux/ if text =~ /Linux/i
'Linux' 'Linux'
elsif text =~ /Darwin/ elsif text =~ /Darwin/i
'OS X' 'OS X'
else else
text.split(' ', 2)[0] text.split(/[\s-]/, 2)[0].to_s.titleize
end end
end end

View File

@ -12,7 +12,7 @@ describe AsciicastDecorator do
let(:method) { :os } let(:method) { :os }
context 'when user_agent is present' do context 'when user_agent is present' do
context 'and the OS is Linux' do context 'and the OS is Linux (pre-0.9.9 client)' do
before do before do
asciicast.user_agent = asciicast.user_agent =
"asciinema/0.9.7 CPython/3.3.1 " \ "asciinema/0.9.7 CPython/3.3.1 " \
@ -22,7 +22,17 @@ describe AsciicastDecorator do
it { should == 'Linux' } it { should == 'Linux' }
end end
context 'and the OS is OS X' do context 'and the OS is Linux (0.9.9+ client)' do
before do
asciicast.user_agent =
"asciinema/0.9.9 gc/go1.3 " \
"linux-amd64"
end
it { should == 'Linux' }
end
context 'and the OS is OS X (pre-0.9.9 client)' do
before do before do
asciicast.user_agent = asciicast.user_agent =
"asciinema/0.9.7 CPython/2.7.4 " \ "asciinema/0.9.7 CPython/2.7.4 " \
@ -32,7 +42,17 @@ describe AsciicastDecorator do
it { should == 'OS X' } it { should == 'OS X' }
end end
context 'and the OS is other' do context 'and the OS is OS X (0.9.9+ client)' do
before do
asciicast.user_agent =
"asciinema/0.9.9 gc/go1.3 " \
"darwin-amd64"
end
it { should == 'OS X' }
end
context 'and the OS is other (pre-0.9.9 client)' do
before do before do
asciicast.user_agent = "asciinema/0.9.7 CPython/2.7.4 Jola/Misio-Foo" asciicast.user_agent = "asciinema/0.9.7 CPython/2.7.4 Jola/Misio-Foo"
end end
@ -41,6 +61,16 @@ describe AsciicastDecorator do
should == 'Jola' should == 'Jola'
end end
end end
context 'and the OS is other (0.9.9+ client)' do
before do
asciicast.user_agent = "asciinema/0.9.9 gc/go1.3 jola-amd64"
end
it 'should return first token titleized' do
should == 'Jola'
end
end
end end
context 'when uname is present' do context 'when uname is present' do