rails_best_practices 1.18.1 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +4 -1
  4. data/Gemfile +3 -3
  5. data/README.md +1 -1
  6. data/Rakefile +1 -4
  7. data/lib/rails_best_practices/analyzer.rb +3 -3
  8. data/lib/rails_best_practices/core/routes.rb +1 -1
  9. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -2
  10. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -2
  11. data/lib/rails_best_practices/prepares/route_prepare.rb +5 -0
  12. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
  13. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
  14. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +2 -2
  15. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -2
  16. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -2
  17. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +2 -2
  18. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +2 -2
  19. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +2 -2
  20. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +2 -2
  21. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
  22. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +2 -2
  23. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +2 -2
  24. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +2 -2
  25. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +2 -2
  26. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -2
  27. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +3 -12
  28. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -2
  29. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -47
  30. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +2 -2
  31. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -2
  32. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
  33. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -2
  34. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +15 -6
  35. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -2
  36. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +2 -2
  37. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -2
  38. data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
  39. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +3 -18
  40. data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -13
  41. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +2 -2
  42. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -2
  43. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -2
  44. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -2
  45. data/lib/rails_best_practices/version.rb +1 -1
  46. data/rails_best_practices.gemspec +2 -2
  47. data/spec/rails_best_practices/analyzer_spec.rb +1 -1
  48. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +338 -586
  49. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +59 -140
  50. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +26 -69
  51. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +44 -153
  52. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +2 -2
  53. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +21 -0
  54. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +160 -272
  55. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +76 -209
  56. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +43 -110
  57. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +4 -4
  58. metadata +5 -23
  59. data/.rubocop.yml +0 -1
  60. data/.rubocop_todo.yml +0 -382
  61. data/install_supported_rubies.sh +0 -10
  62. data/rake_rubies.sh +0 -9
@@ -142,7 +142,7 @@ module RailsBestPractices
142
142
  it "should not protect mass assignment for activerecord 4" do
143
143
  content =<<-EOF
144
144
  GEM
145
- remote: http://rubygems.org
145
+ remote: https://rubygems.org
146
146
  specs:
147
147
  activerecord (4.0.0)
148
148
  EOF
@@ -158,7 +158,7 @@ module RailsBestPractices
158
158
  it "should protect mass assignment for activerecord 3" do
159
159
  content =<<-EOF
160
160
  GEM
161
- remote: http://rubygems.org
161
+ remote: https://rubygems.org
162
162
  specs:
163
163
  activerecord (3.2.13)
164
164
  EOF
@@ -153,6 +153,27 @@ module RailsBestPractices
153
153
  expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:3 - remove unused methods (PostsController#list)")
154
154
  end
155
155
 
156
+ it "should not remove inline routes" do
157
+ content =<<-EOF
158
+ RailsBestPracticesCom::Application.routes.draw do
159
+ resources :posts, only: :none do
160
+ get :display, :list, on: :member
161
+ end
162
+ end
163
+ EOF
164
+ runner.prepare('config/routes.rb', content)
165
+ content =<<-EOF
166
+ class PostsController < ApplicationController
167
+ def display; end
168
+ def list; end
169
+ end
170
+ EOF
171
+ runner.prepare('app/controllers/posts_controller.rb', content)
172
+ runner.review('app/controllers/posts_controller.rb', content)
173
+ runner.after_review
174
+ expect(runner.errors.size).to eq(0)
175
+ end
176
+
156
177
  it "should not remove unused methods if all actions are used in route" do
157
178
  content =<<-EOF
158
179
  ActionController::Routing::Routes.draw do |map|
@@ -20,131 +20,125 @@ module RailsBestPractices
20
20
  runner.prepare('app/controllers/posts_controller.rb', content)
21
21
  end
22
22
 
23
- describe "rails2" do
23
+ it "should restrict auto-generated routes" do
24
+ content =<<-EOF
25
+ RailsBestPracticesCom::Application.routes.draw do
26
+ resources :posts
27
+ end
28
+ EOF
29
+ runner.review('config/routes.rb', content)
30
+ expect(runner.errors.size).to eq(1)
31
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
32
+ end
33
+
34
+ it "should not restrict auto-generated routes with only" do
35
+ content =<<-EOF
36
+ RailsBestPracticesCom::Application.routes.draw do
37
+ resources :posts, only: %w(show new create edit update destroy)
38
+ end
39
+ EOF
40
+ runner.review('config/routes.rb', content)
41
+ expect(runner.errors.size).to eq(0)
42
+ end
43
+
44
+ it "should not restrict auto-generated routes with except" do
45
+ content =<<-EOF
46
+ RailsBestPracticesCom::Application.routes.draw do
47
+ resources :posts, except: :index
48
+ end
49
+ EOF
50
+ runner.review('config/routes.rb', content)
51
+ expect(runner.errors.size).to eq(0)
52
+ end
53
+
54
+ describe "specify a controller" do
24
55
  it "should restrict auto-generated routes" do
25
56
  content =<<-EOF
26
- ActionController::Routing::Routes.draw do |map|
27
- map.resources :posts
57
+ RailsBestPracticesCom::Application.routes.draw do
58
+ resources :articles, controller: "posts"
28
59
  end
29
60
  EOF
30
61
  runner.review('config/routes.rb', content)
31
62
  expect(runner.errors.size).to eq(1)
32
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
63
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes articles (except: [:index])")
33
64
  end
65
+ end
34
66
 
35
- it "should not restrict auto-generated routes with only" do
67
+ describe "namespace" do
68
+ before do
36
69
  content =<<-EOF
37
- ActionController::Routing::Routes.draw do |map|
38
- map.resources :posts, only: [:show, :new, :create, :edit, :update, :destroy]
70
+ class Admin::CommentsController < ApplicationController
71
+ def show; end
72
+ def new; end
73
+ def create; end
74
+ def edit; end
75
+ def update; end
76
+ def destroy; end
39
77
  end
40
78
  EOF
41
- runner.review('config/routes.rb', content)
42
- expect(runner.errors.size).to eq(0)
79
+ runner.prepare('app/controllers/admin/comments_controller.rb', content)
43
80
  end
44
81
 
45
- it "should not restrict auto-generated routes with except" do
82
+ it "should restrict auto-generated routes" do
46
83
  content =<<-EOF
47
- ActionController::Routing::Routes.draw do |map|
48
- map.resources :posts, except: :index
84
+ RailsBestPracticesCom::Application.routes.draw do
85
+ namespace :admin do
86
+ resources :comments
87
+ end
49
88
  end
50
89
  EOF
51
90
  runner.review('config/routes.rb', content)
52
- expect(runner.errors.size).to eq(0)
91
+ expect(runner.errors.size).to eq(1)
92
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])")
53
93
  end
54
94
 
55
- it "should not restrict auto-generated routes with only: :none" do
95
+ it "should restrict auto-generated routes with scope :module" do
56
96
  content =<<-EOF
57
- ActionController::Routing::Routes.draw do |map|
58
- map.resources :posts, only: :none
97
+ RailsBestPracticesCom::Application.routes.draw do
98
+ scope module: :admin do
99
+ resources :comments
100
+ end
59
101
  end
60
102
  EOF
61
103
  runner.review('config/routes.rb', content)
62
- expect(runner.errors.size).to eq(0)
104
+ expect(runner.errors.size).to eq(1)
105
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])")
63
106
  end
64
107
 
65
- it "should not restrict auto-generated routes with except: :all" do
108
+ it "should restrict auto-generated routes with resources :module" do
66
109
  content =<<-EOF
67
- ActionController::Routing::Routes.draw do |map|
68
- map.resources :posts, except: :all
110
+ RailsBestPracticesCom::Application.routes.draw do
111
+ resources :comments, module: :admin
69
112
  end
70
113
  EOF
71
114
  runner.review('config/routes.rb', content)
72
- expect(runner.errors.size).to eq(0)
73
- end
74
-
75
- describe "specify a controller" do
76
- it "should restrict auto-generated routes" do
77
- content =<<-EOF
78
- ActionController::Routing::Routes.draw do |map|
79
- map.resources :articles, controller: "posts"
80
- end
81
- EOF
82
- runner.review('config/routes.rb', content)
83
- expect(runner.errors.size).to eq(1)
84
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes articles (except: [:index])")
85
- end
115
+ expect(runner.errors.size).to eq(1)
116
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes admin/comments (except: [:index])")
86
117
  end
118
+ end
87
119
 
88
- describe "nested routes" do
89
- before :each do
90
- content =<<-EOF
91
- class CommentsController < ApplicationController
92
- def index; end
93
- def show; end
94
- def new; end
95
- def create; end
96
- def edit; end
97
- def update; end
98
- def destroy; end
99
- end
100
- EOF
101
- runner.prepare('app/controllers/comments_controller.rb', content)
102
- end
103
-
104
- it "should restrict auto-generated routes" do
105
- content =<<-EOF
106
- ActionController::Routing::Routes.draw do |map|
107
- map.resources :posts do |post|
108
- post.resources :comments
109
- end
110
- end
111
- EOF
112
- runner.review('config/routes.rb', content)
113
- expect(runner.errors.size).to eq(1)
114
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
115
- end
116
-
117
- it "should not restrict auto-generated routes with only" do
118
- content =<<-EOF
119
- ActionController::Routing::Routes.draw do |map|
120
- map.resources :posts, only: [:show, :new, :create, :edit, :update, :destroy] do |post|
121
- post.resources :comments
122
- end
123
- end
124
- EOF
125
- runner.review('config/routes.rb', content)
126
- expect(runner.errors.size).to eq(0)
127
- end
128
-
129
- it "should not restrict auto-generated routes with except" do
130
- content =<<-EOF
131
- ActionController::Routing::Routes.draw do |map|
132
- map.resources :posts, except: :index do |post|
133
- post.resources :comments
134
- end
135
- end
136
- EOF
137
- runner.review('config/routes.rb', content)
138
- expect(runner.errors.size).to eq(0)
120
+ describe "nested routes" do
121
+ before :each do
122
+ content =<<-EOF
123
+ class CommentsController < ApplicationController
124
+ def index; end
125
+ def show; end
126
+ def new; end
127
+ def create; end
128
+ def edit; end
129
+ def update; end
130
+ def destroy; end
139
131
  end
132
+ EOF
133
+ runner.prepare('app/controllers/comments_controller.rb', content)
140
134
  end
141
- end
142
135
 
143
- describe "rails3" do
144
136
  it "should restrict auto-generated routes" do
145
137
  content =<<-EOF
146
138
  RailsBestPracticesCom::Application.routes.draw do
147
- resources :posts
139
+ resources :posts do
140
+ resources :comments
141
+ end
148
142
  end
149
143
  EOF
150
144
  runner.review('config/routes.rb', content)
@@ -155,7 +149,9 @@ module RailsBestPractices
155
149
  it "should not restrict auto-generated routes with only" do
156
150
  content =<<-EOF
157
151
  RailsBestPracticesCom::Application.routes.draw do
158
- resources :posts, only: %w(show new create edit update destroy)
152
+ resources :posts, only: %w(show new create edit update destroy) do
153
+ resources :comments
154
+ end
159
155
  end
160
156
  EOF
161
157
  runner.review('config/routes.rb', content)
@@ -165,132 +161,14 @@ module RailsBestPractices
165
161
  it "should not restrict auto-generated routes with except" do
166
162
  content =<<-EOF
167
163
  RailsBestPracticesCom::Application.routes.draw do
168
- resources :posts, except: :index
164
+ resources :posts, except: :index do
165
+ resources :comments
166
+ end
169
167
  end
170
168
  EOF
171
169
  runner.review('config/routes.rb', content)
172
170
  expect(runner.errors.size).to eq(0)
173
171
  end
174
-
175
- describe "specify a controller" do
176
- it "should restrict auto-generated routes" do
177
- content =<<-EOF
178
- RailsBestPracticesCom::Application.routes.draw do
179
- resources :articles, controller: "posts"
180
- end
181
- EOF
182
- runner.review('config/routes.rb', content)
183
- expect(runner.errors.size).to eq(1)
184
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes articles (except: [:index])")
185
- end
186
- end
187
-
188
- describe "namespace" do
189
- before do
190
- content =<<-EOF
191
- class Admin::CommentsController < ApplicationController
192
- def show; end
193
- def new; end
194
- def create; end
195
- def edit; end
196
- def update; end
197
- def destroy; end
198
- end
199
- EOF
200
- runner.prepare('app/controllers/admin/comments_controller.rb', content)
201
- end
202
-
203
- it "should restrict auto-generated routes" do
204
- content =<<-EOF
205
- RailsBestPracticesCom::Application.routes.draw do
206
- namespace :admin do
207
- resources :comments
208
- end
209
- end
210
- EOF
211
- runner.review('config/routes.rb', content)
212
- expect(runner.errors.size).to eq(1)
213
- expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])")
214
- end
215
-
216
- it "should restrict auto-generated routes with scope :module" do
217
- content =<<-EOF
218
- RailsBestPracticesCom::Application.routes.draw do
219
- scope module: :admin do
220
- resources :comments
221
- end
222
- end
223
- EOF
224
- runner.review('config/routes.rb', content)
225
- expect(runner.errors.size).to eq(1)
226
- expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])")
227
- end
228
-
229
- it "should restrict auto-generated routes with resources :module" do
230
- content =<<-EOF
231
- RailsBestPracticesCom::Application.routes.draw do
232
- resources :comments, module: :admin
233
- end
234
- EOF
235
- runner.review('config/routes.rb', content)
236
- expect(runner.errors.size).to eq(1)
237
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes admin/comments (except: [:index])")
238
- end
239
- end
240
-
241
- describe "nested routes" do
242
- before :each do
243
- content =<<-EOF
244
- class CommentsController < ApplicationController
245
- def index; end
246
- def show; end
247
- def new; end
248
- def create; end
249
- def edit; end
250
- def update; end
251
- def destroy; end
252
- end
253
- EOF
254
- runner.prepare('app/controllers/comments_controller.rb', content)
255
- end
256
-
257
- it "should restrict auto-generated routes" do
258
- content =<<-EOF
259
- RailsBestPracticesCom::Application.routes.draw do
260
- resources :posts do
261
- resources :comments
262
- end
263
- end
264
- EOF
265
- runner.review('config/routes.rb', content)
266
- expect(runner.errors.size).to eq(1)
267
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
268
- end
269
-
270
- it "should not restrict auto-generated routes with only" do
271
- content =<<-EOF
272
- RailsBestPracticesCom::Application.routes.draw do
273
- resources :posts, only: %w(show new create edit update destroy) do
274
- resources :comments
275
- end
276
- end
277
- EOF
278
- runner.review('config/routes.rb', content)
279
- expect(runner.errors.size).to eq(0)
280
- end
281
-
282
- it "should not restrict auto-generated routes with except" do
283
- content =<<-EOF
284
- RailsBestPracticesCom::Application.routes.draw do
285
- resources :posts, except: :index do
286
- resources :comments
287
- end
288
- end
289
- EOF
290
- runner.review('config/routes.rb', content)
291
- expect(runner.errors.size).to eq(0)
292
- end
293
- end
294
172
  end
295
173
  end
296
174
 
@@ -308,83 +186,93 @@ module RailsBestPractices
308
186
  runner.prepare('app/controllers/accounts_controller.rb', content)
309
187
  end
310
188
 
311
- describe "rails2" do
312
- it "should restrict auto-generated routes" do
313
- content =<<-EOF
314
- ActionController::Routing::Routes.draw do |map|
315
- map.resource :account
316
- end
317
- EOF
318
- runner.review('config/routes.rb', content)
319
- expect(runner.errors.size).to eq(1)
320
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])")
189
+ it "should restrict auto-generated routes" do
190
+ content =<<-EOF
191
+ ActionController::Routing::Routes.draw do |map|
192
+ map.resource :account
321
193
  end
194
+ EOF
195
+ runner.review('config/routes.rb', content)
196
+ expect(runner.errors.size).to eq(1)
197
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])")
198
+ end
322
199
 
323
- it "should not restrict auto-generated routes with only" do
324
- content =<<-EOF
325
- ActionController::Routing::Routes.draw do |map|
326
- map.resource :account, only: %w(show new create edit update)
327
- end
328
- EOF
329
- runner.review('config/routes.rb', content)
330
- expect(runner.errors.size).to eq(0)
200
+ it "should not restrict auto-generated routes with only" do
201
+ content =<<-EOF
202
+ ActionController::Routing::Routes.draw do |map|
203
+ map.resource :account, only: %w(show new create edit update)
331
204
  end
205
+ EOF
206
+ runner.review('config/routes.rb', content)
207
+ expect(runner.errors.size).to eq(0)
208
+ end
332
209
 
333
- it "should not restrict auto-generated routes with except" do
334
- content =<<-EOF
335
- ActionController::Routing::Routes.draw do |map|
336
- map.resource :account, except: :destroy
337
- end
338
- EOF
339
- runner.review('config/routes.rb', content)
340
- expect(runner.errors.size).to eq(0)
210
+ it "should not restrict auto-generated routes with except" do
211
+ content =<<-EOF
212
+ ActionController::Routing::Routes.draw do |map|
213
+ map.resource :account, except: :destroy
341
214
  end
215
+ EOF
216
+ runner.review('config/routes.rb', content)
217
+ expect(runner.errors.size).to eq(0)
342
218
  end
343
219
 
344
- describe "rails3" do
345
- it "should restrict auto-generated routes" do
346
- content =<<-EOF
347
- ActionController::Routing::Routes.draw do |map|
348
- map.resource :account
349
- end
350
- EOF
351
- runner.review('config/routes.rb', content)
352
- expect(runner.errors.size).to eq(1)
353
- expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])")
354
- end
220
+ it "should not check ignored files" do
221
+ runner = Core::Runner.new(prepares: Prepares::ControllerPrepare.new,
222
+ reviews: RestrictAutoGeneratedRoutesReview.new(ignored_files: /config\/routes\.rb/))
355
223
 
356
- it "should not restrict auto-generated routes with only" do
357
- content =<<-EOF
358
- ActionController::Routing::Routes.draw do |map|
359
- map.resource :account, only: %w(show new create edit update)
360
- end
361
- EOF
362
- runner.review('config/routes.rb', content)
363
- expect(runner.errors.size).to eq(0)
224
+ content =<<-EOF
225
+ ActionController::Routing::Routes.draw do |map|
226
+ map.resource :account
364
227
  end
228
+ EOF
229
+ runner.review('config/routes.rb', content)
230
+ expect(runner.errors.size).to eq(0)
231
+ end
232
+ end
365
233
 
366
- it "should not restrict auto-generated routes with except" do
367
- content =<<-EOF
368
- ActionController::Routing::Routes.draw do |map|
369
- map.resource :account, except: :destroy
234
+ context 'api_only = true' do
235
+ let(:runner) { Core::Runner.new(prepares: [Prepares::ConfigPrepare.new, Prepares::ControllerPrepare.new], reviews: RestrictAutoGeneratedRoutesReview.new) }
236
+
237
+ before do
238
+ content =<<-EOF
239
+ module RailsBestPracticesCom
240
+ class Application < Rails::Application
241
+ config.api_only = true
370
242
  end
371
- EOF
372
- runner.review('config/routes.rb', content)
373
- expect(runner.errors.size).to eq(0)
374
243
  end
244
+ EOF
245
+ runner.prepare('config/application.rb', content)
246
+ content =<<-EOF
247
+ class PostsController < ApplicationController
248
+ def show; end
249
+ def create; end
250
+ def update; end
251
+ def destroy; end
252
+ end
253
+ EOF
254
+ runner.prepare('app/controllers/posts_controller.rb', content)
255
+ end
375
256
 
376
- it "should not check ignored files" do
377
- runner = Core::Runner.new(prepares: Prepares::ControllerPrepare.new,
378
- reviews: RestrictAutoGeneratedRoutesReview.new(ignored_files: /config\/routes\.rb/))
257
+ it "should restrict auto-generated routes" do
258
+ content =<<-EOF
259
+ RailsBestPracticesCom::Application.routes.draw do
260
+ resources :posts
261
+ end
262
+ EOF
263
+ runner.review('config/routes.rb', content)
264
+ expect(runner.errors.size).to eq(1)
265
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
266
+ end
379
267
 
380
- content =<<-EOF
381
- ActionController::Routing::Routes.draw do |map|
382
- map.resource :account
383
- end
384
- EOF
385
- runner.review('config/routes.rb', content)
386
- expect(runner.errors.size).to eq(0)
268
+ it "should not restrict auto-generated routes with only" do
269
+ content =<<-EOF
270
+ RailsBestPracticesCom::Application.routes.draw do
271
+ resources :posts, only: %w(show create update destroy)
387
272
  end
273
+ EOF
274
+ runner.review('config/routes.rb', content)
275
+ expect(runner.errors.size).to eq(0)
388
276
  end
389
277
  end
390
278
  end