rc_rails 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG +355 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock.development +117 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +71 -0
  7. data/Rakefile +33 -0
  8. data/Todo.txt +1 -0
  9. data/lib/rc_rails.rb +9 -0
  10. data/lib/resources_controller/actions.rb +147 -0
  11. data/lib/resources_controller/active_record/saved.rb +15 -0
  12. data/lib/resources_controller/helper.rb +123 -0
  13. data/lib/resources_controller/include_actions.rb +37 -0
  14. data/lib/resources_controller/named_route_helper.rb +154 -0
  15. data/lib/resources_controller/railtie.rb +14 -0
  16. data/lib/resources_controller/request_path_introspection.rb +83 -0
  17. data/lib/resources_controller/resource_methods.rb +32 -0
  18. data/lib/resources_controller/singleton_actions.rb +21 -0
  19. data/lib/resources_controller/specification.rb +119 -0
  20. data/lib/resources_controller/version.rb +3 -0
  21. data/lib/resources_controller.rb +849 -0
  22. data/resources_controller.gemspec +29 -0
  23. data/spec/app/database.yml +5 -0
  24. data/spec/app/views/accounts/show.html.erb +0 -0
  25. data/spec/app/views/addresses/edit.html.erb +0 -0
  26. data/spec/app/views/addresses/index.html.erb +0 -0
  27. data/spec/app/views/addresses/new.html.erb +0 -0
  28. data/spec/app/views/addresses/show.html.erb +0 -0
  29. data/spec/app/views/admin/forums/create.html.erb +0 -0
  30. data/spec/app/views/admin/forums/destroy.html.erb +0 -0
  31. data/spec/app/views/admin/forums/edit.html.erb +0 -0
  32. data/spec/app/views/admin/forums/index.html.erb +0 -0
  33. data/spec/app/views/admin/forums/new.html.erb +0 -0
  34. data/spec/app/views/admin/forums/show.html.erb +0 -0
  35. data/spec/app/views/admin/forums/update.html.erb +0 -0
  36. data/spec/app/views/comments/edit.html.erb +0 -0
  37. data/spec/app/views/comments/index.html.erb +0 -0
  38. data/spec/app/views/comments/new.html.erb +0 -0
  39. data/spec/app/views/comments/show.html.erb +0 -0
  40. data/spec/app/views/forum_posts/edit.html.erb +0 -0
  41. data/spec/app/views/forum_posts/index.html.erb +0 -0
  42. data/spec/app/views/forum_posts/new.html.erb +0 -0
  43. data/spec/app/views/forum_posts/show.html.erb +0 -0
  44. data/spec/app/views/forums/create.html.erb +0 -0
  45. data/spec/app/views/forums/destroy.html.erb +0 -0
  46. data/spec/app/views/forums/edit.html.erb +0 -0
  47. data/spec/app/views/forums/index.html.erb +0 -0
  48. data/spec/app/views/forums/new.html.erb +0 -0
  49. data/spec/app/views/forums/show.html.erb +0 -0
  50. data/spec/app/views/forums/update.html.erb +0 -0
  51. data/spec/app/views/infos/edit.html.erb +0 -0
  52. data/spec/app/views/infos/show.html.erb +0 -0
  53. data/spec/app/views/interests/index.html.erb +0 -0
  54. data/spec/app/views/interests/show.html.erb +0 -0
  55. data/spec/app/views/owners/edit.html.erb +0 -0
  56. data/spec/app/views/owners/new.html.erb +0 -0
  57. data/spec/app/views/owners/show.html.erb +0 -0
  58. data/spec/app/views/tags/index.html.erb +0 -0
  59. data/spec/app/views/tags/new.html.erb +0 -0
  60. data/spec/app/views/tags/show.html.erb +0 -0
  61. data/spec/app/views/users/edit.html.erb +0 -0
  62. data/spec/app/views/users/index.html.erb +0 -0
  63. data/spec/app/views/users/show.html.erb +0 -0
  64. data/spec/app.rb +315 -0
  65. data/spec/controllers/accounts_controller_spec.rb +77 -0
  66. data/spec/controllers/addresses_controller_spec.rb +346 -0
  67. data/spec/controllers/admin_forums_controller_spec.rb +638 -0
  68. data/spec/controllers/comments_controller_spec.rb +380 -0
  69. data/spec/controllers/comments_controller_with_models_spec.rb +202 -0
  70. data/spec/controllers/forum_posts_controller_spec.rb +426 -0
  71. data/spec/controllers/forums_controller_spec.rb +694 -0
  72. data/spec/controllers/infos_controller_spec.rb +71 -0
  73. data/spec/controllers/interests_controller_via_forum_spec.rb +80 -0
  74. data/spec/controllers/interests_controller_via_user_spec.rb +114 -0
  75. data/spec/controllers/owners_controller_spec.rb +277 -0
  76. data/spec/controllers/resource_saved_spec.rb +47 -0
  77. data/spec/controllers/resource_service_in_forums_controller_spec.rb +37 -0
  78. data/spec/controllers/resource_service_in_infos_controller_spec.rb +36 -0
  79. data/spec/controllers/resource_service_in_interests_controller_via_forum_spec.rb +51 -0
  80. data/spec/controllers/tags_controller_spec.rb +83 -0
  81. data/spec/controllers/tags_controller_via_account_info_spec.rb +131 -0
  82. data/spec/controllers/tags_controller_via_forum_post_comment_spec.rb +144 -0
  83. data/spec/controllers/tags_controller_via_forum_post_spec.rb +133 -0
  84. data/spec/controllers/tags_controller_via_forum_spec.rb +173 -0
  85. data/spec/controllers/tags_controller_via_user_address_spec.rb +130 -0
  86. data/spec/controllers/users_controller_spec.rb +248 -0
  87. data/spec/lib/action_view_helper_spec.rb +143 -0
  88. data/spec/lib/bug_0001_spec.rb +22 -0
  89. data/spec/lib/include_actions_spec.rb +35 -0
  90. data/spec/lib/load_enclosing_resources_spec.rb +245 -0
  91. data/spec/lib/request_path_introspection_spec.rb +130 -0
  92. data/spec/lib/resource_methods_spec.rb +204 -0
  93. data/spec/lib/resources_controller_spec.rb +57 -0
  94. data/spec/models/comment_saved_spec.rb +24 -0
  95. data/spec/rspec_generator_task.rb +105 -0
  96. data/spec/spec_helper.rb +17 -0
  97. data/spec/verify_rcov.rb +52 -0
  98. metadata +193 -0
@@ -0,0 +1,694 @@
1
+ require 'spec_helper'
2
+
3
+ describe ForumsController do
4
+ describe "Routing shortcuts for Forums should map" do
5
+
6
+ before(:each) do
7
+ @forum = mock('Forum')
8
+ @forum.stub!(:to_param).and_return('2')
9
+ Forum.stub!(:find).and_return(@forum)
10
+ get :show, :id => "2"
11
+ end
12
+
13
+ it "resources_path to /forums" do
14
+ controller.resources_path.should == '/forums'
15
+ end
16
+
17
+ it "resources_path(:foo => 'bar') to /forums?foo=bar" do
18
+ controller.resources_path(:foo => 'bar').should == '/forums?foo=bar'
19
+ end
20
+
21
+ it "resource_path to /forums/2" do
22
+ controller.resource_path.should == '/forums/2'
23
+ end
24
+
25
+ it "resource_path(:foo => 'bar') to /forums/2?foo=bar" do
26
+ controller.resource_path(:foo => 'bar').should == '/forums/2?foo=bar'
27
+ end
28
+
29
+ it "resource_path(9) to /forums/9" do
30
+ controller.resource_path(9).should == '/forums/9'
31
+ end
32
+
33
+ it "resource_path(9, :foo => 'bar') to /forums/2?foo=bar" do
34
+ controller.resource_path(9, :foo => 'bar').should == '/forums/9?foo=bar'
35
+ end
36
+
37
+ it "edit_resource_path to /forums/2/edit" do
38
+ controller.edit_resource_path.should == '/forums/2/edit'
39
+ end
40
+
41
+ it "edit_resource_path(9) to /forums/9/edit" do
42
+ controller.edit_resource_path(9).should == '/forums/9/edit'
43
+ end
44
+
45
+ it "new_resource_path to /forums/new" do
46
+ controller.new_resource_path.should == '/forums/new'
47
+ end
48
+
49
+ it "resources_url to http://test.host/forums" do
50
+ controller.resources_url.should == 'http://test.host/forums'
51
+ end
52
+
53
+ it "resource_url to http://test.host/forums/2" do
54
+ controller.resource_url.should == 'http://test.host/forums/2'
55
+ end
56
+
57
+ it "resource_url(9) to http://test.host/forums/9" do
58
+ controller.resource_url(9).should == 'http://test.host/forums/9'
59
+ end
60
+
61
+ it "edit_resource_url to http://test.host/forums/2/edit" do
62
+ controller.edit_resource_url.should == 'http://test.host/forums/2/edit'
63
+ end
64
+
65
+ it "edit_resource_url(9) to http://test.host/forums/9/edit" do
66
+ controller.edit_resource_url(9).should == 'http://test.host/forums/9/edit'
67
+ end
68
+
69
+ it "new_resource_url to http://test.host/forums/new" do
70
+ controller.new_resource_url.should == 'http://test.host/forums/new'
71
+ end
72
+
73
+ it "resource_interests_path to /forums/2/interests" do
74
+ controller.resource_interests_path.should == "/forums/2/interests"
75
+ end
76
+
77
+ it "resource_interests_path(:foo => 'bar') to /forums/2/interests?foo=bar" do
78
+ controller.resource_interests_path(:foo => 'bar').should == '/forums/2/interests?foo=bar'
79
+ end
80
+
81
+ it "resource_interests_path(9) to /forums/9/interests" do
82
+ controller.resource_interests_path(9).should == "/forums/9/interests"
83
+ end
84
+
85
+ it "resource_interests_path(9, :foo => 'bar') to /forums/9/interests?foo=bar" do
86
+ controller.resource_interests_path(9, :foo => 'bar').should == "/forums/9/interests?foo=bar"
87
+ end
88
+
89
+ it "resource_interest_path(5) to /forums/2/interests/5" do
90
+ controller.resource_interest_path(5).should == "/forums/2/interests/5"
91
+ end
92
+
93
+ it "resource_interest_path(9,5) to /forums/9/interests/5" do
94
+ controller.resource_interest_path(9,5).should == "/forums/9/interests/5"
95
+ end
96
+
97
+ it "resource_interest_path(9,5, :foo => 'bar') to /forums/9/interests/5?foo=bar" do
98
+ controller.resource_interest_path(9, 5, :foo => 'bar').should == "/forums/9/interests/5?foo=bar"
99
+ end
100
+
101
+ it 'new_resource_interest_path(9) to /forums/9/interests/new' do
102
+ controller.new_resource_interest_path(9).should == "/forums/9/interests/new"
103
+ end
104
+
105
+ it 'edit_resource_interest_path(5) to /forums/2/interests/5/edit' do
106
+ controller.edit_resource_interest_path(5).should == "/forums/2/interests/5/edit"
107
+ end
108
+
109
+ it 'edit_resource_interest_path(9,5) to /forums/9/interests/5/edit' do
110
+ controller.edit_resource_interest_path(9,5).should == "/forums/9/interests/5/edit"
111
+ end
112
+
113
+ it "respond_to?(:edit_resource_interest_path) should == true" do
114
+ controller.should respond_to(:edit_resource_interest_path)
115
+ end
116
+
117
+ it "resource_users_path should raise informative NoMethodError" do
118
+ lambda{ controller.resource_users_path }.should raise_error(ResourcesController::CantMapRoute, <<-end_str
119
+ Tried to map :resource_users_path to :forum_users_path,
120
+ which doesn't exist. You may not have defined the route in config/routes.rb.
121
+
122
+ Or, if you have unconventianal route names or name prefixes, you may need
123
+ to explicictly set the :route option in resources_controller_for, and set
124
+ the :name_prefix option on your enclosing resources.
125
+
126
+ Currently:
127
+ :route is 'forum'
128
+ generated name_prefix is ''
129
+ end_str
130
+ )
131
+ end
132
+
133
+ it "enclosing_resource_path should raise informative NoMethodError" do
134
+ lambda{ controller.enclosing_resource_path }.should raise_error(NoMethodError, "Tried to map :enclosing_resource_path but there is no enclosing_resource for this controller")
135
+ end
136
+
137
+ it "any_old_missing_method should raise NoMethodError" do
138
+ lambda{ controller.any_old_missing_method }.should raise_error(NoMethodError)
139
+ end
140
+
141
+ it "respond_to?(:resource_users_path) should == false" do
142
+ controller.should_not respond_to(:resource_users_path)
143
+ end
144
+ end
145
+
146
+ describe ForumsController, " (checking that non actions are hidden)" do
147
+ it "should only have CRUD actions as action_methods" do
148
+ (@controller.class.send(:action_methods) & Set.new(['resource', 'resources'])).should be_empty
149
+ end
150
+ end
151
+
152
+ describe ForumsController, " requesting garbage url" do
153
+ it "should raise ResourcesController::Specification::NoClassFoundError" do
154
+ lambda { get :index, :resource_path => "/forums/\ncrayzeee" }.should raise_error(ResourcesController::Specification::NoClassFoundError)
155
+ end
156
+ end
157
+
158
+ describe ForumsController, " requesting / (testing resource_path)" do
159
+ it "should route to { :controller => 'forums', :action => 'index', :resource_path => '/forums' } from GET /" do
160
+ {:get => "/"}.should route_to(:controller => 'forums', :action => 'index', :resource_path => '/forums')
161
+ end
162
+
163
+ before(:each) do
164
+ @mock_forums = mock('forums')
165
+ Forum.stub!(:all).and_return(@mock_forums)
166
+ end
167
+
168
+ def do_get
169
+ get :index, :resource_path => '/forums'
170
+ end
171
+
172
+ it "should be successful" do
173
+ do_get
174
+ response.should be_success
175
+ end
176
+
177
+ it "should render index.rhtml" do
178
+ do_get
179
+ response.should render_template(:index)
180
+ end
181
+
182
+ it "should find all forums" do
183
+ Forum.should_receive(:all).and_return(@mock_forums)
184
+ do_get
185
+ end
186
+
187
+ it "should assign the found forums for the view" do
188
+ do_get
189
+ assigns[:forums].should == @mock_forums
190
+ end
191
+ end
192
+
193
+ describe ForumsController, " requesting /create_forum (testing resource_method)" do
194
+ it "should generate params { :controller => 'forums', :action => 'create', :resource_path => '/forums', :resource_method => :post } from GET /create_forum" do
195
+ {:get => "/create_forum"}.should route_to(:controller => 'forums', :action => 'create', :resource_path => '/forums', :resource_method => :post)
196
+ end
197
+
198
+ before(:each) do
199
+ @mock_forum = mock('Forum')
200
+ @mock_forum.stub!(:save).and_return(true)
201
+ @mock_forum.stub!(:to_param).and_return("1")
202
+ Forum.stub!(:new).and_return(@mock_forum)
203
+ end
204
+
205
+ def do_post
206
+ post :create, :forum => {:name => 'Forum'}, :resource_path => '/forums', :resource_method => :post
207
+
208
+ end
209
+
210
+ it "should create a new forum" do
211
+ Forum.should_receive(:new).with({'name' => 'Forum'}).and_return(@mock_forum)
212
+ do_post
213
+ end
214
+
215
+ it "should set the flash notice" do
216
+ do_post
217
+ flash[:notice].should == "Forum was successfully created."
218
+ end
219
+
220
+ it "should redirect to the new forum" do
221
+ do_post
222
+ response.should be_redirect
223
+ response.redirect_url.should == "http://test.host/forums/1"
224
+ end
225
+ end
226
+
227
+ describe "Requesting /forums using GET" do
228
+
229
+ before(:each) do
230
+ @mock_forums = mock('forums')
231
+ Forum.stub!(:all).and_return(@mock_forums)
232
+ end
233
+
234
+ def do_get
235
+ get :index
236
+ end
237
+
238
+ it "should be successful" do
239
+ do_get
240
+ response.should be_success
241
+ end
242
+
243
+ it "should render index.rhtml" do
244
+ do_get
245
+ response.should render_template(:index)
246
+ end
247
+
248
+ it "should find all forums" do
249
+ Forum.should_receive(:all).and_return(@mock_forums)
250
+ do_get
251
+ end
252
+
253
+ it "should assign the found forums for the view" do
254
+ do_get
255
+ assigns[:forums].should == @mock_forums
256
+ end
257
+ end
258
+
259
+ describe "Requesting /forums.xml using GET" do
260
+
261
+ before(:each) do
262
+ @mock_forums = mock('forums')
263
+ @mock_forums.stub!(:to_xml).and_return("XML")
264
+ Forum.stub!(:all).and_return(@mock_forums)
265
+ end
266
+
267
+ def do_get
268
+ @request.env["HTTP_ACCEPT"] = "application/xml"
269
+ get :index
270
+ end
271
+
272
+ it "should be successful" do
273
+ do_get
274
+ response.should be_success
275
+ end
276
+
277
+ it "should find all forums" do
278
+ Forum.should_receive(:all).and_return(@mock_forums)
279
+ do_get
280
+ end
281
+
282
+ it "should render the found forums as xml" do
283
+ @mock_forums.should_receive(:to_xml).and_return("XML")
284
+ do_get
285
+ response.body.should eql("XML")
286
+ end
287
+ end
288
+
289
+ describe "Requesting /forums using XHR GET" do
290
+
291
+ before(:each) do
292
+ @mock_forums = mock('forums')
293
+ Forum.stub!(:all).and_return(@mock_forums)
294
+ end
295
+
296
+ def do_get
297
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
298
+ xhr :get, :index
299
+ end
300
+
301
+ it "should be successful" do
302
+ do_get
303
+ response.should be_success
304
+ end
305
+
306
+ it "should find all forums" do
307
+ Forum.should_receive(:all).and_return(@mock_forums)
308
+ do_get
309
+ end
310
+
311
+ it "should render index.rjs" do
312
+ do_get
313
+ response.should render_template('index')
314
+ end
315
+ end
316
+
317
+ describe "Requesting /forums/1 using GET" do
318
+
319
+ before(:each) do
320
+ @mock_forum = mock('Forum')
321
+ Forum.stub!(:find).and_return(@mock_forum)
322
+ end
323
+
324
+ def do_get
325
+ get :show, :id => "1"
326
+ end
327
+
328
+ it "should be successful" do
329
+ do_get
330
+ response.should be_success
331
+ end
332
+
333
+ it "should render show.rhtml" do
334
+ do_get
335
+ response.should render_template(:show)
336
+ end
337
+
338
+ it "should find the forum requested" do
339
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
340
+ do_get
341
+ end
342
+
343
+ it "should assign the found forum for the view" do
344
+ do_get
345
+ assigns[:forum].should == @mock_forum
346
+ end
347
+ end
348
+
349
+ describe "Requesting /forums/1.xml using GET" do
350
+
351
+ before(:each) do
352
+ @mock_forum = mock('Forum')
353
+ @mock_forum.stub!(:to_xml).and_return("XML")
354
+ Forum.stub!(:find).and_return(@mock_forum)
355
+ end
356
+
357
+ def do_get
358
+ @request.env["HTTP_ACCEPT"] = "application/xml"
359
+ get :show, :id => "1"
360
+ end
361
+
362
+ it "should be successful" do
363
+ do_get
364
+ response.should be_success
365
+ end
366
+
367
+ it "should find the forum requested" do
368
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
369
+ do_get
370
+ end
371
+
372
+ it "should render the found forum as xml" do
373
+ @mock_forum.should_receive(:to_xml).and_return("XML")
374
+ do_get
375
+ response.body.should eql("XML")
376
+ end
377
+ end
378
+
379
+ describe "Requesting /forums/1 using XHR GET" do
380
+
381
+ before(:each) do
382
+ @mock_forum = mock('Forum')
383
+ Forum.stub!(:find).and_return(@mock_forum)
384
+ end
385
+
386
+ def do_get
387
+ xhr :get, :show, :id => "1"
388
+ end
389
+
390
+ it "should be successful" do
391
+ do_get
392
+ response.should be_success
393
+ end
394
+
395
+ it "should render show.rjs" do
396
+ do_get
397
+ response.should render_template('show')
398
+ end
399
+
400
+ it "should find the forum requested" do
401
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
402
+ do_get
403
+ end
404
+
405
+ it "should assign the found forum for the view" do
406
+ do_get
407
+ assigns[:forum].should == @mock_forum
408
+ end
409
+ end
410
+
411
+ describe "Requesting /forums/new using GET" do
412
+
413
+ before(:each) do
414
+ @mock_forum = mock('Forum')
415
+ Forum.stub!(:new).and_return(@mock_forum)
416
+ end
417
+
418
+ def do_get
419
+ get :new
420
+ end
421
+
422
+ it "should be successful" do
423
+ do_get
424
+ response.should be_success
425
+ end
426
+
427
+ it "should render new.rhtml" do
428
+ do_get
429
+ response.should render_template(:new)
430
+ end
431
+
432
+ it "should create an new forum" do
433
+ Forum.should_receive(:new).and_return(@mock_forum)
434
+ do_get
435
+ end
436
+
437
+ it "should not save the new forum" do
438
+ @mock_forum.should_not_receive(:save)
439
+ do_get
440
+ end
441
+
442
+ it "should assign the new forum for the view" do
443
+ do_get
444
+ assigns[:forum].should == @mock_forum
445
+ end
446
+ end
447
+
448
+ describe "Requesting /forums/1/edit using GET" do
449
+
450
+ before(:each) do
451
+ @mock_forum = mock('Forum')
452
+ Forum.stub!(:find).and_return(@mock_forum)
453
+ end
454
+
455
+ def do_get
456
+ get :edit, :id => "1"
457
+ end
458
+
459
+ it "should be successful" do
460
+ do_get
461
+ response.should be_success
462
+ end
463
+
464
+ it "should render edit.rhtml" do
465
+ do_get
466
+ response.should render_template(:edit)
467
+ end
468
+
469
+ it "should find the forum requested" do
470
+ Forum.should_receive(:find).and_return(@mock_forum)
471
+ do_get
472
+ end
473
+
474
+ it "should assign the found Forum for the view" do
475
+ do_get
476
+ assigns(:forum).should equal(@mock_forum)
477
+ end
478
+ end
479
+
480
+ describe "Requesting /forums using POST" do
481
+
482
+ before(:each) do
483
+ @mock_forum = mock('Forum')
484
+ @mock_forum.stub!(:save).and_return(true)
485
+ @mock_forum.stub!(:to_param).and_return("1")
486
+ Forum.stub!(:new).and_return(@mock_forum)
487
+ end
488
+
489
+ def do_post
490
+ post :create, :forum => {:name => 'Forum'}
491
+ end
492
+
493
+ it "should create a new forum" do
494
+ Forum.should_receive(:new).with({'name' => 'Forum'}).and_return(@mock_forum)
495
+ do_post
496
+ end
497
+
498
+ it "should set the flash notice" do
499
+ do_post
500
+ flash[:notice].should == "Forum was successfully created."
501
+ end
502
+
503
+ it "should redirect to the new forum" do
504
+ do_post
505
+ response.should be_redirect
506
+ response.redirect_url.should == "http://test.host/forums/1"
507
+ end
508
+ end
509
+
510
+ describe "Requesting /forums using XHR POST" do
511
+
512
+ before(:each) do
513
+ @mock_forum = mock('Forum')
514
+ @mock_forum.stub!(:save).and_return(true)
515
+ @mock_forum.stub!(:to_param).and_return("1")
516
+ Forum.stub!(:new).and_return(@mock_forum)
517
+ end
518
+
519
+ def do_post
520
+ xhr :post, :create, :forum => {:name => 'Forum'}
521
+ end
522
+
523
+ it "should create a new forum" do
524
+ Forum.should_receive(:new).with({'name' => 'Forum'}).and_return(@mock_forum)
525
+ do_post
526
+ end
527
+
528
+ it "should not set the flash notice" do
529
+ do_post
530
+ flash[:notice].should == nil
531
+ end
532
+
533
+ it "should render create.rjs" do
534
+ do_post
535
+ response.should render_template('create')
536
+ end
537
+
538
+ it "should render new.rjs if unsuccesful" do
539
+ @mock_forum.stub!(:save).and_return(false)
540
+ do_post
541
+ response.should render_template('new')
542
+ end
543
+ end
544
+
545
+ describe "Requesting /forums/1 using PUT" do
546
+
547
+ before(:each) do
548
+ @mock_forum = mock('Forum').as_null_object
549
+ @mock_forum.stub!(:to_param).and_return("1")
550
+ Forum.stub!(:find).and_return(@mock_forum)
551
+ end
552
+
553
+ def do_update
554
+ put :update, :id => "1"
555
+ end
556
+
557
+ it "should find the forum requested" do
558
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
559
+ do_update
560
+ end
561
+
562
+ it "should set the flash notice" do
563
+ do_update
564
+ flash[:notice].should == "Forum was successfully updated."
565
+ end
566
+
567
+ it "should update the found forum" do
568
+ @mock_forum.should_receive(:update_attributes)
569
+ do_update
570
+ assigns(:forum).should == @mock_forum
571
+ end
572
+
573
+ it "should assign the found forum for the view" do
574
+ do_update
575
+ assigns(:forum).should == @mock_forum
576
+ end
577
+
578
+ it "should redirect to the forum" do
579
+ do_update
580
+ response.should be_redirect
581
+ response.redirect_url.should == "http://test.host/forums/1"
582
+ end
583
+ end
584
+
585
+ describe "Requesting /forums/1 using XHR PUT" do
586
+
587
+ before(:each) do
588
+ @mock_forum = mock('Forum').as_null_object
589
+ @mock_forum.stub!(:to_param).and_return("1")
590
+ Forum.stub!(:find).and_return(@mock_forum)
591
+ end
592
+
593
+ def do_update
594
+ xhr :put, :update, :id => "1"
595
+ end
596
+
597
+ it "should find the forum requested" do
598
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
599
+ do_update
600
+ end
601
+
602
+ it "should update the found forum" do
603
+ @mock_forum.should_receive(:update_attributes)
604
+ do_update
605
+ assigns(:forum).should == @mock_forum
606
+ end
607
+
608
+ it "should not set the flash notice" do
609
+ do_update
610
+ flash[:notice].should == nil
611
+ end
612
+
613
+ it "should assign the found forum for the view" do
614
+ do_update
615
+ assigns(:forum).should == @mock_forum
616
+ end
617
+
618
+ it "should render update.rjs" do
619
+ do_update
620
+ response.should render_template('update')
621
+ end
622
+
623
+ it "should render edit.rjs, on unsuccessful save" do
624
+ @mock_forum.stub!(:update_attributes).and_return(false)
625
+ do_update
626
+ response.should render_template('edit')
627
+ end
628
+ end
629
+
630
+ describe "Requesting /forums/1 using DELETE" do
631
+
632
+ before(:each) do
633
+ @mock_forum = mock('Forum').as_null_object
634
+ Forum.stub!(:find).and_return(@mock_forum)
635
+ end
636
+
637
+ def do_delete
638
+ delete :destroy, :id => "1"
639
+ end
640
+
641
+ it "should find the forum requested" do
642
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
643
+ do_delete
644
+ end
645
+
646
+ it "should call destroy on the found forum" do
647
+ @mock_forum.should_receive(:destroy)
648
+ do_delete
649
+ end
650
+
651
+ it "should set the flash notice" do
652
+ do_delete
653
+ flash[:notice].should == 'Forum was successfully destroyed.'
654
+ end
655
+
656
+ it "should redirect to the forums list" do
657
+ do_delete
658
+ response.should be_redirect
659
+ response.redirect_url.should == "http://test.host/forums"
660
+ end
661
+ end
662
+
663
+ describe "Requesting /forums/1 using XHR DELETE" do
664
+
665
+ before(:each) do
666
+ @mock_forum = mock('Forum').as_null_object
667
+ Forum.stub!(:find).and_return(@mock_forum)
668
+ end
669
+
670
+ def do_delete
671
+ xhr :delete, :destroy, :id => "1"
672
+ end
673
+
674
+ it "should find the forum requested" do
675
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
676
+ do_delete
677
+ end
678
+
679
+ it "should not set the flash notice" do
680
+ do_delete
681
+ flash[:notice].should == nil
682
+ end
683
+
684
+ it "should call destroy on the found forum" do
685
+ @mock_forum.should_receive(:destroy)
686
+ do_delete
687
+ end
688
+
689
+ it "should render destroy.rjs" do
690
+ do_delete
691
+ response.should render_template('destroy')
692
+ end
693
+ end
694
+ end