GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
ix not-available vs. not-provided bug in content negotiation
ezmobius (author)
Fri Mar 07 18:17:47 -0800 2008
commit  03bb0c841a9ecab2ef58fc2b4baca31de56d97e0
tree    7faacd2ca0ec5ce1ab1dda9bbaa7afdad986b3a4
parent  b70fa60d8142c2696efea2b4d5c812ca926ab043
...
289
290
291
292
293
294
295
296
297
298
 
299
 
 
 
 
300
301
302
...
289
290
291
 
 
 
 
 
 
 
292
293
294
295
296
297
298
299
300
0
@@ -289,14 +289,12 @@ module Merb
0
       if (fmt = params[:format]) && !fmt.empty?
0
         accepts = [fmt.to_sym]
0
       else
0
- accepts = Responder.parse(request.accept).map {|t| t.to_sym}
0
- accepts.compact!
0
- end
0
- return _provided_formats.first if accepts.first == :all
0
- (accepts & _provided_formats).first || begin
0
- return _provided_formats.first unless ([:all] & accepts).empty?
0
- raise Merb::ControllerExceptions::NotAcceptable
0
+ accepts = Responder.parse(request.accept).map {|t| t.to_sym}.compact
0
       end
0
+ specifics = accepts & _provided_formats
0
+ return specifics.first unless specifics.length == 0
0
+ return _provided_formats.first if accepts.include? :all
0
+ raise Merb::ControllerExceptions::NotAcceptable
0
     end
0
 
0
     # Returns the output format for this request, based on the
...
43
44
45
46
 
47
48
49
50
 
 
 
 
 
51
52
53
...
43
44
45
 
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -43,11 +43,16 @@ describe Merb::Controller, " responds" do
0
     controller.body.should == "JS: Multi"
0
   end
0
   
0
- it "should use */* if no specific supported content-type matches are found" do
0
+ it "should pick the first mime-type if no specific supported content-type matches are *available*" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*")
0
     controller.body.should == "HTML: Multi"
0
   end
0
 
0
+ it "should pick the first mime-type if no specific supported content-type matches are actually *provided*" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "application/json, */*")
0
+ controller.body.should == "HTML: Multi"
0
+ end
0
+
0
   it "should select the format based on params supplied to it with class provides" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, :format => "xml")
0
     controller.content_type.should == :xml

Comments

    No one has commented yet.