merb 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/README +23 -160
  2. data/Rakefile +15 -14
  3. data/app_generators/merb/merb_generator.rb +4 -3
  4. data/app_generators/merb/templates/Rakefile +1 -6
  5. data/app_generators/merb/templates/app/mailers/views/layout/{application.erb → application.html.erb} +0 -0
  6. data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +1 -0
  7. data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +1 -0
  8. data/app_generators/merb/templates/app/views/layout/application.html.erb +2 -2
  9. data/app_generators/merb/templates/config/dependencies.rb +1 -1
  10. data/app_generators/merb/templates/config/router.rb +4 -1
  11. data/app_generators/merb/templates/spec/spec_helper.rb +2 -3
  12. data/lib/autotest/merb_rspec.rb +1 -0
  13. data/lib/merb/abstract_controller.rb +31 -2
  14. data/lib/merb/controller.rb +5 -5
  15. data/lib/merb/core_ext/get_args.rb +5 -1
  16. data/lib/merb/exceptions.rb +17 -0
  17. data/lib/merb/generators/merb_app/merb_app.rb +4 -1
  18. data/lib/merb/generators/merb_plugin.rb +4 -1
  19. data/lib/merb/logger.rb +5 -1
  20. data/lib/merb/mail_controller.rb +1 -1
  21. data/lib/merb/mailer.rb +2 -2
  22. data/lib/merb/mixins/controller.rb +5 -1
  23. data/lib/merb/mixins/render.rb +57 -27
  24. data/lib/merb/part_controller.rb +1 -1
  25. data/lib/merb/request.rb +2 -2
  26. data/lib/merb/server.rb +33 -5
  27. data/lib/merb/template/erubis.rb +1 -1
  28. data/lib/merb.rb +15 -5
  29. data/merb_generators/resource/resource_generator.rb +9 -2
  30. data/spec/fixtures/config/merb.yml +18 -0
  31. data/spec/fixtures/controllers/dispatch_spec_controllers.rb +227 -0
  32. data/spec/fixtures/controllers/render_spec_controllers.rb +115 -0
  33. data/spec/fixtures/foo.rb +3 -0
  34. data/spec/fixtures/mailers/views/layout/application.html.erb +3 -0
  35. data/spec/fixtures/mailers/views/layout/application.text.erb +3 -0
  36. data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +1 -0
  37. data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +1 -0
  38. data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +1 -0
  39. data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +1 -0
  40. data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +1 -0
  41. data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +1 -0
  42. data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +1 -0
  43. data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +1 -0
  44. data/spec/fixtures/models/router_spec_models.rb +20 -0
  45. data/spec/fixtures/parts/views/layout/todo_part.html.erb +3 -0
  46. data/spec/fixtures/parts/views/layout/todo_part.xml.erb +3 -0
  47. data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +1 -0
  48. data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +1 -0
  49. data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +1 -0
  50. data/spec/fixtures/parts/views/todo_part/list.html.erb +3 -0
  51. data/spec/fixtures/sample.txt +1 -0
  52. data/spec/fixtures/views/erubis.html.erb +1 -0
  53. data/spec/fixtures/views/examples/_erubis.html.erb +1 -0
  54. data/spec/fixtures/views/examples/_haml.html.haml +1 -0
  55. data/spec/fixtures/views/examples/_markaby.html.mab +1 -0
  56. data/spec/fixtures/views/examples/_throw_content.html.erb +6 -0
  57. data/spec/fixtures/views/examples/hello.xml.builder +1 -0
  58. data/spec/fixtures/views/examples/js.js.erb +1 -0
  59. data/spec/fixtures/views/examples/template_catch_content.html.erb +15 -0
  60. data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +6 -0
  61. data/spec/fixtures/views/examples/template_throw_content.html.erb +10 -0
  62. data/spec/fixtures/views/exceptions/admin_access_required.html.erb +1 -0
  63. data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +1 -0
  64. data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +1 -0
  65. data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +1 -0
  66. data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +1 -0
  67. data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +1 -0
  68. data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +1 -0
  69. data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +1 -0
  70. data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
  71. data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +1 -0
  72. data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +1 -0
  73. data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +1 -0
  74. data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
  75. data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
  76. data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +1 -0
  77. data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +1 -0
  78. data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +1 -0
  79. data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +4 -0
  80. data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +1 -0
  81. data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +1 -0
  82. data/spec/fixtures/views/haml.html.haml +1 -0
  83. data/spec/fixtures/views/haml.xml.haml +2 -0
  84. data/spec/fixtures/views/layout/application.html.erb +1 -0
  85. data/spec/fixtures/views/layout/application.xml.erb +1 -0
  86. data/spec/fixtures/views/layout/nested/example.html.erb +1 -0
  87. data/spec/fixtures/views/markaby.html.mab +1 -0
  88. data/spec/fixtures/views/nested/example/test.html.erb +1 -0
  89. data/spec/fixtures/views/partials/_erubis.html.erb +1 -0
  90. data/spec/fixtures/views/partials/_erubis_collection.html.erb +1 -0
  91. data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +1 -0
  92. data/spec/fixtures/views/partials/_erubis_new.html.erb +1 -0
  93. data/spec/fixtures/views/partials/_haml.html.haml +1 -0
  94. data/spec/fixtures/views/partials/_haml_collection.html.haml +1 -0
  95. data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +1 -0
  96. data/spec/fixtures/views/partials/_haml_new.html.haml +1 -0
  97. data/spec/fixtures/views/partials/_markaby.html.mab +1 -0
  98. data/spec/fixtures/views/partials/_markaby_collection.html.mab +1 -0
  99. data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +1 -0
  100. data/spec/fixtures/views/partials/_markaby_new.html.mab +1 -0
  101. data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +1 -0
  102. data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +1 -0
  103. data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +1 -0
  104. data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +4 -0
  105. data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +7 -0
  106. data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +7 -0
  107. data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +15 -0
  108. data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +15 -0
  109. data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +4 -0
  110. data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +12 -0
  111. data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +11 -0
  112. data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +14 -0
  113. data/spec/fixtures/views/test.dir/the_template.html.erb +1 -0
  114. data/spec/merb/abstract_controller_spec.rb +37 -0
  115. data/spec/merb/caching_spec.rb +102 -0
  116. data/spec/merb/config_spec.rb +29 -0
  117. data/spec/merb/controller_filters_spec.rb +188 -0
  118. data/spec/merb/controller_spec.rb +144 -0
  119. data/spec/merb/cookie_store_spec.rb +85 -0
  120. data/spec/merb/core_ext_spec.rb +430 -0
  121. data/spec/merb/dispatch_spec.rb +514 -0
  122. data/spec/merb/fake_request_spec.rb +72 -0
  123. data/spec/merb/form_control_mixin_spec.rb +431 -0
  124. data/spec/merb/generator_spec.rb +121 -0
  125. data/spec/merb/handler_spec.rb +169 -0
  126. data/spec/merb/mail_controller_spec.rb +144 -0
  127. data/spec/merb/mailer_spec.rb +87 -0
  128. data/spec/merb/multipart_spec.rb +49 -0
  129. data/spec/merb/part_controller_spec.rb +92 -0
  130. data/spec/merb/plugins_spec.rb +80 -0
  131. data/spec/merb/render_spec.rb +378 -0
  132. data/spec/merb/request_spec.rb +243 -0
  133. data/spec/merb/responder_spec.rb +561 -0
  134. data/spec/merb/router_spec.rb +726 -0
  135. data/spec/merb/template_spec.rb +41 -0
  136. data/spec/merb/upload_handler_spec.rb +101 -0
  137. data/spec/merb/view_context_spec.rb +148 -0
  138. data/spec/spec_generator_helper.rb +19 -0
  139. data/spec/spec_helper.rb +88 -0
  140. metadata +203 -65
  141. data/lib/merb/caching/store/memcache.rb +0 -20
  142. data/script/destroy +0 -14
  143. data/script/generate +0 -14
@@ -0,0 +1,514 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../fixtures/controllers/dispatch_spec_controllers'
3
+
4
+ $TESTING = true
5
+
6
+ describe Merb::Dispatcher do
7
+
8
+ before(:all) do
9
+ Merb::Server.config[:allow_reloading] = false
10
+ Merb::Router.prepare do |r|
11
+ r.resource :icon
12
+ r.resources :posts, :member => {:stats => [:get, :put]},
13
+ :collection => {:filter => [:get]} do |post|
14
+ post.resources :comments, :member => {:stats => [:get, :put]}
15
+ post.resource :profile
16
+ end
17
+ r.resources :as do |a|
18
+ a.resources :bs do |b|
19
+ b.resources :cs
20
+ end
21
+ end
22
+ r.match("/admin") do |admin|
23
+ admin.resources :tags
24
+ end
25
+ r.default_routes
26
+ end
27
+ puts Merb::Router.named_routes[:new_comment].generate(:post_id => 1)
28
+ end
29
+
30
+ it "should not allow private and protected methods to be called" do
31
+ controller, action = request(:get, '/foo/call_filters')
32
+ controller.status.should == Merb::ControllerExceptions::ActionNotFound::STATUS
33
+ end
34
+
35
+ it "should handle request: GET /foo/bar and return Foo#bar" do
36
+ controller, action = request(:get, '/foo/bar')
37
+ e = controller.params[:exception]
38
+ controller.class.should == Foo
39
+ action.should == "bar"
40
+ controller.body.should == "bar"
41
+ end
42
+
43
+ it "should handle request: GET /foo/bar/1.xml and return Foo#bar format xml" do
44
+ controller, action = request(:get, '/foo/bar/1.xml')
45
+ controller.class.should == Foo
46
+ controller.params[:format].should == 'xml'
47
+ action.should == "bar"
48
+ controller.body.should == "bar"
49
+ end
50
+
51
+ it "should handle request: GET /foo/bar.xml and return Foo#bar format xml" do
52
+ controller, action = request(:get, '/foo/bar.xml')
53
+ controller.class.should == Foo
54
+ controller.params[:format].should == 'xml'
55
+ action.should == "bar"
56
+ controller.body.should == "bar"
57
+ end
58
+
59
+ it "should handle request: GET /foo.xml and return Foo#index format xml" do
60
+ controller, action = request(:get, '/foo.xml')
61
+ controller.class.should == Foo
62
+ controller.params[:format].should == 'xml'
63
+ action.should == "index"
64
+ controller.body.should == "index"
65
+ end
66
+
67
+ it "should handle request: GET /foo and return Foo#index" do
68
+ controller, action = request(:get, '/foo')
69
+ controller.class.should == Foo
70
+ action.should == "index"
71
+ controller.body.should == "index"
72
+ end
73
+
74
+ it "should handle request: GET /icon and return Icon#show" do
75
+ controller, action = request(:get, '/icon')
76
+ controller.class.should == Icon
77
+ action.should == "show"
78
+ controller.body.should == :show
79
+ end
80
+
81
+ it "should handle request: GET /icon.xml and return Icon#show format xml" do
82
+ controller, action = request(:get, '/icon.xml')
83
+ controller.class.should == Icon
84
+ action.should == "show"
85
+ controller.params[:format].should == 'xml'
86
+ controller.body.should == :show
87
+ end
88
+
89
+ it "should handle request: GET /icon/new and return Icon#new" do
90
+ controller, action = request(:get, '/icon/new')
91
+ controller.class.should == Icon
92
+ action.should == "new"
93
+ controller.body.should == :new
94
+ end
95
+
96
+ it "should handle request: GET /icon;edit and return Icon#edit" do
97
+ controller, action = request(:get, '/icon;edit')
98
+ controller.class.should == Icon
99
+ action.should == "edit"
100
+ controller.body.should == :edit
101
+ end
102
+
103
+ it "should handle request: GET /icon/edit and return Icon#edit" do
104
+ controller, action = request(:get, '/icon/edit')
105
+ controller.class.should == Icon
106
+ action.should == "edit"
107
+ controller.body.should == :edit
108
+ end
109
+
110
+ it "should handle request: POST /icon and return Icon#create" do
111
+ controller, action = request(:post, '/icon')
112
+ controller.class.should == Icon
113
+ action.should == "create"
114
+ controller.body.should == :create
115
+ end
116
+
117
+ it "should handle request: PUT /icon and return Icon#update" do
118
+ controller, action = request(:put, '/icon')
119
+ controller.class.should == Icon
120
+ action.should == "update"
121
+ controller.body.should == :update
122
+ end
123
+
124
+ it "should handle request: DELETE /icon and return Icon#destroy" do
125
+ controller, action = request(:delete, '/icon')
126
+ controller.class.should == Icon
127
+ action.should == "destroy"
128
+ controller.body.should == :destroy
129
+ end
130
+
131
+ it "should handle request: GET /admin/tags and return Tags#index" do
132
+ controller, action = request(:get, '/admin/tags')
133
+ controller.class.should == Tags
134
+ action.should == "index"
135
+ controller.body.should == :index
136
+ end
137
+
138
+ it "should handle request: GET /admin/tags.xml and return Tags#index format xml" do
139
+ controller, action = request(:get, '/admin/tags.xml')
140
+ controller.class.should == Tags
141
+ action.should == "index"
142
+ controller.params[:format].should == 'xml'
143
+ controller.body.should == :index
144
+ end
145
+
146
+ it "should handle request: GET /posts and return Posts#index" do
147
+ controller, action = request(:get, '/posts')
148
+ controller.class.should == Posts
149
+ action.should == "index"
150
+ controller.body.should == :index
151
+ end
152
+
153
+ it "should handle request: GET /posts;filter and return Posts#filter" do
154
+ controller, action = request(:get, '/posts;filter')
155
+ controller.class.should == Posts
156
+ action.should == "filter"
157
+ controller.body.should == :filter
158
+ end
159
+
160
+ it "should handle request: GET /posts/filter and return Posts#filter" do
161
+ controller, action = request(:get, '/posts/filter')
162
+ controller.class.should == Posts
163
+ action.should == "filter"
164
+ controller.body.should == :filter
165
+ end
166
+
167
+ it "should handle request: GET /posts/1/comments and return Comments#index with post_id == 1" do
168
+ controller, action = request(:get, '/posts/1/comments')
169
+ controller.class.should == Comments
170
+ action.should == "index"
171
+ controller.body.should == :index
172
+ end
173
+
174
+ it "should handle request: GET /posts/1/profile and return Profile#show with post_id == 1" do
175
+ controller, action = request(:get, '/posts/1/profile')
176
+ controller.class.should == Profile
177
+ action.should == "show"
178
+ controller.body.should == :show
179
+ end
180
+
181
+ it "should handle request: GET /posts/1/profile.xml and return Profile#show with post_id == 1" do
182
+ controller, action = request(:get, '/posts/1/profile.xml')
183
+ controller.class.should == Profile
184
+ controller.params[:format].should == 'xml'
185
+ action.should == "show"
186
+ controller.body.should == :show
187
+ end
188
+
189
+ it "should handle request: GET /posts.xml and return Posts#index format xml" do
190
+ controller, action = request(:get, '/posts.xml')
191
+ controller.class.should == Posts
192
+ controller.params[:format].should == 'xml'
193
+ action.should == "index"
194
+ controller.body.should == :index
195
+ end
196
+
197
+ it "should handle request: GET /posts/1 and return Posts#show" do
198
+ controller, action = request(:get, '/posts/1')
199
+ controller.class.should == Posts
200
+ action.should == "show"
201
+ controller.params[:id].should == '1'
202
+ controller.body.should == :show
203
+ end
204
+
205
+ it "should handle request: GET /posts/1/comments/1 and return Comments#show with post_id == 1" do
206
+ controller, action = request(:get, '/posts/1/comments/1')
207
+ controller.class.should == Comments
208
+ controller.params[:id].should == '1'
209
+ controller.params[:post_id].should == '1'
210
+ action.should == "show"
211
+ controller.body.should == :show
212
+ end
213
+
214
+ it "should handle request: GET /as/1/bs/1 and return Bs#show with as_id == 1 & id == 1" do
215
+ controller, action = request(:get, '/as/1/bs/1')
216
+ controller.class.should == Bs
217
+ controller.params[:id].should == '1'
218
+ controller.params[:a_id].should == '1'
219
+ action.should == "show"
220
+ controller.body.should == :show
221
+ end
222
+
223
+ it "should handle request: GET /as/1/bs/1/cs and return Cs#show with a_id == 1 & b_id == 1" do
224
+ controller, action = request(:get, '/as/1/bs/1/cs')
225
+ controller.class.should == Cs
226
+ controller.params[:b_id].should == '1'
227
+ controller.params[:a_id].should == '1'
228
+ action.should == "index"
229
+ controller.body.should == :index
230
+ end
231
+
232
+ it "should handle request: GET /as/1/bs/1/cs/1 and return Bs#show with as_id == 1 & b_id == 1 & id == 1" do
233
+ controller, action = request(:get, '/as/1/bs/1/cs/1')
234
+ controller.class.should == Cs
235
+ controller.params[:id].should == '1'
236
+ controller.params[:a_id].should == '1'
237
+ controller.params[:b_id].should == '1'
238
+ action.should == "show"
239
+ controller.body.should == :show
240
+ end
241
+
242
+ it "should handle request: GET /posts/1.xml and return Posts#show format xml" do
243
+ controller, action = request(:get, '/posts/1.xml')
244
+ controller.class.should == Posts
245
+ controller.params[:format].should == 'xml'
246
+ action.should == "show"
247
+ controller.params[:id].should == '1'
248
+ controller.body.should == :show
249
+ end
250
+
251
+ it "should handle request: GET /posts/1/comments/1.xml and return Comments#show with post_id == 1 and format xml" do
252
+ controller, action = request(:get, '/posts/1/comments/1.xml')
253
+ controller.class.should == Comments
254
+ controller.params[:id].should == '1'
255
+ controller.params[:format].should == 'xml'
256
+ controller.params[:post_id].should == '1'
257
+ action.should == "show"
258
+ controller.body.should == :show
259
+ end
260
+
261
+ it "should handle request: GET /posts/new and return Posts#new" do
262
+ controller, action = request(:get, '/posts/new')
263
+ controller.class.should == Posts
264
+ action.should == "new"
265
+ controller.body.should == :new
266
+ end
267
+
268
+ it "should handle request: GET /posts/1/comments/new and return Comments#new with post_id == 1" do
269
+ controller, action = request(:get, '/posts/1/comments/new')
270
+ controller.class.should == Comments
271
+ action.should == "new"
272
+ controller.body.should == :new
273
+ end
274
+
275
+ it "should handle request: GET /posts/1;edit and return Posts#edit" do
276
+ controller, action = request(:get, '/posts/1;edit')
277
+ controller.class.should == Posts
278
+ action.should == "edit"
279
+ controller.params[:id].should == '1'
280
+ controller.body.should == :edit
281
+ end
282
+ it "should handle request: GET /posts/1/edit and return Posts#edit" do
283
+ controller, action = request(:get, '/posts/1/edit')
284
+ controller.class.should == Posts
285
+ action.should == "edit"
286
+ controller.params[:id].should == '1'
287
+ controller.body.should == :edit
288
+ end
289
+
290
+ it "should handle request: GET /posts/1/comments/1;edit and return Comments#edit with post_id == 1" do
291
+ controller, action = request(:get, '/posts/1/comments/1;edit')
292
+ controller.class.should == Comments
293
+ controller.params[:id].should == '1'
294
+ controller.params[:post_id].should == '1'
295
+ action.should == "edit"
296
+ controller.body.should == :edit
297
+ end
298
+
299
+ it "should handle request: GET /posts/1/comments/1/edit and return Comments#edit with post_id == 1" do
300
+ controller, action = request(:get, '/posts/1/comments/1/edit')
301
+ controller.class.should == Comments
302
+ controller.params[:id].should == '1'
303
+ controller.params[:post_id].should == '1'
304
+ action.should == "edit"
305
+ controller.body.should == :edit
306
+ end
307
+
308
+ it "should handle request: POST /posts and return Posts#create" do
309
+ controller, action = request(:post, '/posts')
310
+ controller.class.should == Posts
311
+ action.should == "create"
312
+ controller.body.should == :create
313
+ end
314
+
315
+ it "should handle request: POST /posts/1/comments and return Comments#create with post_id == 1" do
316
+ controller, action = request(:post, '/posts/1/comments')
317
+ controller.class.should == Comments
318
+ action.should == "create"
319
+ controller.body.should == :create
320
+ end
321
+
322
+ it "should handle request: POST /posts/1/comments.xml and return Comments#create with post_id == 1 and format xml" do
323
+ controller, action = request(:post, '/posts/1/comments.xml')
324
+ controller.class.should == Comments
325
+ controller.params[:format].should == 'xml'
326
+ action.should == "create"
327
+ controller.body.should == :create
328
+ end
329
+
330
+
331
+ it "should handle request: POST /posts.xml and return Posts#create format xml" do
332
+ controller, action = request(:post, '/posts.xml')
333
+ controller.class.should == Posts
334
+ controller.params[:format].should == 'xml'
335
+ action.should == "create"
336
+ controller.body.should == :create
337
+ end
338
+
339
+ it "should handle request: PUT /posts/1 and return Posts#update" do
340
+ controller, action = request(:put, '/posts/1')
341
+ controller.class.should == Posts
342
+ action.should == "update"
343
+ controller.params[:id].should == '1'
344
+ controller.body.should == :update
345
+ end
346
+
347
+ it "should handle request: PUT /posts/1/comments/1 and return Comments#update with post_id == 1" do
348
+ controller, action = request(:put, '/posts/1/comments/1')
349
+ controller.class.should == Comments
350
+ action.should == "update"
351
+ controller.params[:post_id].should == '1'
352
+ controller.params[:id].should == '1'
353
+ controller.body.should == :update
354
+ end
355
+
356
+ it "should handle request: PUT /posts/1.xml and return Posts#update format xml" do
357
+ controller, action = request(:put, '/posts/1.xml')
358
+ controller.class.should == Posts
359
+ controller.params[:format].should == 'xml'
360
+ controller.params[:id].should == '1'
361
+ action.should == "update"
362
+ controller.body.should == :update
363
+ end
364
+
365
+ it "should handle request: PUT /posts/1/comments/1.xml and return Comments#update with post_id == 1 and format xml" do
366
+ controller, action = request(:put, '/posts/1/comments/1.xml')
367
+ controller.class.should == Comments
368
+ action.should == "update"
369
+ controller.params[:post_id].should == '1'
370
+ controller.params[:format].should == 'xml'
371
+ controller.params[:id].should == '1'
372
+ controller.body.should == :update
373
+ end
374
+
375
+ it "should handle request: DELETE /posts/1 and return Posts#destroy" do
376
+ controller, action = request(:delete, '/posts/1')
377
+ controller.class.should == Posts
378
+ controller.params[:id].should == '1'
379
+ action.should == "destroy"
380
+ controller.body.should == :destroy
381
+ end
382
+
383
+ it "should handle request: DELETE /posts/1/comments/1 and return Comments#destroy with post_id == 1" do
384
+ controller, action = request(:delete, '/posts/1/comments/1')
385
+ controller.class.should == Comments
386
+ controller.params[:id].should == '1'
387
+ controller.params[:post_id].should == '1'
388
+ action.should == "destroy"
389
+ controller.body.should == :destroy
390
+ end
391
+
392
+ it "should handle request: DELETE /posts/1.xml and return Posts#destroy format xml" do
393
+ controller, action = request(:delete, '/posts/1.xml')
394
+ controller.class.should == Posts
395
+ controller.params[:format].should == 'xml'
396
+ controller.params[:id].should == '1'
397
+ action.should == "destroy"
398
+ controller.body.should == :destroy
399
+ end
400
+
401
+ it "should handle request: DELETE /posts/1/comments/1.xml and return Comments#destroy with post_id == 1" do
402
+ controller, action = request(:delete, '/posts/1/comments/1.xml')
403
+ controller.class.should == Comments
404
+ controller.params[:id].should == '1'
405
+ controller.params[:format].should == 'xml'
406
+ controller.params[:post_id].should == '1'
407
+ action.should == "destroy"
408
+ controller.body.should == :destroy
409
+ end
410
+
411
+ it "should handle request: GET /posts/1;stats and return Posts#stats" do
412
+ controller, action = request(:get, '/posts/1;stats')
413
+ controller.class.should == Posts
414
+ action.should == 'stats'
415
+ controller.params[:id].should == '1'
416
+ controller.body.should == :stats
417
+ end
418
+
419
+ it "should handle request: GET /posts/1/stats and return Posts#stats" do
420
+ controller, action = request(:get, '/posts/1/stats')
421
+ controller.class.should == Posts
422
+ action.should == 'stats'
423
+ controller.params[:id].should == '1'
424
+ controller.body.should == :stats
425
+ end
426
+
427
+ it "should handle request: GET /posts/1/comments/1;stats and return Comments#stats with post_id == 1" do
428
+ controller, action = request(:get, '/posts/1/comments/1;stats')
429
+ controller.class.should == Comments
430
+ action.should == 'stats'
431
+ controller.params[:id].should == '1'
432
+ controller.params[:post_id].should == '1'
433
+ controller.body.should == :stats
434
+ end
435
+
436
+ it "should handle request: GET /posts/1/comments/1/stats and return Comments#stats with post_id == 1" do
437
+ controller, action = request(:get, '/posts/1/comments/1/stats')
438
+ controller.class.should == Comments
439
+ action.should == 'stats'
440
+ controller.params[:id].should == '1'
441
+ controller.params[:post_id].should == '1'
442
+ controller.body.should == :stats
443
+ end
444
+
445
+ it "should handle request: PUT /posts/1;stats and return Posts#stats" do
446
+ controller, action = request(:put, '/posts/1;stats')
447
+ controller.class.should == Posts
448
+ action.should == 'stats'
449
+ controller.params[:id].should == '1'
450
+ controller.body.should == :stats
451
+ end
452
+
453
+ it "should handle request: PUT /posts/1/comments/1;stats and return Comments#stats with post_id == 1" do
454
+ controller, action = request(:get, '/posts/1/comments/1;stats')
455
+ controller.class.should == Comments
456
+ action.should == 'stats'
457
+ controller.params[:id].should == '1'
458
+ controller.params[:post_id].should == '1'
459
+ controller.body.should == :stats
460
+ end
461
+
462
+ it "should handle request: PUT /posts/1/comments/1/stats and return Comments#stats with post_id == 1" do
463
+ controller, action = request(:get, '/posts/1/comments/1/stats')
464
+ controller.class.should == Comments
465
+ action.should == 'stats'
466
+ controller.params[:id].should == '1'
467
+ controller.params[:post_id].should == '1'
468
+ controller.body.should == :stats
469
+ end
470
+
471
+ it "should show the custom error page" do
472
+ controller, action = request(:get, '/foo/error')
473
+ controller.body.should == "oh no!"
474
+ end
475
+
476
+ it "should show the a 404 error page" do
477
+ controller, action = request(:get, '/foo/raise404')
478
+ controller.status.should == Merb::ControllerExceptions::NotFound::STATUS
479
+ end
480
+
481
+ it "should not show the a 404 error page if you call with upcase url" do
482
+ controller, action = request(:get, '/Posts/1')
483
+ controller.status.should == Merb::ControllerExceptions::NotFound::STATUS
484
+ end
485
+
486
+ it "should not show the a 404 error page if you call with - in the controller name with no explicit route" do
487
+ controller, action = request(:get, '/pos-ts/1')
488
+ controller.status.should == Merb::ControllerExceptions::NotFound::STATUS
489
+ end
490
+
491
+ if defined?(ParseTreeArray)
492
+ it "should support parameterized actions with required arguments" do
493
+ controller, action = request(:get, '/bar/foo/1')
494
+ controller.body.should == "1"
495
+ end
496
+
497
+ it "should support parameterized actions with required and optional arguments" do
498
+ controller, action = request(:get, '/bar/bar?a=1&b=3')
499
+ controller.body.should == "1 3"
500
+ end
501
+
502
+ it "should use optional arguments in parameters if they exist" do
503
+ controller, action = request(:get, '/bar/bar?a=1')
504
+ controller.body.should == "1 2"
505
+ end
506
+
507
+ it "should use optional arguments even if a later argument is provided" do
508
+ controller, action = request(:get, '/bar/baz?a=1&c=5')
509
+ controller.body.should == "1 2 5"
510
+ end
511
+ end
512
+
513
+
514
+ end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Merb::Test::FakeRequest, ".new(env = {}, method = 'GET', req = StringIO.new)" do
4
+ it "should create request with default enviroment" do
5
+ @mock = Merb::Test::FakeRequest.new
6
+ @mock.env.should == Merb::Test::FakeRequest::DEFAULT_ENV
7
+ end
8
+
9
+ it "should override default env values passed in HTTP format" do
10
+ @mock = Merb::Test::FakeRequest.new('HTTP_ACCEPT' => 'nothing')
11
+ @mock['HTTP_ACCEPT'].should == 'nothing'
12
+ end
13
+
14
+ it "should override default env values passed in symbol format" do
15
+ @mock = Merb::Test::FakeRequest.new(:http_accept => 'nothing')
16
+ @mock['HTTP_ACCEPT'].should == 'nothing'
17
+ end
18
+
19
+ it "should change :cookies into HTTP_COOKIE" do
20
+ @mock = Merb::Test::FakeRequest.new(:cookies => 'icanhazcookie=true')
21
+ @mock['HTTP_COOKIE'].should == 'icanhazcookie=true'
22
+ end
23
+
24
+ it "should set body to an empty StringIO" do
25
+ @mock = Merb::Test::FakeRequest.new
26
+ @mock.body.should be_kind_of(StringIO)
27
+ @mock.body.read.should == ''
28
+ end
29
+ end
30
+
31
+ describe Merb::Test::FakeRequest, ".with(path, options = {})" do
32
+ before(:each) do
33
+ @mock = Merb::Test::FakeRequest.with('/foo?bar=baz')
34
+ end
35
+
36
+ it "should set REQUEST_URI to path" do
37
+ @mock['REQUEST_URI'].should == '/foo?bar=baz'
38
+ end
39
+
40
+ it "should set PATH_INFO to path without query string" do
41
+ @mock['PATH_INFO'].should == '/foo'
42
+ end
43
+
44
+ it "should pass other options through to new" do
45
+ @mock = Merb::Test::FakeRequest.with('/foo?bar=baz', :http_accept => 'cash/money')
46
+ @mock['HTTP_ACCEPT'].should == 'cash/money'
47
+ end
48
+ end
49
+
50
+ describe Merb::Test::FakeRequest, ".post_body=(post)" do
51
+ it "should wrap post param in new StringIO" do
52
+ @mock = Merb::Test::FakeRequest.new
53
+ @mock.post_body = "hello world"
54
+ @mock.body.should be_kind_of(StringIO)
55
+ @mock.body.read.should == "hello world"
56
+ end
57
+ end
58
+
59
+ describe Merb::Test::FakeRequest, "[](key)" do
60
+ it "should return the key from @env" do
61
+ @mock = Merb::Test::FakeRequest.new(:http_accept => 'cash/money')
62
+ @mock['HTTP_ACCEPT'].should == 'cash/money'
63
+ end
64
+ end
65
+
66
+ describe Merb::Test::FakeRequest, "[]=(key, value)" do
67
+ it "should set key in @env to value" do
68
+ @mock = Merb::Test::FakeRequest.new(:http_accept => 'cash/money')
69
+ @mock['HTTP_ACCEPT'] = 'also/credit_card'
70
+ @mock['HTTP_ACCEPT'].should == 'also/credit_card'
71
+ end
72
+ end