Permalink
Browse files

Adds a force option to run the custom format checks regardless

  • Loading branch information...
1 parent 7e4369c commit f1d3bd48f0b80e4700df9b7d1b02b8a6118139a5 @hassox committed Dec 15, 2008
Showing with 27 additions and 5 deletions.
  1. +2 −1 lib/merb_custom_formats/router_helper.rb
  2. +1 −1 spec/controllers.rb
  3. +24 −3 spec/merb_custom_formats_spec.rb
@@ -2,8 +2,9 @@
# Wrap your routes
def custom_formats(*formats, &block)
+ custom_options_format = extract_options_from_args!(formats) || {}
p = Proc.new do |request, params|
- if params[:format]
+ if params[:format] && !custom_options_format[:force]
params
else
formats_to_run = if formats.empty?
View
@@ -1,5 +1,5 @@
class MainController < Merb::Controller
- provides :iphone, :android, :yaml
+ provides :iphone, :android, :yaml, :xml
def index
"#{content_type.inspect}"
end
@@ -110,6 +110,14 @@
match("/foo_for_iphone").register
end
+ custom_formats(:force => true) do
+ match("/force_all(.:format)").register
+ end
+
+ custom_formats(:iphone, :force => true) do
+ match("/force_iphone(.:format)").register
+ end
+
match("/foo_with_no_custom_formats").register
end
end
@@ -144,7 +152,6 @@
it "should check all formats registered with selectors" do
response = request("/foo")
- puts Merb::CustomFormats.router_procs.keys.inspect
response.should be_successful
Viking.captures.should include(:iphone)
Viking.captures.should include(:android)
@@ -153,7 +160,6 @@
it "should set the format to :html if there is nothing matching" do
response = request("/foo")
- puts response.body.to_s
response.body.should == ":html"
end
@@ -184,7 +190,7 @@
end
it "should not run any selectors when the format is already set" do
- response = request("/foo.yaml", "User-Agent" => @iphone_ua)
+ response = request("/foo.yaml", "User-Agent" => @iphone_ua)
response.body.should == ":yaml"
Viking.captures.should_not include(:iphone)
Viking.captures.should_not include(:android)
@@ -196,6 +202,21 @@
Viking.captures.should_not include(:iphone)
Viking.captures.should_not include(:android)
end
+
+ it "should force check the custom formats when a format is set via .format" do
+ response = request("/force_all.xml")
+ response.body.should == ":xml"
+ Viking.captures.should include(:iphone)
+ Viking.captures.should include(:android)
+ end
+
+ it "should force check the custom formats for a particular format" do
+ response = request("/force_iphone.xml")
+ response.body.should == ":xml"
+ Viking.captures.should include(:iphone)
+ Viking.captures.should_not include(:android)
+ end
+
end
end

0 comments on commit f1d3bd4

Please sign in to comment.