Skip to content
Browse files

router patched to process lambda supports

  • Loading branch information...
1 parent a5f2724 commit 8e9369b10953b3e140649488ec872148e19ca8fa @assembler committed Apr 20, 2012
Showing with 27 additions and 3 deletions.
  1. +11 −3 lib/browsernizer/router.rb
  2. +16 −0 spec/browsernizer/router_spec.rb
View
14 lib/browsernizer/router.rb
@@ -57,15 +57,23 @@ def on_redirection_path?
@config.get_location && @config.get_location == @env["PATH_INFO"]
end
+ def raw_agent
+ ::UserAgent.parse @env["HTTP_USER_AGENT"]
+ end
+
def agent
- a = ::UserAgent.parse @env["HTTP_USER_AGENT"]
- Browser.new a.browser.to_s, a.version.to_s
+ Browser.new raw_agent.browser.to_s, raw_agent.version.to_s
end
# supported by default
def unsupported?
@config.get_supported.any? do |requirement|
- agent.meets?(requirement) === false
+ supported = if requirement.respond_to?(:call)
+ requirement.call(raw_agent)
+ else
+ agent.meets?(requirement)
+ end
+ supported === false
end
end
end
View
16 spec/browsernizer/router_spec.rb
@@ -8,6 +8,9 @@
Browsernizer::Router.new(app) do |config|
config.supported "Firefox", false
config.supported "Chrome", "7.1"
+ config.supported do |agent|
+ !(agent.browser == "Safari" && agent.mobile?)
+ end
end
end
@@ -103,6 +106,15 @@
it_behaves_like "unsupported browser"
end
+ context "Unsupported by proc" do
+ before do
+ @env = default_env.merge({
+ "HTTP_USER_AGENT" => mobile_safari_agent
+ })
+ end
+ it_behaves_like "unsupported browser"
+ end
+
def chrome_agent(version)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/#{version} Safari/535.7"
end
@@ -111,4 +123,8 @@ def firefox_agent(version)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.1) Gecko/20100101 Firefox/#{version}"
end
+ def mobile_safari_agent
+ "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419"
+ end
+
end

0 comments on commit 8e9369b

Please sign in to comment.
Something went wrong with that request. Please try again.