This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Move mobile platforms to constant. More specs.

* saves array creation for every mobile check
* specs for true and false of mobile?
  • Loading branch information...
jnunemaker committed Oct 5, 2011
1 parent 5f136b3 commit 94c376337b76e9c2a738ef64c30f5c686b01b3de
Showing with 15 additions and 3 deletions.
  1. +3 −1 lib/user_agent.rb
  2. +12 −2 spec/user_agent_spec.rb
View
@@ -71,6 +71,8 @@ module Platform
Symbian = /symbian(os)?/i
end
+ MobilePlatforms = [:android, :blackberry, :ipad, :ipod, :iphone, :symbian, :windows_phone]
+
def self.engine(string)
case string
when Engines::Webkit then :webkit
@@ -203,7 +205,7 @@ def platform
end
def mobile?
- [:android, :blackberry, :ipad, :ipod, :iphone, :symbian, :windows_phone].include? platform or name == :psp
+ MobilePlatforms.include?(platform) || name == :psp
end
def to_s
View
@@ -42,8 +42,18 @@
end
describe "#mobile?" do
- it "should return true for mobile platforms" do
- @agent.mobile?.should == false
+ it "returs true for mobile platform" do
+ agent = UserAgent.new('Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1')
+ agent.should be_mobile
+ end
+
+ it "returns true for psp" do
+ agent = UserAgent.new('PSP (PlayStation Portable); 2.00')
+ agent.should be_mobile
+ end
+
+ it "returns false for not mobile platform" do
+ @agent.should_not be_mobile
end
end

0 comments on commit 94c3763

Please sign in to comment.