diff --git a/lib/mobylette/controllers/respond_to_mobile_requests.rb b/lib/mobylette/controllers/respond_to_mobile_requests.rb index 634b3bc..3320cc7 100644 --- a/lib/mobylette/controllers/respond_to_mobile_requests.rb +++ b/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 diff --git a/spec/controllers/actioncontroller_base_spec.rb b/spec/controllers/actioncontroller_base_spec.rb index a889d2e..ef0ccd9 100644 --- a/spec/controllers/actioncontroller_base_spec.rb +++ b/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 diff --git a/spec/respond_to_mobile_requests_spec.rb b/spec/respond_to_mobile_requests_spec.rb index 32215bc..06849bb 100644 --- a/spec/respond_to_mobile_requests_spec.rb +++ b/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