Skip to content

Commit

Permalink
Allow adding and removing mobile user agents
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro committed Apr 3, 2012
1 parent 5e552b7 commit 956508f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/mobylette/controllers/respond_to_mobile_requests.rb
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions spec/controllers/actioncontroller_base_spec.rb
Expand Up @@ -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
Expand All @@ -19,6 +27,4 @@

@controller.send(:is_mobile_view?).should be_nil
end


end
16 changes: 16 additions & 0 deletions spec/respond_to_mobile_requests_spec.rb
Expand Up @@ -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.