From 3207c4a65fdb051750fcc6e28f4b2d3caf3472f3 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Wed, 5 Nov 2014 13:40:27 +0000 Subject: [PATCH] Update OS detection for 0.9.9 client's User-Agent format --- app/decorators/asciicast_decorator.rb | 6 ++-- spec/decorators/asciicast_decorator_spec.rb | 36 +++++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/decorators/asciicast_decorator.rb b/app/decorators/asciicast_decorator.rb index 8d884fb..8d1e1e6 100644 --- a/app/decorators/asciicast_decorator.rb +++ b/app/decorators/asciicast_decorator.rb @@ -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 diff --git a/spec/decorators/asciicast_decorator_spec.rb b/spec/decorators/asciicast_decorator_spec.rb index 17f8292..862fd01 100644 --- a/spec/decorators/asciicast_decorator_spec.rb +++ b/spec/decorators/asciicast_decorator_spec.rb @@ -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