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

private-asciicasts
Marcin Kulik 10 years ago
parent 68f0907526
commit 3207c4a65f

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

@ -12,7 +12,7 @@ describe AsciicastDecorator do
let(:method) { :os }
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
asciicast.user_agent =
"asciinema/0.9.7 CPython/3.3.1 " \
@ -22,7 +22,17 @@ describe AsciicastDecorator do
it { should == 'Linux' }
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
asciicast.user_agent =
"asciinema/0.9.7 CPython/2.7.4 " \
@ -32,7 +42,17 @@ describe AsciicastDecorator do
it { should == 'OS X' }
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
asciicast.user_agent = "asciinema/0.9.7 CPython/2.7.4 Jola/Misio-Foo"
end
@ -41,6 +61,16 @@ describe AsciicastDecorator do
should == 'Jola'
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
context 'when uname is present' do

Loading…
Cancel
Save