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,426 @@
1
+ require 'spec_helper'
2
+
3
+ module ForumPostsSpecHelper
4
+ def setup_mocks
5
+ @forum = mock('Forum')
6
+ @forum_posts = mock('Assoc: forum_posts')
7
+ @forum.stub!(:posts).and_return(@forum_posts)
8
+ @forum.stub!(:to_param).and_return("2")
9
+
10
+ Forum.stub!(:find).and_return(@forum)
11
+ end
12
+ end
13
+
14
+ describe ForumPostsController do
15
+ describe "Routing shortcuts for ForumPosts (forums/2/posts/1) should map" do
16
+ include ForumPostsSpecHelper
17
+
18
+ before(:each) do
19
+ setup_mocks
20
+ @post = mock('Post')
21
+ @post.stub!(:to_param).and_return('1')
22
+ @forum_posts.stub!(:find).and_return(@post)
23
+
24
+ get :show, :forum_id => "2", :id => "1"
25
+ end
26
+
27
+ it "resources_path to /forums/2/posts" do
28
+ controller.resources_path.should == '/forums/2/posts'
29
+ end
30
+
31
+ it "resource_path to /forums/2/posts/1" do
32
+ controller.resource_path.should == '/forums/2/posts/1'
33
+ end
34
+
35
+ it "resource_path(9) to /forums/2/posts/9" do
36
+ controller.resource_path(9).should == '/forums/2/posts/9'
37
+ end
38
+
39
+ it "edit_resource_path to /forums/2/posts/1/edit" do
40
+ controller.edit_resource_path.should == '/forums/2/posts/1/edit'
41
+ end
42
+
43
+ it "edit_resource_path(9) to /forums/2/posts/9/edit" do
44
+ controller.edit_resource_path(9).should == '/forums/2/posts/9/edit'
45
+ end
46
+
47
+ it "new_resource_path to /forums/2/posts/new" do
48
+ controller.new_resource_path.should == '/forums/2/posts/new'
49
+ end
50
+
51
+ it "resource_tags_path to /forums/2/posts/1/tags" do
52
+ controller.resource_tags_path.should == "/forums/2/posts/1/tags"
53
+ end
54
+
55
+ it "resource_tags_path(9) to /forums/2/posts/9/tags" do
56
+ controller.resource_tags_path(9).should == "/forums/2/posts/9/tags"
57
+ end
58
+
59
+ it "resource_tag_path(5) to /forums/2/posts/1/tags/5" do
60
+ controller.resource_tag_path(5).should == "/forums/2/posts/1/tags/5"
61
+ end
62
+
63
+ it "resource_tag_path(9,5) to /forums/2/posts/9/tags/5" do
64
+ controller.resource_tag_path(9,5).should == "/forums/2/posts/9/tags/5"
65
+ end
66
+
67
+ it "enclosing_resource_path to /forums/2" do
68
+ controller.enclosing_resource_path.should == '/forums/2'
69
+ end
70
+
71
+ it "enclosing_resource_path(9) to /forums/9" do
72
+ controller.enclosing_resource_path(9).should == '/forums/9'
73
+ end
74
+
75
+ it "enclosing_resources_path to /forums" do
76
+ controller.enclosing_resources_path.should == '/forums'
77
+ end
78
+
79
+ it "new_enclosing_resource_path to /forums/new" do
80
+ controller.new_enclosing_resource_path.should == '/forums/new'
81
+ end
82
+
83
+ it "enclosing_resource_tags_path to /forums/2/tags" do
84
+ controller.enclosing_resource_tags_path.should == '/forums/2/tags'
85
+ end
86
+
87
+ it "enclosing_resource_tag_path(9) to /forums/2/tags/9" do
88
+ controller.enclosing_resource_tag_path(9).should == '/forums/2/tags/9'
89
+ end
90
+
91
+ it "enclosing_resource_tag_path(8,9) to /forums/8/tags/9" do
92
+ controller.enclosing_resource_tag_path(8,9).should == '/forums/8/tags/9'
93
+ end
94
+ end
95
+
96
+ describe ForumPostsController, " errors" do
97
+
98
+ it "should raise ResourceMismatch for /posts" do
99
+ lambda{ get :index }.should raise_error(ResourcesController::ResourceMismatch)
100
+ end
101
+
102
+ it "should raise ResourceMismatch, when route does not contain the resource segment" do
103
+ lambda{ get :index, :foo_id => 1}.should raise_error(ResourcesController::ResourceMismatch)
104
+ end
105
+ end
106
+
107
+ describe "resource_service in ForumPostsController" do
108
+
109
+ before(:each) do
110
+ @forum = Forum.create
111
+ @post = Post.create :forum_id => @forum.id
112
+ @other_forum = Forum.create
113
+ @other_post = Post.create :forum_id => @other_forum.id
114
+
115
+ get :index, :forum_id => @forum.id
116
+ @resource_service = controller.send :resource_service
117
+ end
118
+
119
+ it "should build new post with @forum foreign key with new" do
120
+ resource = @resource_service.new
121
+ resource.should be_kind_of(Post)
122
+ resource.forum_id.should == @forum.id
123
+ end
124
+
125
+ it "should find @post with find(@post.id)" do
126
+ resource = @resource_service.find(@post.id)
127
+ resource.should == @post
128
+ end
129
+
130
+ it "should raise RecordNotFound with find(@other_post.id)" do
131
+ lambda{ @resource_service.find(@other_post.id) }.should raise_error(ActiveRecord::RecordNotFound)
132
+ end
133
+
134
+ it "should find only posts belonging to @forum with find(:all)" do
135
+ resources = @resource_service.find(:all)
136
+ resources.should be == Post.find(:all, :conditions => "forum_id = #{@forum.id}")
137
+ end
138
+ end
139
+
140
+ describe ForumPostsController, ' order of before_filters' do
141
+ before do
142
+ @forum = Forum.create
143
+ get :index, :forum_id => @forum.id
144
+ end
145
+
146
+ it { @controller.filter_trace.should == [:abstract, :posts, :load_enclosing, :forum_posts] }
147
+ end
148
+
149
+ describe "Requesting /forums/2/posts (testing the before filters)" do
150
+ include ForumPostsSpecHelper
151
+
152
+ before(:each) do
153
+ setup_mocks
154
+ @posts = mock('Posts')
155
+ @forum_posts.stub!(:find).and_return(@posts)
156
+ end
157
+
158
+ def do_get
159
+ get :index, :forum_id => '2'
160
+ end
161
+
162
+ it "should find the forum" do
163
+ Forum.should_receive(:find).with('2').and_return(@forum)
164
+ do_get
165
+ end
166
+
167
+ it "should assign the form as other_name_for_forum" do
168
+ do_get
169
+ assigns[:other_name_for_forum].should == assigns[:forum]
170
+ end
171
+
172
+ it "should assign the found forum for the view" do
173
+ do_get
174
+ assigns[:forum].should == @forum
175
+ end
176
+
177
+ it "should assign the forum_posts association as the posts resource_service" do
178
+ @forum.should_receive(:posts).and_return(@forum_posts)
179
+ do_get
180
+ @controller.resource_service.should == @forum_posts
181
+ end
182
+ end
183
+
184
+ describe "Requesting /forums/2/posts using GET" do
185
+ include ForumPostsSpecHelper
186
+
187
+ before(:each) do
188
+ setup_mocks
189
+ @posts = mock('Posts')
190
+ @forum_posts.stub!(:find).and_return(@posts)
191
+ end
192
+
193
+ def do_get
194
+ get :index, :forum_id => '2'
195
+ end
196
+
197
+ it "should be successful" do
198
+ do_get
199
+ response.should be_success
200
+ end
201
+
202
+ it "should render index.rhtml" do
203
+ do_get
204
+ response.should render_template(:index)
205
+ end
206
+
207
+ it "should find all posts, in reverse order (because of AbstractPostsController)" do
208
+ @forum_posts.should_receive(:find).with(:all, :order => 'id DESC').and_return(@posts)
209
+ do_get
210
+ end
211
+
212
+ it "should assign the found posts for the view" do
213
+ do_get
214
+ assigns[:posts].should == @posts
215
+ end
216
+ end
217
+
218
+ describe "Requesting /forums/2/posts/1 using GET" do
219
+ include ForumPostsSpecHelper
220
+
221
+ before(:each) do
222
+ setup_mocks
223
+ @post = mock('a post')
224
+ @forum_posts.stub!(:find).and_return(@post)
225
+ end
226
+
227
+ def do_get
228
+ get :show, :id => "1", :forum_id => "2"
229
+ end
230
+
231
+ it "should be successful" do
232
+ do_get
233
+ response.should be_success
234
+ end
235
+
236
+ it "should render show.rhtml" do
237
+ do_get
238
+ response.should render_template(:show)
239
+ end
240
+
241
+ it "should find the thing requested" do
242
+ @forum_posts.should_receive(:find).with("1").and_return(@post)
243
+ do_get
244
+ end
245
+
246
+ it "should assign the found thing for the view" do
247
+ do_get
248
+ assigns[:post].should == @post
249
+ end
250
+ end
251
+
252
+ describe "Requesting /forums/2/posts/new using GET" do
253
+ include ForumPostsSpecHelper
254
+
255
+ before(:each) do
256
+ setup_mocks
257
+ @post = mock('new Post')
258
+ @forum_posts.stub!(:build).and_return(@post)
259
+ end
260
+
261
+ def do_get
262
+ get :new, :forum_id => "2"
263
+ end
264
+
265
+ it "should be successful" do
266
+ do_get
267
+ response.should be_success
268
+ end
269
+
270
+ it "should render new.rhtml" do
271
+ do_get
272
+ response.should render_template(:new)
273
+ end
274
+
275
+ it "should build an new thing" do
276
+ @forum_posts.should_receive(:build).and_return(@post)
277
+ do_get
278
+ end
279
+
280
+ it "should not save the new thing" do
281
+ @post.should_not_receive(:save)
282
+ do_get
283
+ end
284
+
285
+ it "should assign the new thing for the view" do
286
+ do_get
287
+ assigns[:post].should == @post
288
+ end
289
+ end
290
+
291
+ describe "Requesting /forums/2/posts/1/edit using GET" do
292
+ include ForumPostsSpecHelper
293
+
294
+ before(:each) do
295
+ setup_mocks
296
+ @post = mock('Post')
297
+ @forum_posts.stub!(:find).and_return(@post)
298
+ end
299
+
300
+ def do_get
301
+ get :edit, :id => "1", :forum_id => "2"
302
+ end
303
+
304
+ it "should be successful" do
305
+ do_get
306
+ response.should be_success
307
+ end
308
+
309
+ it "should render edit.rhtml" do
310
+ do_get
311
+ response.should render_template(:edit)
312
+ end
313
+
314
+ it "should find the thing requested" do
315
+ @forum_posts.should_receive(:find).with("1").and_return(@post)
316
+ do_get
317
+ end
318
+
319
+ it "should assign the found Thing for the view" do
320
+ do_get
321
+ assigns(:post).should equal(@post)
322
+ end
323
+ end
324
+
325
+ describe "Requesting /forums/2/posts using POST" do
326
+ include ForumPostsSpecHelper
327
+
328
+ before(:each) do
329
+ setup_mocks
330
+ @post = mock('Post')
331
+ @post.stub!(:save).and_return(true)
332
+ @post.stub!(:to_param).and_return("1")
333
+ @forum_posts.stub!(:build).and_return(@post)
334
+ end
335
+
336
+ def do_post
337
+ post :create, :post => {:name => 'Post'}, :forum_id => "2"
338
+ end
339
+
340
+ it "should build a new post" do
341
+ @forum_posts.should_receive(:build).with({'name' => 'Post'}).and_return(@post)
342
+ do_post
343
+ end
344
+
345
+ it "should attempt to save the new post" do
346
+ @post.should_receive(:save).and_return(true)
347
+ do_post
348
+ end
349
+
350
+ it "should redirect to the new post.save == true" do
351
+ do_post
352
+ response.should be_redirect
353
+ response.redirect_url.should == "http://test.host/forums/2/posts/1"
354
+ end
355
+
356
+ it "should render new when post.save == false" do
357
+ @post.stub!(:save).and_return(false)
358
+ do_post
359
+ response.should render_template(:new)
360
+ end
361
+ end
362
+
363
+ describe "Requesting /forums/2/posts/1 using PUT" do
364
+ include ForumPostsSpecHelper
365
+
366
+ before(:each) do
367
+ setup_mocks
368
+ @post = mock('Post').as_null_object
369
+ @post.stub!(:to_param).and_return("1")
370
+ @forum_posts.stub!(:find).and_return(@post)
371
+ end
372
+
373
+ def do_update
374
+ put :update, :id => "1", :forum_id => "2"
375
+ end
376
+
377
+ it "should find the post requested" do
378
+ @forum_posts.should_receive(:find).with("1").and_return(@post)
379
+ do_update
380
+ end
381
+
382
+ it "should update the found post" do
383
+ @post.should_receive(:update_attributes)
384
+ do_update
385
+ end
386
+
387
+ it "should assign the found post for the view" do
388
+ do_update
389
+ assigns(:post).should == @post
390
+ end
391
+
392
+ it "should redirect to the post" do
393
+ do_update
394
+ response.should be_redirect
395
+ response.redirect_url.should == "http://test.host/forums/2/posts/1"
396
+ end
397
+ end
398
+
399
+ describe "Requesting /forums/2/posts/1 using DELETE" do
400
+ include ForumPostsSpecHelper
401
+
402
+ before(:each) do
403
+ setup_mocks
404
+ @post = mock('Post').as_null_object
405
+ @forum_posts.stub!(:find).and_return(@post)
406
+ @forum_posts.stub!(:destroy)
407
+ end
408
+
409
+ def do_delete
410
+ delete :destroy, :id => "1", :forum_id => "2"
411
+ end
412
+
413
+ it "should find and destroy the post requested" do
414
+ @forum_posts.should_receive(:find).with("1").and_return(@post)
415
+ @forum_posts.should_receive(:destroy).with("1")
416
+ do_delete
417
+ assigns['post'].should == @post
418
+ end
419
+
420
+ it "should redirect to the things list" do
421
+ do_delete
422
+ response.should be_redirect
423
+ response.redirect_url.should == "http://test.host/forums/2/posts"
424
+ end
425
+ end
426
+ end