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
Fixed nasty bugs in controller/mixins/responder and its specs.
fabien (author)
Fri Jul 25 03:43:34 -0700 2008
commit  105a206920f0fb4bea379e968770527fcac6876b
tree    7093017540aed63e8af13486e17667f66c5b20bc
parent  df7306d346d9ee721f15e3adb0367f0c188f2e66
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
237
238
239
240
241
 
242
243
244
...
255
256
257
258
 
 
259
260
261
...
273
274
275
276
277
 
278
279
280
...
195
196
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
199
200
...
216
217
218
 
 
219
220
221
222
...
233
234
235
 
236
237
238
239
240
...
252
253
254
 
 
255
256
257
258
0
@@ -195,27 +195,6 @@ module Merb
0
       @_provided_formats ||= class_provided_formats.dup
0
     end
0
     
0
- # Sets the provided formats for this action. Usually, you would use a
0
- # combination of provides, only_provides and does_not_provide to manage
0
- # this, but you can set it directly.
0
- #
0
- # ==== Parameters
0
- # *formats<Symbol>:: A list of formats to be passed to provides.
0
- #
0
- # ==== Raises
0
- # Merb::ResponderMixin::ContentTypeAlreadySet::
0
- # Content negotiation already occured, and the content_type is set.
0
- #
0
- # ==== Returns
0
- # Array[Symbol]:: List of formats passed in.
0
- def _set_provided_formats(*formats)
0
- if @_content_type
0
- raise ContentTypeAlreadySet, "Cannot modify provided_formats because content_type has already been set"
0
- end
0
- provides(*formats)
0
- end
0
- alias :_provided_formats= :_set_provided_formats
0
-
0
     # Adds formats to the list of provided formats for this particular request.
0
     # Usually used to add formats to a single action. See also the
0
     # controller-level provides that affects all actions in a controller.
0
@@ -237,8 +216,7 @@ module Merb
0
       if @_content_type
0
         raise ContentTypeAlreadySet, "Cannot modify provided_formats because content_type has already been set"
0
       end
0
- @_provided_formats ||= []
0
- @_provided_formats |= formats
0
+ @_provided_formats = self._provided_formats | formats # merges with class_provided_formats if not already
0
     end
0
 
0
     # Sets list of provided formats for this particular request. Usually used
0
@@ -255,7 +233,8 @@ module Merb
0
     #---
0
     # @public
0
     def only_provides(*formats)
0
- _set_provided_formats(*formats)
0
+ @_provided_formats = []
0
+ provides(*formats)
0
     end
0
     
0
     # Removes formats from the list of provided formats for this particular
0
@@ -273,8 +252,7 @@ module Merb
0
     #---
0
     # @public
0
     def does_not_provide(*formats)
0
- formats.flatten!
0
- self._provided_formats -= formats
0
+ @_provided_formats -= formats.flatten
0
     end
0
     
0
     # Do the content negotiation:
...
34
35
36
 
 
 
 
 
 
 
37
38
39
...
34
35
36
37
38
39
40
41
42
43
44
45
46
0
@@ -34,6 +34,13 @@ module Merb::Test::Fixtures::Controllers
0
     end
0
   end
0
 
0
+ class ClassAndLocalProvides < Responder
0
+ provides :html
0
+ def index
0
+ provides :xml
0
+ render
0
+ end
0
+ end
0
 
0
   class ClassOnlyProvides < Responder
0
     only_provides :text, :xml
...
13
14
15
16
 
17
18
19
...
23
24
25
26
 
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
...
53
54
55
56
 
57
58
59
60
61
 
62
63
64
65
 
 
 
 
 
 
 
 
 
 
66
67
 
68
69
70
71
72
 
73
74
75
76
77
 
78
79
80
81
82
 
83
84
85
86
87
 
 
 
 
88
89
90
91
92
 
 
 
93
94
95
...
13
14
15
 
16
17
18
19
...
23
24
25
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
...
67
68
69
 
70
71
72
73
74
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
97
98
99
100
101
102
103
104
105
106
107
 
108
109
110
 
 
 
111
112
113
114
115
116
117
 
 
118
119
120
121
122
123
0
@@ -13,7 +13,7 @@ describe Merb::Controller, " responds" do
0
     dispatch_to(Merb::Test::Fixtures::Controllers::HtmlDefault, :index).body.should == "HTML: Default"
0
   end
0
 
0
- it "should use other mime-types if they are provided on the class level" do
0
+ it "should use other mime-types if they are provided on the controller-level" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, {}, :http_accept => "application/xml")
0
     controller.body.should == "<XML:Class provides='true' />"
0
   end
0
@@ -23,10 +23,24 @@ describe Merb::Controller, " responds" do
0
       should raise_error(Merb::ControllerExceptions::NotAcceptable)
0
   end
0
 
0
- it "should use mime-types that are provided at the local level" do
0
+ it "should use mime-types that are provided at the action-level" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::LocalProvides, :index, {}, :http_accept => "application/xml")
0
     controller.body.should == "<XML:Local provides='true' />"
0
   end
0
+
0
+ it "should use mime-types that are provided at the controller-level as well as the action-level (controller)" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, {}, :http_accept => "text/html")
0
+ controller.class_provided_formats.should == [:html]
0
+ controller._provided_formats.should == [:html, :xml]
0
+ controller.body.should == "HTML: Class and Local"
0
+ end
0
+
0
+ it "should use mime-types that are provided at the controller-level as well as the action-level (action)" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, {}, :http_accept => "application/xml")
0
+ controller.class_provided_formats.should == [:html]
0
+ controller._provided_formats.should == [:html, :xml]
0
+ controller.body.should == "<XML:ClassAndLocalProvides provides='true' />"
0
+ end
0
 
0
   it "should use the first mime-type when accepting anything */*" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "*/*")
0
@@ -53,43 +67,57 @@ describe Merb::Controller, " responds" do
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
+ it "should select the format based on params supplied to it with controller-level provides" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, :format => "xml")
0
     controller.content_type.should == :xml
0
   end
0
   
0
- it "should select the format based on params supplied to it with instance provides" do
0
+ it "should select the format based on params supplied to it with action-level provides" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::LocalProvides, :index, :format => "xml")
0
     controller.content_type.should == :xml
0
   end
0
   
0
+ it "should select the format based on params supplied to it with controller and action provides (controller)" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, :format => "html")
0
+ controller.content_type.should == :html
0
+ end
0
+
0
+ it "should select the format based on params supplied to it with controller and action provides (action)" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, :format => "xml")
0
+ controller.content_type.should == :xml
0
+ end
0
+
0
   it "should properly add formats when only_provides is called in action" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::OnlyProvides, :index, {}, :http_accept => "application/xml")
0
+ controller._provided_formats.should == [:text, :xml]
0
     controller.content_type.should == :xml
0
   end
0
 
0
   it "should properly remove formats when only_provides is called in action" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::OnlyProvides, :index, {}, :http_accept => "application/html")
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::OnlyProvides, :index, {}, :http_accept => "text/html")
0
     lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
0
   end
0
 
0
   it "should properly add formats when only_provides is called in controller" do
0
     controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassOnlyProvides, :index, {}, :http_accept => "application/xml")
0
+ controller._provided_formats.should == [:text, :xml]
0
     controller.content_type.should == :xml
0
   end
0
 
0
   it "should properly remove formats when only_provides is called in controller" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassOnlyProvides, :index, {}, :http_accept => "application/html")
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassOnlyProvides, :index, {}, :http_accept => "text/html")
0
     lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
0
   end
0
-
0
- it "should properly remove formats when does_not_provide is called in action" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::OnlyProvides, :index, {}, :http_accept => "application/html")
0
+
0
+ it "should properly remove formats when does_not_provide is called in controller" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassDoesntProvides, :index, {}, :http_accept => "text/html")
0
+ controller._provided_formats.should == [:xml]
0
     lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
0
   end
0
 
0
- it "should properly remove formats when does_not_provide is called in controller" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassOnlyProvides, :index, {}, :http_accept => "application/html")
0
+ it "should properly remove formats when does_not_provide is called in action" do
0
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::DoesntProvide, :index, {}, :http_accept => "text/html")
0
+ controller._provided_formats.should == [:xml]
0
     lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
0
   end
0
   

Comments

    No one has commented yet.