Commit 49b0fe02689365104ba52b427922168824e9274d
1 parent
bd17fa78
Exists in
master
and in
1 other branch
use Josh Peek's useragent gem to parse HTTP_USER_AGENT
Showing
4 changed files
with
21 additions
and
0 deletions
Show diff stats
Gemfile
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
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) | ... | ... |