Commit 49b0fe02689365104ba52b427922168824e9274d

Authored by Bob Lail
1 parent bd17fa78
Exists in master and in 1 other branch production

use Josh Peek's useragent gem to parse HTTP_USER_AGENT

Gemfile
... ... @@ -8,6 +8,7 @@ gem 'will_paginate'
8 8 gem 'devise', '~> 1.1.8'
9 9 gem 'lighthouse-api'
10 10 gem 'redmine_client', :git => "git://github.com/oruen/redmine_client.git"
  11 +gem 'useragent', '~> 0.3.1'
11 12  
12 13 platform :ruby do
13 14 gem 'bson_ext', '~> 1.2'
... ...
Gemfile.lock
... ... @@ -109,6 +109,7 @@ GEM
109 109 treetop (1.4.9)
110 110 polyglot (>= 0.3.1)
111 111 tzinfo (0.3.25)
  112 + useragent (0.3.1)
112 113 warden (1.0.3)
113 114 rack (>= 1.0.0)
114 115 webmock (1.6.2)
... ... @@ -132,5 +133,6 @@ DEPENDENCIES
132 133 redmine_client!
133 134 rspec (~> 2.5)
134 135 rspec-rails (~> 2.5)
  136 + useragent (~> 0.3.1)
135 137 webmock
136 138 will_paginate
... ...
app/models/notice.rb
... ... @@ -46,6 +46,11 @@ class Notice
46 46 })
47 47 end
48 48  
  49 + def user_agent
  50 + agent_string = env_vars['HTTP_USER_AGENT']
  51 + agent_string.blank? ? nil : UserAgent.parse(agent_string)
  52 + end
  53 +
49 54 def request
50 55 read_attribute(:request) || {}
51 56 end
... ...
spec/models/notice_spec.rb
... ... @@ -105,6 +105,19 @@ describe Notice do
105 105 end
106 106 end
107 107  
  108 + describe "user agent" do
  109 + it "should be parsed and human-readable" do
  110 + notice = Factory.build(:notice, :request => {'cgi-data' => {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16'}})
  111 + notice.user_agent.browser.should == 'Chrome'
  112 + notice.user_agent.version.to_s.should =~ /^10\.0/
  113 + end
  114 +
  115 + it "should be nil if HTTP_USER_AGENT is blank" do
  116 + notice = Factory.build(:notice)
  117 + notice.user_agent.should == nil
  118 + end
  119 + end
  120 +
108 121 describe "email notifications" do
109 122 before do
110 123 @app = Factory(:app_with_watcher)
... ...