Skip to content

Commit

Permalink
Allow an array of symbols as the except option
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro committed Apr 3, 2012
1 parent cca7a7b commit 5c648cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mobylette/controllers/respond_to_mobile_requests.rb
Expand Up @@ -96,7 +96,7 @@ def respond_to_mobile_requests(options = {})
# works on 1.9, but not on 1.8
#valid_options = [:fall_back, :skip_xhr_requests]
#self.mobylette_options = options.reject {|option| !valid_options.include?(option)}
options[:except] = Array(options[:except])
options[:except] = Array(options[:except]).map {|ua| ua.to_s}
self.mobylette_options = options

self.send(:include, Mobylette::Controllers::RespondToMobileRequestsMethods)
Expand Down
20 changes: 18 additions & 2 deletions spec/respond_to_mobile_requests_spec.rb
Expand Up @@ -23,12 +23,12 @@ def session

it "supports a single exception" do
controller.respond_to_mobile_requests :except => :ipad
controller.mobylette_options[:except].should == [:ipad]
controller.mobylette_options[:except].should == ['ipad']
end

it "supports multiple exceptions" do
controller.respond_to_mobile_requests :except => [:ipad, :android]
controller.mobylette_options[:except].should == [:ipad, :android]
controller.mobylette_options[:except].should == ['ipad', 'android']
end

describe "when iPad is excepted" do
Expand All @@ -44,4 +44,20 @@ def session
end

end

describe "when iPad and Android are excepted" do
let(:controller) { new_controller('android') }

context "request is Android" do
it "remains a mobile request" do
controller.respond_to_mobile_requests :except => [:ipad, :android]
controller.new.send(:is_mobile_request?).should be_true
end

it "does not respond as mobile" do
controller.respond_to_mobile_requests :except => [:ipad, :android]
controller.new.send(:respond_as_mobile?).should be_false
end
end
end
end

0 comments on commit 5c648cb

Please sign in to comment.