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
|
EOF
|
29
29
|
runner.review('app/controllers/posts_controller.rb', content)
|
30
30
|
runner.after_review
|
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/models/post.rb:4 - remove unused methods (Post#find_by_sql)")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should not remove unused methods with except_methods" do
|
@@ -41,7 +41,7 @@ module RailsBestPractices
|
|
41
41
|
runner.prepare('app/models/post.rb', content)
|
42
42
|
runner.review('app/models/post.rb', content)
|
43
43
|
runner.after_review
|
44
|
-
runner.
|
44
|
+
expect(runner.errors.size).to eq(0)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not remove unused methods with var_ref" do
|
@@ -65,7 +65,7 @@ module RailsBestPractices
|
|
65
65
|
EOF
|
66
66
|
runner.review('app/controllers/posts_controller.rb', content)
|
67
67
|
runner.after_review
|
68
|
-
runner.
|
68
|
+
expect(runner.errors.size).to eq(0)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should not remove unused methods with callback" do
|
@@ -79,7 +79,7 @@ module RailsBestPractices
|
|
79
79
|
runner.prepare('app/models/post.rb', content)
|
80
80
|
runner.review('app/models/post.rb', content)
|
81
81
|
runner.after_review
|
82
|
-
runner.
|
82
|
+
expect(runner.errors.size).to eq(0)
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should not remove unused method with command" do
|
@@ -103,7 +103,7 @@ module RailsBestPractices
|
|
103
103
|
EOF
|
104
104
|
runner.review('app/controllers/posts_controller.rb', content)
|
105
105
|
runner.after_review
|
106
|
-
runner.
|
106
|
+
expect(runner.errors.size).to eq(0)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should not remove unused method with call" do
|
@@ -127,7 +127,7 @@ module RailsBestPractices
|
|
127
127
|
EOF
|
128
128
|
runner.review('app/controllers/posts_controller.rb', content)
|
129
129
|
runner.after_review
|
130
|
-
runner.
|
130
|
+
expect(runner.errors.size).to eq(0)
|
131
131
|
end
|
132
132
|
|
133
133
|
it "should not remove unused method with message" do
|
@@ -153,7 +153,7 @@ module RailsBestPractices
|
|
153
153
|
EOF
|
154
154
|
runner.review('app/controllers/posts_controller.rb', content)
|
155
155
|
runner.after_review
|
156
|
-
runner.
|
156
|
+
expect(runner.errors.size).to eq(0)
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should not remove unused method with validation condition" do
|
@@ -167,7 +167,7 @@ module RailsBestPractices
|
|
167
167
|
runner.prepare('app/models/post.rb', content)
|
168
168
|
runner.review('app/models/post.rb', content)
|
169
169
|
runner.after_review
|
170
|
-
runner.
|
170
|
+
expect(runner.errors.size).to eq(0)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "should not remove unused method with aasm" do
|
@@ -181,7 +181,7 @@ module RailsBestPractices
|
|
181
181
|
runner.prepare('app/models/post.rb', content)
|
182
182
|
runner.review('app/models/post.rb', content)
|
183
183
|
runner.after_review
|
184
|
-
runner.
|
184
|
+
expect(runner.errors.size).to eq(0)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should not remove unused method with initialize" do
|
@@ -194,7 +194,7 @@ module RailsBestPractices
|
|
194
194
|
runner.prepare('app/models/post.rb', content)
|
195
195
|
runner.review('app/models/post.rb', content)
|
196
196
|
runner.after_review
|
197
|
-
runner.
|
197
|
+
expect(runner.errors.size).to eq(0)
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
@@ -207,8 +207,8 @@ module RailsBestPractices
|
|
207
207
|
EOF
|
208
208
|
runner.prepare('app/models/post.rb', content)
|
209
209
|
runner.after_review
|
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("app/models/post.rb:2 - remove unused methods (Post#fetch)")
|
212
212
|
end
|
213
213
|
|
214
214
|
it "should not remove unused methods" do
|
@@ -227,7 +227,7 @@ module RailsBestPractices
|
|
227
227
|
EOF
|
228
228
|
runner.review('app/controllers/posts_controller.rb', content)
|
229
229
|
runner.after_review
|
230
|
-
runner.
|
230
|
+
expect(runner.errors.size).to eq(0)
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should not remove unused methods for attribute assignment" do
|
@@ -239,7 +239,7 @@ module RailsBestPractices
|
|
239
239
|
runner.prepare('app/models/post.rb', content)
|
240
240
|
runner.review('app/models/post.rb', content)
|
241
241
|
runner.after_review
|
242
|
-
runner.
|
242
|
+
expect(runner.errors.size).to eq(0)
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should not remove unused methods for try" do
|
@@ -259,7 +259,7 @@ module RailsBestPractices
|
|
259
259
|
EOF
|
260
260
|
runner.review('app/controllers/posts_controller.rb', content)
|
261
261
|
runner.after_review
|
262
|
-
runner.
|
262
|
+
expect(runner.errors.size).to eq(0)
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should not remove unused methods for send" do
|
@@ -279,7 +279,7 @@ module RailsBestPractices
|
|
279
279
|
EOF
|
280
280
|
runner.review('app/controllers/posts_controller.rb', content)
|
281
281
|
runner.after_review
|
282
|
-
runner.
|
282
|
+
expect(runner.errors.size).to eq(0)
|
283
283
|
end
|
284
284
|
|
285
285
|
it "should remove unused methods for send string_embexpre" do
|
@@ -300,7 +300,7 @@ module RailsBestPractices
|
|
300
300
|
EOF
|
301
301
|
runner.review('app/controllers/posts_controller.rb', content)
|
302
302
|
runner.after_review
|
303
|
-
runner.
|
303
|
+
expect(runner.errors.size).to eq(1)
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should remove unused methods for send variable" do
|
@@ -321,7 +321,7 @@ module RailsBestPractices
|
|
321
321
|
EOF
|
322
322
|
runner.review('app/controllers/posts_controller.rb', content)
|
323
323
|
runner.after_review
|
324
|
-
runner.
|
324
|
+
expect(runner.errors.size).to eq(1)
|
325
325
|
end
|
326
326
|
end
|
327
327
|
|
@@ -344,8 +344,8 @@ module RailsBestPractices
|
|
344
344
|
EOF
|
345
345
|
runner.review('app/controllers/posts_controller.rb', content)
|
346
346
|
runner.after_review
|
347
|
-
runner.
|
348
|
-
runner.errors[0].to_s.
|
347
|
+
expect(runner.errors.size).to eq(1)
|
348
|
+
expect(runner.errors[0].to_s).to eq("app/models/post.rb:3 - remove unused methods (Post#test)")
|
349
349
|
end
|
350
350
|
|
351
351
|
it "should not remove unused methods" do
|
@@ -375,7 +375,7 @@ module RailsBestPractices
|
|
375
375
|
EOF
|
376
376
|
runner.review('app/controllers/posts_controller.rb', content)
|
377
377
|
runner.after_review
|
378
|
-
runner.
|
378
|
+
expect(runner.errors.size).to eq(0)
|
379
379
|
end
|
380
380
|
end
|
381
381
|
|
@@ -397,7 +397,7 @@ module RailsBestPractices
|
|
397
397
|
EOF
|
398
398
|
runner.review("app/controllers/posts_controller.rb", content)
|
399
399
|
runner.after_review
|
400
|
-
runner.
|
400
|
+
expect(runner.errors.size).to eq(0)
|
401
401
|
end
|
402
402
|
|
403
403
|
it "should remove unused named_scope" do
|
@@ -409,8 +409,8 @@ module RailsBestPractices
|
|
409
409
|
runner.prepare("app/models/post.rb", content)
|
410
410
|
runner.review("app/models/post.rb", content)
|
411
411
|
runner.after_review
|
412
|
-
runner.
|
413
|
-
runner.errors[0].to_s.
|
412
|
+
expect(runner.errors.size).to eq(1)
|
413
|
+
expect(runner.errors[0].to_s).to eq("app/models/post.rb:2 - remove unused methods (Post#active)")
|
414
414
|
end
|
415
415
|
end
|
416
416
|
|
@@ -432,7 +432,7 @@ module RailsBestPractices
|
|
432
432
|
EOF
|
433
433
|
runner.review("app/controllers/posts_controller.rb", content)
|
434
434
|
runner.after_review
|
435
|
-
runner.
|
435
|
+
expect(runner.errors.size).to eq(0)
|
436
436
|
end
|
437
437
|
|
438
438
|
it "should remove unused named_scope" do
|
@@ -444,8 +444,8 @@ module RailsBestPractices
|
|
444
444
|
runner.prepare("app/models/post.rb", content)
|
445
445
|
runner.review("app/models/post.rb", content)
|
446
446
|
runner.after_review
|
447
|
-
runner.
|
448
|
-
runner.errors[0].to_s.
|
447
|
+
expect(runner.errors.size).to eq(1)
|
448
|
+
expect(runner.errors[0].to_s).to eq("app/models/post.rb:2 - remove unused methods (Post#active)")
|
449
449
|
end
|
450
450
|
end
|
451
451
|
|
@@ -468,7 +468,7 @@ module RailsBestPractices
|
|
468
468
|
EOF
|
469
469
|
runner.review("app/controllers/posts_controller.rb", content)
|
470
470
|
runner.after_review
|
471
|
-
runner.
|
471
|
+
expect(runner.errors.size).to eq(0)
|
472
472
|
end
|
473
473
|
|
474
474
|
it "should not remove unused method with symbol alias" do
|
@@ -489,7 +489,7 @@ module RailsBestPractices
|
|
489
489
|
EOF
|
490
490
|
runner.review("app/controllers/posts_controller.rb", content)
|
491
491
|
runner.after_review
|
492
|
-
runner.
|
492
|
+
expect(runner.errors.size).to eq(0)
|
493
493
|
end
|
494
494
|
|
495
495
|
it "should not remove unused method with alias_method" do
|
@@ -510,7 +510,7 @@ module RailsBestPractices
|
|
510
510
|
EOF
|
511
511
|
runner.review("app/controllers/posts_controller.rb", content)
|
512
512
|
runner.after_review
|
513
|
-
runner.
|
513
|
+
expect(runner.errors.size).to eq(0)
|
514
514
|
end
|
515
515
|
|
516
516
|
it "should not remove unused method with alias_method_chain" do
|
@@ -531,7 +531,7 @@ module RailsBestPractices
|
|
531
531
|
EOF
|
532
532
|
runner.review("app/controllers/posts_controller.rb", content)
|
533
533
|
runner.after_review
|
534
|
-
runner.
|
534
|
+
expect(runner.errors.size).to eq(0)
|
535
535
|
end
|
536
536
|
end
|
537
537
|
|
@@ -549,7 +549,7 @@ module RailsBestPractices
|
|
549
549
|
runner.prepare("app/models/post.rb", content)
|
550
550
|
runner.review("app/models/post.rb", content)
|
551
551
|
runner.after_review
|
552
|
-
runner.
|
552
|
+
expect(runner.errors.size).to eq(0)
|
553
553
|
end
|
554
554
|
end
|
555
555
|
|
@@ -568,7 +568,7 @@ module RailsBestPractices
|
|
568
568
|
runner.prepare("app/models/post.rb", content)
|
569
569
|
runner.review("app/models/post.rb", content)
|
570
570
|
runner.after_review
|
571
|
-
runner.
|
571
|
+
expect(runner.errors.size).to eq(0)
|
572
572
|
end
|
573
573
|
end
|
574
574
|
|
@@ -585,7 +585,7 @@ module RailsBestPractices
|
|
585
585
|
runner.prepare("app/models/post.rb", content)
|
586
586
|
runner.review("app/models/post.rb", content)
|
587
587
|
runner.after_review
|
588
|
-
runner.
|
588
|
+
expect(runner.errors.size).to eq(0)
|
589
589
|
end
|
590
590
|
|
591
591
|
it "should not remove unused method for validate_on_create and validate_on_update" do
|
@@ -602,7 +602,7 @@ module RailsBestPractices
|
|
602
602
|
runner.prepare("app/models/post.rb", content)
|
603
603
|
runner.review("app/models/post.rb", content)
|
604
604
|
runner.after_review
|
605
|
-
runner.
|
605
|
+
expect(runner.errors.size).to eq(0)
|
606
606
|
end
|
607
607
|
|
608
608
|
it "should not remove unused methods for to_param" do
|
@@ -616,7 +616,7 @@ module RailsBestPractices
|
|
616
616
|
runner.prepare("app/models/post.rb", content)
|
617
617
|
runner.review("app/models/post.rb", content)
|
618
618
|
runner.after_review
|
619
|
-
runner.
|
619
|
+
expect(runner.errors.size).to eq(0)
|
620
620
|
end
|
621
621
|
end
|
622
622
|
|
@@ -634,7 +634,7 @@ module RailsBestPractices
|
|
634
634
|
EOF
|
635
635
|
runner.review("app/views/categories/_form.html.erb", content)
|
636
636
|
runner.after_review
|
637
|
-
runner.
|
637
|
+
expect(runner.errors.size).to eq(0)
|
638
638
|
end
|
639
639
|
|
640
640
|
it "should not remove unused method for command collection_select" do
|
@@ -650,7 +650,7 @@ module RailsBestPractices
|
|
650
650
|
EOF
|
651
651
|
runner.review("app/views/categories/_form.html.erb", content)
|
652
652
|
runner.after_review
|
653
|
-
runner.
|
653
|
+
expect(runner.errors.size).to eq(0)
|
654
654
|
end
|
655
655
|
|
656
656
|
it "should not remove unused method for options_from_collection_for_select" do
|
@@ -666,7 +666,7 @@ module RailsBestPractices
|
|
666
666
|
EOF
|
667
667
|
runner.review("app/views/categories/_form.html.erb", content)
|
668
668
|
runner.after_review
|
669
|
-
runner.
|
669
|
+
expect(runner.errors.size).to eq(0)
|
670
670
|
end
|
671
671
|
end
|
672
672
|
|
@@ -686,7 +686,7 @@ module RailsBestPractices
|
|
686
686
|
EOF
|
687
687
|
runner.review("app/views/users/show.json.rabl", content)
|
688
688
|
runner.after_review
|
689
|
-
runner.
|
689
|
+
expect(runner.errors.size).to eq(0)
|
690
690
|
end
|
691
691
|
|
692
692
|
it "should not skip :call as call message" do
|
@@ -703,6 +703,31 @@ module RailsBestPractices
|
|
703
703
|
runner.prepare("app/mixins/date_range.rb", content)
|
704
704
|
runner.review("app/mixins/date_range.rb", content)
|
705
705
|
end
|
706
|
+
|
707
|
+
it "should not check ignored files" do
|
708
|
+
runner = Core::Runner.new(prepares: Prepares::ModelPrepare.new,
|
709
|
+
reviews: RemoveUnusedMethodsInModelsReview.new(except_methods: [], ignored_files: /post/))
|
710
|
+
|
711
|
+
content =<<-EOF
|
712
|
+
class Post < ActiveRecord::Base
|
713
|
+
def find; end
|
714
|
+
private
|
715
|
+
def find_by_sql; end
|
716
|
+
end
|
717
|
+
EOF
|
718
|
+
runner.prepare('app/models/post.rb', content)
|
719
|
+
runner.review('app/models/post.rb', content)
|
720
|
+
content =<<-EOF
|
721
|
+
class PostsController < ApplicationController
|
722
|
+
def get
|
723
|
+
Post.new.find
|
724
|
+
end
|
725
|
+
end
|
726
|
+
EOF
|
727
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
728
|
+
runner.after_review
|
729
|
+
expect(runner.errors.size).to eq(0)
|
730
|
+
end
|
706
731
|
end
|
707
732
|
end
|
708
733
|
end
|
data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb
CHANGED
@@ -25,8 +25,8 @@ module RailsBestPractices
|
|
25
25
|
end
|
26
26
|
EOF
|
27
27
|
runner.review('app/controllers/invoices_controller.rb', content)
|
28
|
-
runner.
|
29
|
-
runner.errors[0].to_s.
|
28
|
+
expect(runner.errors.size).to eq(1)
|
29
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/invoices_controller.rb:2 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should not replace complex creation with factory method with simple creation" do
|
@@ -41,7 +41,7 @@ module RailsBestPractices
|
|
41
41
|
end
|
42
42
|
EOF
|
43
43
|
runner.review('app/controllers/invoices_controller.rb', content)
|
44
|
-
runner.
|
44
|
+
expect(runner.errors.size).to eq(0)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not replace complex creation with factory method when attrasgn_count is 5" do
|
@@ -65,7 +65,31 @@ module RailsBestPractices
|
|
65
65
|
EOF
|
66
66
|
runner = Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new('attribute_assignment_count' => 5))
|
67
67
|
runner.review('app/controllers/invoices_controller.rb', content)
|
68
|
-
runner.
|
68
|
+
expect(runner.errors.size).to eq(0)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not check ignored files" do
|
72
|
+
runner = Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new(ignored_files: /invoices_controller/))
|
73
|
+
content = <<-EOF
|
74
|
+
class InvoiceController < ApplicationController
|
75
|
+
def create
|
76
|
+
@invoice = Invoice.new(params[:invoice])
|
77
|
+
@invoice.address = current_user.address
|
78
|
+
@invoice.phone = current_user.phone
|
79
|
+
@invoice.vip = (@invoice.amount > 1000)
|
80
|
+
|
81
|
+
if Time.now.day > 15
|
82
|
+
@invoice.deliver_time = Time.now + 2.month
|
83
|
+
else
|
84
|
+
@invoice.deliver_time = Time.now + 1.month
|
85
|
+
end
|
86
|
+
|
87
|
+
@invoice.save
|
88
|
+
end
|
89
|
+
end
|
90
|
+
EOF
|
91
|
+
runner.review('app/controllers/invoices_controller.rb', content)
|
92
|
+
expect(runner.errors.size).to eq(0)
|
69
93
|
end
|
70
94
|
end
|
71
95
|
end
|
data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
CHANGED
@@ -10,8 +10,8 @@ module RailsBestPractices
|
|
10
10
|
<%= @post.title %>
|
11
11
|
EOF
|
12
12
|
runner.review('app/views/posts/_post.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/_post.html.erb:1 - replace instance variable with local variable")
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should replace instance variable with local varialbe in haml file" do
|
@@ -19,8 +19,8 @@ module RailsBestPractices
|
|
19
19
|
= @post.title
|
20
20
|
EOF
|
21
21
|
runner.review('app/views/posts/_post.html.haml', 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/_post.html.haml:1 - replace instance variable with local variable")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should replace instance variable with local varialbe in slim file" do
|
@@ -28,8 +28,8 @@ module RailsBestPractices
|
|
28
28
|
= @post.title
|
29
29
|
EOF
|
30
30
|
runner.review('app/views/posts/_post.html.slim', 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/_post.html.slim:1 - replace instance variable with local variable")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should not replace instance variable with local varialbe" do
|
@@ -37,7 +37,16 @@ module RailsBestPractices
|
|
37
37
|
<%= post.title %>
|
38
38
|
EOF
|
39
39
|
runner.review('app/views/posts/_post.html.erb', content)
|
40
|
-
runner.
|
40
|
+
expect(runner.errors.size).to eq(0)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not check ignored files" do
|
44
|
+
runner = Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new(ignored_files: /views\/posts/))
|
45
|
+
content = <<-EOF
|
46
|
+
<%= @post.title %>
|
47
|
+
EOF
|
48
|
+
runner.review('app/views/posts/_post.html.erb', content)
|
49
|
+
expect(runner.errors.size).to eq(0)
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|