Skip to content
Browse files

Allow adding and removing mobile user agents

  • Loading branch information...
1 parent 5e552b7 commit 956508ff8dd2409013ffe113c5c2cb6e1a4ba013 @sandro sandro committed Apr 2, 2012
View
8 lib/mobylette/controllers/respond_to_mobile_requests.rb
@@ -101,6 +101,14 @@ def respond_to_mobile_requests(options = {})
self.send(:include, Mobylette::Controllers::RespondToMobileRequestsMethods)
end
+
+ def add_mobile_user_agent(agent)
+ MOBILE_USER_AGENTS << agent
+ end
+
+ def remove_mobile_user_agent(agent)
+ MOBILE_USER_AGENTS.delete agent
+ end
end
private
View
10 spec/controllers/actioncontroller_base_spec.rb
@@ -6,6 +6,14 @@
ActionController::Base.respond_to?(:respond_to_mobile_requests).should be_true
end
+ it "should have the add_mobylette_user_agent method" do
+ ActionController::Base.should respond_to(:add_mobile_user_agent)
+ end
+
+ it "should have the remove_mobylette_user_agent method" do
+ ActionController::Base.should respond_to(:remove_mobile_user_agent)
+ end
+
it "should have the :is_mobile_request? method" do
# works on ruby 1.9.2, but not on 1.8.7:
#@controller.private_methods.include?(:is_mobile_request?).should be_true
@@ -19,6 +27,4 @@
@controller.send(:is_mobile_view?).should be_nil
end
-
-
end
View
16 spec/respond_to_mobile_requests_spec.rb
@@ -63,4 +63,20 @@ def session
end
end
+ describe "#add_mobile_user_agent" do
+ it "adds a user agent to the list of agents" do
+ controller.const_get(:MOBILE_USER_AGENTS).should_not include('killerapp')
+ controller.add_mobile_user_agent 'killerapp'
+ controller.const_get(:MOBILE_USER_AGENTS).should include('killerapp')
+ end
+ end
+
+ describe "#remove_mobile_user_agent" do
+ it "removes a user agent from the list of agents" do
+ controller.add_mobile_user_agent 'killerapp'
+ controller.remove_mobile_user_agent 'killerapp'
+ controller.const_get(:MOBILE_USER_AGENTS).should_not include('killerapp')
+ end
+ end
+
end

0 comments on commit 956508f

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