rails_best_practices 1.14.4 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/README.md +26 -6
- data/lib/rails_best_practices/core/check.rb +15 -2
- data/lib/rails_best_practices/core/klasses.rb +13 -3
- data/lib/rails_best_practices/core/model_associations.rb +1 -1
- data/lib/rails_best_practices/core/runner.rb +2 -0
- data/lib/rails_best_practices/lexicals/long_line_check.rb +1 -1
- data/lib/rails_best_practices/prepares/route_prepare.rb +17 -1
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +2 -2
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +1 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +1 -1
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +1 -2
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +1 -1
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +15 -26
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -2
- data/lib/rails_best_practices/version.rb +1 -1
- data/spec/rails_best_practices/analyzer_spec.rb +11 -11
- data/spec/rails_best_practices/core/check_spec.rb +1 -1
- data/spec/rails_best_practices/core/error_spec.rb +6 -6
- data/spec/rails_best_practices/core/klasses_spec.rb +26 -2
- data/spec/rails_best_practices/core/methods_spec.rb +18 -18
- data/spec/rails_best_practices/core/model_associations_spec.rb +6 -6
- data/spec/rails_best_practices/core/model_attributes_spec.rb +6 -6
- data/spec/rails_best_practices/core/modules_spec.rb +3 -3
- data/spec/rails_best_practices/core/routes_spec.rb +4 -4
- data/spec/rails_best_practices/core/runner_spec.rb +1 -1
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +18 -6
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +18 -5
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +17 -5
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +13 -13
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +44 -44
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +102 -78
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +25 -9
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +43 -23
- data/spec/rails_best_practices/reviews/check_save_return_value_spec.rb +34 -20
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +16 -5
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +25 -3
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +18 -7
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +30 -7
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +24 -8
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +24 -12
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +17 -5
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +14 -3
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +24 -13
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +25 -6
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +26 -4
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +31 -18
- data/spec/rails_best_practices/reviews/not_rescue_exception_spec.rb +23 -10
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +34 -7
- data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +19 -8
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +33 -19
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +25 -13
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +14 -4
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +91 -23
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +20 -5
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +66 -41
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +28 -4
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -7
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +45 -32
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +20 -9
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +23 -14
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +34 -7
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +21 -6
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +124 -79
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +12 -12
- data/spec/rails_best_practices/reviews/use_parenthesis_in_method_def_spec.rb +16 -4
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +39 -27
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +22 -8
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +39 -21
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +66 -7
- metadata +36 -37
- data/.ruby-gemset +0 -1
@@ -28,8 +28,8 @@ module RailsBestPractices
|
|
28
28
|
end
|
29
29
|
EOF
|
30
30
|
runner.review('config/routes.rb', content)
|
31
|
-
runner.
|
32
|
-
runner.errors[0].to_s.
|
31
|
+
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])")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should not restrict auto-generated routes with only" do
|
@@ -39,7 +39,7 @@ module RailsBestPractices
|
|
39
39
|
end
|
40
40
|
EOF
|
41
41
|
runner.review('config/routes.rb', content)
|
42
|
-
runner.
|
42
|
+
expect(runner.errors.size).to eq(0)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should not restrict auto-generated routes with except" do
|
@@ -49,7 +49,7 @@ module RailsBestPractices
|
|
49
49
|
end
|
50
50
|
EOF
|
51
51
|
runner.review('config/routes.rb', content)
|
52
|
-
runner.
|
52
|
+
expect(runner.errors.size).to eq(0)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not restrict auto-generated routes with only: :none" do
|
@@ -59,7 +59,7 @@ module RailsBestPractices
|
|
59
59
|
end
|
60
60
|
EOF
|
61
61
|
runner.review('config/routes.rb', content)
|
62
|
-
runner.
|
62
|
+
expect(runner.errors.size).to eq(0)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should not restrict auto-generated routes with except: :all" do
|
@@ -69,7 +69,7 @@ module RailsBestPractices
|
|
69
69
|
end
|
70
70
|
EOF
|
71
71
|
runner.review('config/routes.rb', content)
|
72
|
-
runner.
|
72
|
+
expect(runner.errors.size).to eq(0)
|
73
73
|
end
|
74
74
|
|
75
75
|
describe "specify a controller" do
|
@@ -80,8 +80,8 @@ module RailsBestPractices
|
|
80
80
|
end
|
81
81
|
EOF
|
82
82
|
runner.review('config/routes.rb', content)
|
83
|
-
runner.
|
84
|
-
runner.errors[0].to_s.
|
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
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -110,8 +110,8 @@ module RailsBestPractices
|
|
110
110
|
end
|
111
111
|
EOF
|
112
112
|
runner.review('config/routes.rb', content)
|
113
|
-
runner.
|
114
|
-
runner.errors[0].to_s.
|
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
115
|
end
|
116
116
|
|
117
117
|
it "should not restrict auto-generated routes with only" do
|
@@ -123,7 +123,7 @@ module RailsBestPractices
|
|
123
123
|
end
|
124
124
|
EOF
|
125
125
|
runner.review('config/routes.rb', content)
|
126
|
-
runner.
|
126
|
+
expect(runner.errors.size).to eq(0)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should not restrict auto-generated routes with except" do
|
@@ -135,7 +135,7 @@ module RailsBestPractices
|
|
135
135
|
end
|
136
136
|
EOF
|
137
137
|
runner.review('config/routes.rb', content)
|
138
|
-
runner.
|
138
|
+
expect(runner.errors.size).to eq(0)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -148,8 +148,8 @@ module RailsBestPractices
|
|
148
148
|
end
|
149
149
|
EOF
|
150
150
|
runner.review('config/routes.rb', content)
|
151
|
-
runner.
|
152
|
-
runner.errors[0].to_s.
|
151
|
+
expect(runner.errors.size).to eq(1)
|
152
|
+
expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should not restrict auto-generated routes with only" do
|
@@ -159,7 +159,7 @@ module RailsBestPractices
|
|
159
159
|
end
|
160
160
|
EOF
|
161
161
|
runner.review('config/routes.rb', content)
|
162
|
-
runner.
|
162
|
+
expect(runner.errors.size).to eq(0)
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should not restrict auto-generated routes with except" do
|
@@ -169,7 +169,7 @@ module RailsBestPractices
|
|
169
169
|
end
|
170
170
|
EOF
|
171
171
|
runner.review('config/routes.rb', content)
|
172
|
-
runner.
|
172
|
+
expect(runner.errors.size).to eq(0)
|
173
173
|
end
|
174
174
|
|
175
175
|
describe "specify a controller" do
|
@@ -180,8 +180,8 @@ module RailsBestPractices
|
|
180
180
|
end
|
181
181
|
EOF
|
182
182
|
runner.review('config/routes.rb', content)
|
183
|
-
runner.
|
184
|
-
runner.errors[0].to_s.
|
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
185
|
end
|
186
186
|
end
|
187
187
|
|
@@ -207,8 +207,8 @@ module RailsBestPractices
|
|
207
207
|
end
|
208
208
|
EOF
|
209
209
|
runner.review('config/routes.rb', content)
|
210
|
-
runner.
|
211
|
-
runner.errors[0].to_s.
|
210
|
+
expect(runner.errors.size).to eq(1)
|
211
|
+
expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])")
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
@@ -237,8 +237,8 @@ module RailsBestPractices
|
|
237
237
|
end
|
238
238
|
EOF
|
239
239
|
runner.review('config/routes.rb', content)
|
240
|
-
runner.
|
241
|
-
runner.errors[0].to_s.
|
240
|
+
expect(runner.errors.size).to eq(1)
|
241
|
+
expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])")
|
242
242
|
end
|
243
243
|
|
244
244
|
it "should not restrict auto-generated routes with only" do
|
@@ -250,7 +250,7 @@ module RailsBestPractices
|
|
250
250
|
end
|
251
251
|
EOF
|
252
252
|
runner.review('config/routes.rb', content)
|
253
|
-
runner.
|
253
|
+
expect(runner.errors.size).to eq(0)
|
254
254
|
end
|
255
255
|
|
256
256
|
it "should not restrict auto-generated routes with except" do
|
@@ -262,7 +262,7 @@ module RailsBestPractices
|
|
262
262
|
end
|
263
263
|
EOF
|
264
264
|
runner.review('config/routes.rb', content)
|
265
|
-
runner.
|
265
|
+
expect(runner.errors.size).to eq(0)
|
266
266
|
end
|
267
267
|
end
|
268
268
|
end
|
@@ -290,8 +290,8 @@ module RailsBestPractices
|
|
290
290
|
end
|
291
291
|
EOF
|
292
292
|
runner.review('config/routes.rb', content)
|
293
|
-
runner.
|
294
|
-
runner.errors[0].to_s.
|
293
|
+
expect(runner.errors.size).to eq(1)
|
294
|
+
expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])")
|
295
295
|
end
|
296
296
|
|
297
297
|
it "should not restrict auto-generated routes with only" do
|
@@ -301,7 +301,7 @@ module RailsBestPractices
|
|
301
301
|
end
|
302
302
|
EOF
|
303
303
|
runner.review('config/routes.rb', content)
|
304
|
-
runner.
|
304
|
+
expect(runner.errors.size).to eq(0)
|
305
305
|
end
|
306
306
|
|
307
307
|
it "should not restrict auto-generated routes with except" do
|
@@ -311,7 +311,7 @@ module RailsBestPractices
|
|
311
311
|
end
|
312
312
|
EOF
|
313
313
|
runner.review('config/routes.rb', content)
|
314
|
-
runner.
|
314
|
+
expect(runner.errors.size).to eq(0)
|
315
315
|
end
|
316
316
|
end
|
317
317
|
|
@@ -323,8 +323,8 @@ module RailsBestPractices
|
|
323
323
|
end
|
324
324
|
EOF
|
325
325
|
runner.review('config/routes.rb', content)
|
326
|
-
runner.
|
327
|
-
runner.errors[0].to_s.
|
326
|
+
expect(runner.errors.size).to eq(1)
|
327
|
+
expect(runner.errors[0].to_s).to eq("config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])")
|
328
328
|
end
|
329
329
|
|
330
330
|
it "should not restrict auto-generated routes with only" do
|
@@ -334,7 +334,7 @@ module RailsBestPractices
|
|
334
334
|
end
|
335
335
|
EOF
|
336
336
|
runner.review('config/routes.rb', content)
|
337
|
-
runner.
|
337
|
+
expect(runner.errors.size).to eq(0)
|
338
338
|
end
|
339
339
|
|
340
340
|
it "should not restrict auto-generated routes with except" do
|
@@ -344,7 +344,20 @@ module RailsBestPractices
|
|
344
344
|
end
|
345
345
|
EOF
|
346
346
|
runner.review('config/routes.rb', content)
|
347
|
-
runner.
|
347
|
+
expect(runner.errors.size).to eq(0)
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should not check ignored files" do
|
351
|
+
runner = Core::Runner.new(prepares: Prepares::ControllerPrepare.new,
|
352
|
+
reviews: RestrictAutoGeneratedRoutesReview.new(ignored_files: /config\/routes\.rb/))
|
353
|
+
|
354
|
+
content =<<-EOF
|
355
|
+
ActionController::Routing::Routes.draw do |map|
|
356
|
+
map.resource :account
|
357
|
+
end
|
358
|
+
EOF
|
359
|
+
runner.review('config/routes.rb', content)
|
360
|
+
expect(runner.errors.size).to eq(0)
|
348
361
|
end
|
349
362
|
end
|
350
363
|
end
|
@@ -12,8 +12,8 @@ module RailsBestPractices
|
|
12
12
|
end
|
13
13
|
EOF
|
14
14
|
runner.review("app/controllers/posts_controller.rb", content)
|
15
|
-
runner.
|
16
|
-
runner.errors[0].to_s.
|
15
|
+
expect(runner.errors.size).to eq(1)
|
16
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - simplify render in controllers")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should simplify render actions's template" do
|
@@ -23,8 +23,8 @@ module RailsBestPractices
|
|
23
23
|
end
|
24
24
|
EOF
|
25
25
|
runner.review("app/controllers/posts_controller.rb", content)
|
26
|
-
runner.
|
27
|
-
runner.errors[0].to_s.
|
26
|
+
expect(runner.errors.size).to eq(1)
|
27
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - simplify render in controllers")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should simplify render an arbitrary file" do
|
@@ -34,8 +34,8 @@ module RailsBestPractices
|
|
34
34
|
end
|
35
35
|
EOF
|
36
36
|
runner.review("app/controllers/posts_controller.rb", content)
|
37
|
-
runner.
|
38
|
-
runner.errors[0].to_s.
|
37
|
+
expect(runner.errors.size).to eq(1)
|
38
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - simplify render in controllers")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should not simplify render action view" do
|
@@ -43,7 +43,7 @@ module RailsBestPractices
|
|
43
43
|
render :edit
|
44
44
|
EOF
|
45
45
|
runner.review("app/controllers/posts_controller", content)
|
46
|
-
runner.
|
46
|
+
expect(runner.errors.size).to eq(0)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should not simplify render actions's template" do
|
@@ -53,7 +53,7 @@ module RailsBestPractices
|
|
53
53
|
end
|
54
54
|
EOF
|
55
55
|
runner.review("app/controllers/posts_controller.rb", content)
|
56
|
-
runner.
|
56
|
+
expect(runner.errors.size).to eq(0)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should not simplify render an arbitrary file" do
|
@@ -63,7 +63,18 @@ module RailsBestPractices
|
|
63
63
|
end
|
64
64
|
EOF
|
65
65
|
runner.review("app/controllers/posts_controller.rb", content)
|
66
|
-
runner.
|
66
|
+
expect(runner.errors.size).to eq(0)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not check ignored files" do
|
70
|
+
runner = Core::Runner.new(reviews: SimplifyRenderInControllersReview.new(ignored_files: /posts_controller/))
|
71
|
+
content =<<-EOF
|
72
|
+
def edit
|
73
|
+
render action: :edit
|
74
|
+
end
|
75
|
+
EOF
|
76
|
+
runner.review("app/controllers/posts_controller.rb", content)
|
77
|
+
expect(runner.errors.size).to eq(0)
|
67
78
|
end
|
68
79
|
end
|
69
80
|
end
|
@@ -10,8 +10,8 @@ module RailsBestPractices
|
|
10
10
|
<%= render partial: 'sidebar' %>
|
11
11
|
EOF
|
12
12
|
runner.review('app/views/posts/index.html.erb', content)
|
13
|
-
runner.
|
14
|
-
runner.errors[0].to_s.
|
13
|
+
expect(runner.errors.size).to eq(1)
|
14
|
+
expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - simplify render in views")
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should simplify render partial with object" do
|
@@ -19,8 +19,8 @@ module RailsBestPractices
|
|
19
19
|
<%= render partial: 'post', object: @post %>
|
20
20
|
EOF
|
21
21
|
runner.review('app/views/posts/index.html.erb', content)
|
22
|
-
runner.
|
23
|
-
runner.errors[0].to_s.
|
22
|
+
expect(runner.errors.size).to eq(1)
|
23
|
+
expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - simplify render in views")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should simplify render partial with collection" do
|
@@ -28,8 +28,8 @@ module RailsBestPractices
|
|
28
28
|
<%= render partial: 'posts', collection: @posts %>
|
29
29
|
EOF
|
30
30
|
runner.review('app/views/posts/index.html.erb', content)
|
31
|
-
runner.
|
32
|
-
runner.errors[0].to_s.
|
31
|
+
expect(runner.errors.size).to eq(1)
|
32
|
+
expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - simplify render in views")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should simplify render partial with local variables" do
|
@@ -37,8 +37,8 @@ module RailsBestPractices
|
|
37
37
|
<%= render partial: 'comment', locals: { parent: post } %>
|
38
38
|
EOF
|
39
39
|
runner.review('app/views/posts/index.html.erb', content)
|
40
|
-
runner.
|
41
|
-
runner.errors[0].to_s.
|
40
|
+
expect(runner.errors.size).to eq(1)
|
41
|
+
expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - simplify render in views")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should not simplify render simple partial" do
|
@@ -47,7 +47,7 @@ module RailsBestPractices
|
|
47
47
|
<%= render 'shared/sidebar' %>
|
48
48
|
EOF
|
49
49
|
runner.review('app/views/posts/index.html.erb', content)
|
50
|
-
runner.
|
50
|
+
expect(runner.errors.size).to eq(0)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should not simplify render partial with object" do
|
@@ -55,7 +55,7 @@ module RailsBestPractices
|
|
55
55
|
<%= render @post %>
|
56
56
|
EOF
|
57
57
|
runner.review('app/views/posts/index.html.erb', content)
|
58
|
-
runner.
|
58
|
+
expect(runner.errors.size).to eq(0)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should not simplify render partial with collection" do
|
@@ -63,7 +63,7 @@ module RailsBestPractices
|
|
63
63
|
<%= render @posts %>
|
64
64
|
EOF
|
65
65
|
runner.review('app/views/posts/index.html.erb', content)
|
66
|
-
runner.
|
66
|
+
expect(runner.errors.size).to eq(0)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should not simplify render partial with local variables" do
|
@@ -71,7 +71,7 @@ module RailsBestPractices
|
|
71
71
|
<%= render 'comment', parent: post %>
|
72
72
|
EOF
|
73
73
|
runner.review('app/views/posts/index.html.erb', content)
|
74
|
-
runner.
|
74
|
+
expect(runner.errors.size).to eq(0)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should not simplify render partial with complex partial" do
|
@@ -79,7 +79,7 @@ module RailsBestPractices
|
|
79
79
|
<%= render partial: 'shared/post', object: @post %>
|
80
80
|
EOF
|
81
81
|
runner.review('app/views/posts/index.html.erb', content)
|
82
|
-
runner.
|
82
|
+
expect(runner.errors.size).to eq(0)
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should not simplify render partial with layout option" do
|
@@ -87,7 +87,16 @@ module RailsBestPractices
|
|
87
87
|
<%= render partial: 'post', layout: 'post' %>
|
88
88
|
EOF
|
89
89
|
runner.review('app/views/posts/index.html.erb', content)
|
90
|
-
runner.
|
90
|
+
expect(runner.errors.size).to eq(0)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not check ignored files" do
|
94
|
+
runner = Core::Runner.new(reviews: SimplifyRenderInViewsReview.new(ignored_files: /views\/posts\/index/))
|
95
|
+
content =<<-EOF
|
96
|
+
<%= render partial: 'sidebar' %>
|
97
|
+
EOF
|
98
|
+
runner.review('app/views/posts/index.html.erb', content)
|
99
|
+
expect(runner.errors.size).to eq(0)
|
91
100
|
end
|
92
101
|
end
|
93
102
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module RailsBestPractices
|
4
4
|
module Reviews
|
5
5
|
describe UseBeforeFilterReview do
|
6
|
-
let(:runner) { Core::Runner.new(reviews: UseBeforeFilterReview.new(
|
6
|
+
let(:runner) { Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2)) }
|
7
7
|
|
8
8
|
it "should use before_filter" do
|
9
9
|
content = <<-EOF
|
@@ -28,8 +28,8 @@ module RailsBestPractices
|
|
28
28
|
end
|
29
29
|
EOF
|
30
30
|
runner.review('app/controllers/posts_controller.rb', content)
|
31
|
-
runner.
|
32
|
-
runner.errors[0].to_s.
|
31
|
+
expect(runner.errors.size).to eq(1)
|
32
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2,6,10,15 - use before_filter for show,edit,update,destroy")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should not use before_filter when equal to customize count" do
|
@@ -45,7 +45,7 @@ module RailsBestPractices
|
|
45
45
|
end
|
46
46
|
EOF
|
47
47
|
runner.review('app/controllers/posts_controller.rb', content)
|
48
|
-
runner.
|
48
|
+
expect(runner.errors.size).to eq(0)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not use before_filter" do
|
@@ -68,7 +68,7 @@ module RailsBestPractices
|
|
68
68
|
end
|
69
69
|
EOF
|
70
70
|
runner.review('app/controllers/posts_controller.rb', content)
|
71
|
-
runner.
|
71
|
+
expect(runner.errors.size).to eq(0)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should not use before_filter by nil" do
|
@@ -81,7 +81,7 @@ module RailsBestPractices
|
|
81
81
|
end
|
82
82
|
EOF
|
83
83
|
runner.review('app/controllers/posts_controller.rb', content)
|
84
|
-
runner.
|
84
|
+
expect(runner.errors.size).to eq(0)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should not use before_filter for protected/private methods" do
|
@@ -100,7 +100,34 @@ module RailsBestPractices
|
|
100
100
|
end
|
101
101
|
EOF
|
102
102
|
runner.review('app/controllers/posts_controller.rb', content)
|
103
|
-
runner.
|
103
|
+
expect(runner.errors.size).to eq(0)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should not check ignored files" do
|
107
|
+
runner = Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2, ignored_files: /posts_controller/))
|
108
|
+
content = <<-EOF
|
109
|
+
class PostsController < ApplicationController
|
110
|
+
def show
|
111
|
+
@post = current_user.posts.find(params[:id])
|
112
|
+
end
|
113
|
+
|
114
|
+
def edit
|
115
|
+
@post = current_user.posts.find(params[:id])
|
116
|
+
end
|
117
|
+
|
118
|
+
def update
|
119
|
+
@post = current_user.posts.find(params[:id])
|
120
|
+
@post.update_attributes(params[:post])
|
121
|
+
end
|
122
|
+
|
123
|
+
def destroy
|
124
|
+
@post = current_user.posts.find(params[:id])
|
125
|
+
@post.destroy
|
126
|
+
end
|
127
|
+
end
|
128
|
+
EOF
|
129
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
130
|
+
expect(runner.errors.size).to eq(1)
|
104
131
|
end
|
105
132
|
end
|
106
133
|
end
|
@@ -16,8 +16,8 @@ module RailsBestPractices
|
|
16
16
|
end
|
17
17
|
EOF
|
18
18
|
runner.review('app/controllers/posts_controller.rb', content)
|
19
|
-
runner.
|
20
|
-
runner.errors[0].to_s.
|
19
|
+
expect(runner.errors.size).to eq(1)
|
20
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - use model association (for @post)")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not use model association without association assign" do
|
@@ -30,7 +30,7 @@ module RailsBestPractices
|
|
30
30
|
end
|
31
31
|
EOF
|
32
32
|
runner.review('app/controllers/posts_controller.rb', content)
|
33
|
-
runner.
|
33
|
+
expect(runner.errors.size).to eq(0)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should use model association for local variable" do
|
@@ -44,8 +44,8 @@ module RailsBestPractices
|
|
44
44
|
end
|
45
45
|
EOF
|
46
46
|
runner.review('app/controllers/posts_controller.rb', content)
|
47
|
-
runner.
|
48
|
-
runner.errors[0].to_s.
|
47
|
+
expect(runner.errors.size).to eq(1)
|
48
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - use model association (for post)")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not use model association" do
|
@@ -58,7 +58,22 @@ module RailsBestPractices
|
|
58
58
|
end
|
59
59
|
EOF
|
60
60
|
runner.review('app/controllers/posts_controller.rb', content)
|
61
|
-
runner.
|
61
|
+
expect(runner.errors.size).to eq(0)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not check ignored files" do
|
65
|
+
runner = Core::Runner.new(reviews: UseModelAssociationReview.new(ignored_files: /posts_controller/))
|
66
|
+
content = <<-EOF
|
67
|
+
class PostsController < ApplicationController
|
68
|
+
def create
|
69
|
+
@post = Post.new(params[:post])
|
70
|
+
@post.user_id = current_user.id
|
71
|
+
@post.save
|
72
|
+
end
|
73
|
+
end
|
74
|
+
EOF
|
75
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
76
|
+
expect(runner.errors.size).to eq(0)
|
62
77
|
end
|
63
78
|
end
|
64
79
|
end
|