rc_rails 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,638 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::ForumsController do
4
+ describe "Routing shortcuts for Admin::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 /admin/forums" do
14
+ controller.resources_path.should == '/admin/forums'
15
+ end
16
+
17
+ it "resources_path(:foo => 'bar') to /admin/forums?foo=bar" do
18
+ controller.resources_path(:foo => 'bar').should == '/admin/forums?foo=bar'
19
+ end
20
+
21
+ it "resource_path to /admin/forums/2" do
22
+ controller.resource_path.should == '/admin/forums/2'
23
+ end
24
+
25
+ it "resource_path(:foo => 'bar') to /admin/forums/2?foo=bar" do
26
+ controller.resource_path(:foo => 'bar').should == '/admin/forums/2?foo=bar'
27
+ end
28
+
29
+ it "resource_path(9) to /admin/forums/9" do
30
+ controller.resource_path(9).should == '/admin/forums/9'
31
+ end
32
+
33
+ it "resource_path(9, :foo => 'bar') to /admin/forums/2?foo=bar" do
34
+ controller.resource_path(9, :foo => 'bar').should == '/admin/forums/9?foo=bar'
35
+ end
36
+
37
+ it "edit_resource_path to /admin/forums/2/edit" do
38
+ controller.edit_resource_path.should == '/admin/forums/2/edit'
39
+ end
40
+
41
+ it "edit_resource_path(9) to /admin/forums/9/edit" do
42
+ controller.edit_resource_path(9).should == '/admin/forums/9/edit'
43
+ end
44
+
45
+ it "new_resource_path to /admin/forums/new" do
46
+ controller.new_resource_path.should == '/admin/forums/new'
47
+ end
48
+
49
+ it "resources_url to http://test.host/admin/forums" do
50
+ controller.resources_url.should == 'http://test.host/admin/forums'
51
+ end
52
+
53
+ it "resource_url to http://test.host/admin/forums/2" do
54
+ controller.resource_url.should == 'http://test.host/admin/forums/2'
55
+ end
56
+
57
+ it "resource_url(9) to http://test.host/admin/forums/9" do
58
+ controller.resource_url(9).should == 'http://test.host/admin/forums/9'
59
+ end
60
+
61
+ it "edit_resource_url to http://test.host/admin/forums/2/edit" do
62
+ controller.edit_resource_url.should == 'http://test.host/admin/forums/2/edit'
63
+ end
64
+
65
+ it "edit_resource_url(9) to http://test.host/admin/forums/9/edit" do
66
+ controller.edit_resource_url(9).should == 'http://test.host/admin/forums/9/edit'
67
+ end
68
+
69
+ it "new_resource_url to http://test.host/admin/forums/new" do
70
+ controller.new_resource_url.should == 'http://test.host/admin/forums/new'
71
+ end
72
+
73
+ it "resource_interests_path to /admin/forums/2/interests" do
74
+ controller.resource_interests_path.should == "/admin/forums/2/interests"
75
+ end
76
+
77
+ it "resource_interests_path(:foo => 'bar') to /admin/forums/2/interests?foo=bar" do
78
+ controller.resource_interests_path(:foo => 'bar').should == '/admin/forums/2/interests?foo=bar'
79
+ end
80
+
81
+ it "resource_interests_path(9) to /admin/forums/9/interests" do
82
+ controller.resource_interests_path(9).should == "/admin/forums/9/interests"
83
+ end
84
+
85
+ it "resource_interests_path(9, :foo => 'bar') to /admin/forums/9/interests?foo=bar" do
86
+ controller.resource_interests_path(9, :foo => 'bar').should == "/admin/forums/9/interests?foo=bar"
87
+ end
88
+
89
+ it "resource_interest_path(5) to /admin/forums/2/interests/5" do
90
+ controller.resource_interest_path(5).should == "/admin/forums/2/interests/5"
91
+ end
92
+
93
+ it "resource_interest_path(9,5) to /admin/forums/9/interests/5" do
94
+ controller.resource_interest_path(9,5).should == "/admin/forums/9/interests/5"
95
+ end
96
+
97
+ it "resource_interest_path(9,5, :foo => 'bar') to /admin/forums/9/interests/5?foo=bar" do
98
+ controller.resource_interest_path(9, 5, :foo => 'bar').should == "/admin/forums/9/interests/5?foo=bar"
99
+ end
100
+
101
+ it 'new_resource_interest_path(9) to /admin/forums/9/interests/new' do
102
+ controller.new_resource_interest_path(9).should == "/admin/forums/9/interests/new"
103
+ end
104
+
105
+ it 'edit_resource_interest_path(5) to /admin/forums/2/interests/5/edit' do
106
+ controller.edit_resource_interest_path(5).should == "/admin/forums/2/interests/5/edit"
107
+ end
108
+
109
+ it 'edit_resource_interest_path(9,5) to /admin/forums/9/interests/5/edit' do
110
+ controller.edit_resource_interest_path(9,5).should == "/admin/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 CantMapRoute" do
118
+ lambda{ controller.resource_users_path }.should raise_error(ResourcesController::CantMapRoute, <<-end_str
119
+ Tried to map :resource_users_path to :admin_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 'admin_'
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 "resource_service in Admin::ForumsController" do
147
+
148
+ before(:each) do
149
+ @forum = Forum.create
150
+
151
+ get :index
152
+ @resource_service = controller.send :resource_service
153
+ end
154
+
155
+ it "should build new forum with new" do
156
+ resource = @resource_service.new
157
+ resource.should be_kind_of(Forum)
158
+ end
159
+
160
+ it "should find @forum with find(@forum.id)" do
161
+ resource = @resource_service.find(@forum.id)
162
+ resource.should == @forum
163
+ end
164
+
165
+ it "should find all forums with find(:all)" do
166
+ resources = @resource_service.find(:all)
167
+ resources.should == Forum.find(:all)
168
+ end
169
+ end
170
+
171
+ describe "Requesting /admin/forums using GET" do
172
+
173
+ before(:each) do
174
+ @mock_forums = mock('forums')
175
+ Forum.stub!(:all).and_return(@mock_forums)
176
+ end
177
+
178
+ def do_get
179
+ get :index
180
+ end
181
+
182
+ it "should be successful" do
183
+ do_get
184
+ response.should be_success
185
+ end
186
+
187
+ it "should render index.rhtml" do
188
+ do_get
189
+ response.should render_template(:index)
190
+ end
191
+
192
+ it "should find all forums" do
193
+ Forum.should_receive(:all).and_return(@mock_forums)
194
+ do_get
195
+ end
196
+
197
+ it "should assign the found forums for the view" do
198
+ do_get
199
+ assigns[:forums].should == @mock_forums
200
+ end
201
+ end
202
+
203
+ describe "Requesting /admin/forums.xml using GET" do
204
+
205
+ before(:each) do
206
+ @mock_forums = mock('forums')
207
+ @mock_forums.stub!(:to_xml).and_return("XML")
208
+ Forum.stub!(:all).and_return(@mock_forums)
209
+ end
210
+
211
+ def do_get
212
+ @request.env["HTTP_ACCEPT"] = "application/xml"
213
+ get :index
214
+ end
215
+
216
+ it "should be successful" do
217
+ do_get
218
+ response.should be_success
219
+ end
220
+
221
+ it "should find all forums" do
222
+ Forum.should_receive(:all).and_return(@mock_forums)
223
+ do_get
224
+ end
225
+
226
+ it "should render the found forums as xml" do
227
+ @mock_forums.should_receive(:to_xml).and_return("XML")
228
+ do_get
229
+ response.body.should eql("XML")
230
+ end
231
+ end
232
+
233
+ describe "Requesting /admin/forums using XHR GET" do
234
+
235
+ before(:each) do
236
+ @mock_forums = mock('forums')
237
+ Forum.stub!(:all).and_return(@mock_forums)
238
+ end
239
+
240
+ def do_get
241
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
242
+ xhr :get, :index
243
+ end
244
+
245
+ it "should be successful" do
246
+ do_get
247
+ response.should be_success
248
+ end
249
+
250
+ it "should find all forums" do
251
+ Forum.should_receive(:all).and_return(@mock_forums)
252
+ do_get
253
+ end
254
+
255
+ it "should render index.rjs" do
256
+ do_get
257
+ response.should render_template('index')
258
+ end
259
+ end
260
+
261
+ describe "Requesting /admin/forums/1 using GET" do
262
+
263
+ before(:each) do
264
+ @mock_forum = mock('Forum')
265
+ Forum.stub!(:find).and_return(@mock_forum)
266
+ end
267
+
268
+ def do_get
269
+ get :show, :id => "1"
270
+ end
271
+
272
+ it "should be successful" do
273
+ do_get
274
+ response.should be_success
275
+ end
276
+
277
+ it "should render show.rhtml" do
278
+ do_get
279
+ response.should render_template(:show)
280
+ end
281
+
282
+ it "should find the forum requested" do
283
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
284
+ do_get
285
+ end
286
+
287
+ it "should assign the found forum for the view" do
288
+ do_get
289
+ assigns[:forum].should == @mock_forum
290
+ end
291
+ end
292
+
293
+ describe "Requesting /admin/forums/1.xml using GET" do
294
+
295
+ before(:each) do
296
+ @mock_forum = mock('Forum')
297
+ @mock_forum.stub!(:to_xml).and_return("XML")
298
+ Forum.stub!(:find).and_return(@mock_forum)
299
+ end
300
+
301
+ def do_get
302
+ @request.env["HTTP_ACCEPT"] = "application/xml"
303
+ get :show, :id => "1"
304
+ end
305
+
306
+ it "should be successful" do
307
+ do_get
308
+ response.should be_success
309
+ end
310
+
311
+ it "should find the forum requested" do
312
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
313
+ do_get
314
+ end
315
+
316
+ it "should render the found forum as xml" do
317
+ @mock_forum.should_receive(:to_xml).and_return("XML")
318
+ do_get
319
+ response.body.should eql("XML")
320
+ end
321
+ end
322
+
323
+ describe "Requesting /admin/forums/1 using XHR GET" do
324
+
325
+ before(:each) do
326
+ @mock_forum = mock('Forum')
327
+ Forum.stub!(:find).and_return(@mock_forum)
328
+ end
329
+
330
+ def do_get
331
+ xhr :get, :show, :id => "1"
332
+ end
333
+
334
+ it "should be successful" do
335
+ do_get
336
+ response.should be_success
337
+ end
338
+
339
+ it "should render show.rjs" do
340
+ do_get
341
+ response.should render_template('show')
342
+ end
343
+
344
+ it "should find the forum requested" do
345
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
346
+ do_get
347
+ end
348
+
349
+ it "should assign the found forum for the view" do
350
+ do_get
351
+ assigns[:forum].should == @mock_forum
352
+ end
353
+ end
354
+
355
+ describe "Requesting /admin/forums/new using GET" do
356
+
357
+ before(:each) do
358
+ @mock_forum = mock('Forum')
359
+ Forum.stub!(:new).and_return(@mock_forum)
360
+ end
361
+
362
+ def do_get
363
+ get :new
364
+ end
365
+
366
+ it "should be successful" do
367
+ do_get
368
+ response.should be_success
369
+ end
370
+
371
+ it "should render new.rhtml" do
372
+ do_get
373
+ response.should render_template(:new)
374
+ end
375
+
376
+ it "should create an new forum" do
377
+ Forum.should_receive(:new).and_return(@mock_forum)
378
+ do_get
379
+ end
380
+
381
+ it "should not save the new forum" do
382
+ @mock_forum.should_not_receive(:save)
383
+ do_get
384
+ end
385
+
386
+ it "should assign the new forum for the view" do
387
+ do_get
388
+ assigns[:forum].should == @mock_forum
389
+ end
390
+ end
391
+
392
+ describe "Requesting /admin/forums/1/edit using GET" do
393
+
394
+ before(:each) do
395
+ @mock_forum = mock('Forum')
396
+ Forum.stub!(:find).and_return(@mock_forum)
397
+ end
398
+
399
+ def do_get
400
+ get :edit, :id => "1"
401
+ end
402
+
403
+ it "should be successful" do
404
+ do_get
405
+ response.should be_success
406
+ end
407
+
408
+ it "should render edit.rhtml" do
409
+ do_get
410
+ response.should render_template(:edit)
411
+ end
412
+
413
+ it "should find the forum requested" do
414
+ Forum.should_receive(:find).and_return(@mock_forum)
415
+ do_get
416
+ end
417
+
418
+ it "should assign the found Forum for the view" do
419
+ do_get
420
+ assigns(:forum).should equal(@mock_forum)
421
+ end
422
+ end
423
+
424
+ describe "Requesting /admin/forums using POST" do
425
+
426
+ before(:each) do
427
+ @mock_forum = mock('Forum')
428
+ @mock_forum.stub!(:save).and_return(true)
429
+ @mock_forum.stub!(:to_param).and_return("1")
430
+ Forum.stub!(:new).and_return(@mock_forum)
431
+ end
432
+
433
+ def do_post
434
+ post :create, :forum => {:name => 'Forum'}
435
+ end
436
+
437
+ it "should create a new forum" do
438
+ Forum.should_receive(:new).with({'name' => 'Forum'}).and_return(@mock_forum)
439
+ do_post
440
+ end
441
+
442
+ it "should set the flash notice" do
443
+ do_post
444
+ flash[:notice].should == "Forum was successfully created."
445
+ end
446
+
447
+ it "should redirect to the new forum" do
448
+ do_post
449
+ response.should be_redirect
450
+ response.redirect_url.should == "http://test.host/admin/forums/1"
451
+ end
452
+ end
453
+
454
+ describe "Requesting /admin/forums using XHR POST" do
455
+
456
+ before(:each) do
457
+ @mock_forum = mock('Forum')
458
+ @mock_forum.stub!(:save).and_return(true)
459
+ @mock_forum.stub!(:to_param).and_return("1")
460
+ Forum.stub!(:new).and_return(@mock_forum)
461
+ end
462
+
463
+ def do_post
464
+ xhr :post, :create, :forum => {:name => 'Forum'}
465
+ end
466
+
467
+ it "should create a new forum" do
468
+ Forum.should_receive(:new).with({'name' => 'Forum'}).and_return(@mock_forum)
469
+ do_post
470
+ end
471
+
472
+ it "should not set the flash notice" do
473
+ do_post
474
+ flash[:notice].should == nil
475
+ end
476
+
477
+ it "should render create.rjs" do
478
+ do_post
479
+ response.should render_template('create')
480
+ end
481
+
482
+ it "should render new.rjs if unsuccesful" do
483
+ @mock_forum.stub!(:save).and_return(false)
484
+ do_post
485
+ response.should render_template('new')
486
+ end
487
+ end
488
+
489
+ describe "Requesting /admin/forums/1 using PUT" do
490
+
491
+ before(:each) do
492
+ @mock_forum = mock('Forum').as_null_object
493
+ @mock_forum.stub!(:to_param).and_return("1")
494
+ Forum.stub!(:find).and_return(@mock_forum)
495
+ end
496
+
497
+ def do_update
498
+ put :update, :id => "1"
499
+ end
500
+
501
+ it "should find the forum requested" do
502
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
503
+ do_update
504
+ end
505
+
506
+ it "should set the flash notice" do
507
+ do_update
508
+ flash[:notice].should == "Forum was successfully updated."
509
+ end
510
+
511
+ it "should update the found forum" do
512
+ @mock_forum.should_receive(:update_attributes).and_return(true)
513
+ do_update
514
+ assigns(:forum).should == @mock_forum
515
+ end
516
+
517
+ it "should assign the found forum for the view" do
518
+ do_update
519
+ assigns(:forum).should == @mock_forum
520
+ end
521
+
522
+ it "should redirect to the forum" do
523
+ do_update
524
+ response.should be_redirect
525
+ response.redirect_url.should == "http://test.host/admin/forums/1"
526
+ end
527
+ end
528
+
529
+ describe "Requesting /admin/forums/1 using XHR PUT" do
530
+
531
+ before(:each) do
532
+ @mock_forum = mock('Forum').as_null_object
533
+ @mock_forum.stub!(:to_param).and_return("1")
534
+ Forum.stub!(:find).and_return(@mock_forum)
535
+ end
536
+
537
+ def do_update
538
+ xhr :put, :update, :id => "1"
539
+ end
540
+
541
+ it "should find the forum requested" do
542
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
543
+ do_update
544
+ end
545
+
546
+ it "should update the found forum" do
547
+ @mock_forum.should_receive(:update_attributes).and_return(true)
548
+ do_update
549
+ assigns(:forum).should == @mock_forum
550
+ end
551
+
552
+ it "should not set the flash notice" do
553
+ do_update
554
+ flash[:notice].should == nil
555
+ end
556
+
557
+ it "should assign the found forum for the view" do
558
+ do_update
559
+ assigns(:forum).should == @mock_forum
560
+ end
561
+
562
+ it "should render update.rjs" do
563
+ do_update
564
+ response.should render_template('update')
565
+ end
566
+
567
+ it "should render edit.rjs, on unsuccessful save" do
568
+ @mock_forum.stub!(:update_attributes).and_return(false)
569
+ do_update
570
+ response.should render_template('edit')
571
+ end
572
+ end
573
+
574
+ describe "Requesting /admin/forums/1 using DELETE" do
575
+
576
+ before(:each) do
577
+ @mock_forum = mock('Forum').as_null_object
578
+ Forum.stub!(:find).and_return(@mock_forum)
579
+ end
580
+
581
+ def do_delete
582
+ delete :destroy, :id => "1"
583
+ end
584
+
585
+ it "should find the forum requested" do
586
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
587
+ do_delete
588
+ end
589
+
590
+ it "should call destroy on the found forum" do
591
+ @mock_forum.should_receive(:destroy)
592
+ do_delete
593
+ end
594
+
595
+ it "should set the flash notice" do
596
+ do_delete
597
+ flash[:notice].should == 'Forum was successfully destroyed.'
598
+ end
599
+
600
+ it "should redirect to the forums list" do
601
+ do_delete
602
+ response.should be_redirect
603
+ response.redirect_url.should == "http://test.host/admin/forums"
604
+ end
605
+ end
606
+
607
+ describe "Requesting /admin/forums/1 using XHR DELETE" do
608
+
609
+ before(:each) do
610
+ @mock_forum = mock('Forum').as_null_object
611
+ Forum.stub!(:find).and_return(@mock_forum)
612
+ end
613
+
614
+ def do_delete
615
+ xhr :delete, :destroy, :id => "1"
616
+ end
617
+
618
+ it "should find the forum requested" do
619
+ Forum.should_receive(:find).with("1").and_return(@mock_forum)
620
+ do_delete
621
+ end
622
+
623
+ it "should not set the flash notice" do
624
+ do_delete
625
+ flash[:notice].should == nil
626
+ end
627
+
628
+ it "should call destroy on the found forum" do
629
+ @mock_forum.should_receive(:destroy)
630
+ do_delete
631
+ end
632
+
633
+ it "should render destroy.rjs" do
634
+ do_delete
635
+ response.should render_template('destroy')
636
+ end
637
+ end
638
+ end