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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -0
  4. data/README.md +26 -6
  5. data/lib/rails_best_practices/core/check.rb +15 -2
  6. data/lib/rails_best_practices/core/klasses.rb +13 -3
  7. data/lib/rails_best_practices/core/model_associations.rb +1 -1
  8. data/lib/rails_best_practices/core/runner.rb +2 -0
  9. data/lib/rails_best_practices/lexicals/long_line_check.rb +1 -1
  10. data/lib/rails_best_practices/prepares/route_prepare.rb +17 -1
  11. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
  12. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +2 -2
  13. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +1 -1
  14. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +1 -1
  15. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
  16. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
  17. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +1 -1
  18. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +1 -1
  19. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +1 -2
  20. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +1 -1
  21. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +2 -1
  22. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +15 -26
  23. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -2
  24. data/lib/rails_best_practices/version.rb +1 -1
  25. data/spec/rails_best_practices/analyzer_spec.rb +11 -11
  26. data/spec/rails_best_practices/core/check_spec.rb +1 -1
  27. data/spec/rails_best_practices/core/error_spec.rb +6 -6
  28. data/spec/rails_best_practices/core/klasses_spec.rb +26 -2
  29. data/spec/rails_best_practices/core/methods_spec.rb +18 -18
  30. data/spec/rails_best_practices/core/model_associations_spec.rb +6 -6
  31. data/spec/rails_best_practices/core/model_attributes_spec.rb +6 -6
  32. data/spec/rails_best_practices/core/modules_spec.rb +3 -3
  33. data/spec/rails_best_practices/core/routes_spec.rb +4 -4
  34. data/spec/rails_best_practices/core/runner_spec.rb +1 -1
  35. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +18 -6
  36. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +18 -5
  37. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +17 -5
  38. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +1 -1
  39. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +13 -13
  40. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +1 -1
  41. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +2 -2
  42. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +2 -2
  43. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +1 -1
  44. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +44 -44
  45. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +102 -78
  46. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +6 -6
  47. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +25 -9
  48. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +43 -23
  49. data/spec/rails_best_practices/reviews/check_save_return_value_spec.rb +34 -20
  50. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +16 -5
  51. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +25 -3
  52. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +18 -7
  53. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +30 -7
  54. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +24 -8
  55. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +24 -12
  56. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +17 -5
  57. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +14 -3
  58. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +24 -13
  59. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +25 -6
  60. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +26 -4
  61. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +31 -18
  62. data/spec/rails_best_practices/reviews/not_rescue_exception_spec.rb +23 -10
  63. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +34 -7
  64. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +19 -8
  65. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +33 -19
  66. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +25 -13
  67. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +14 -4
  68. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +91 -23
  69. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +20 -5
  70. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +66 -41
  71. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +28 -4
  72. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -7
  73. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +45 -32
  74. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +20 -9
  75. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +23 -14
  76. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +34 -7
  77. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +21 -6
  78. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +124 -79
  79. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +12 -12
  80. data/spec/rails_best_practices/reviews/use_parenthesis_in_method_def_spec.rb +16 -4
  81. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +39 -27
  82. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +22 -8
  83. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +39 -21
  84. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +66 -7
  85. metadata +36 -37
  86. data/.ruby-gemset +0 -1
@@ -33,8 +33,8 @@ module RailsBestPractices
33
33
  <%= @invoice.user.cellphone %>
34
34
  EOF
35
35
  runner.review('app/views/invoices/show.html.erb', content)
36
- runner.should have(3).errors
37
- runner.errors[0].to_s.should == "app/views/invoices/show.html.erb:1 - law of demeter"
36
+ expect(runner.errors.size).to eq(3)
37
+ expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.erb:1 - law of demeter")
38
38
  end
39
39
 
40
40
  it "should law of demeter with haml" do
@@ -44,8 +44,8 @@ module RailsBestPractices
44
44
  = @invoice.user.cellphone
45
45
  EOF
46
46
  runner.review('app/views/invoices/show.html.haml', content)
47
- runner.should have(3).errors
48
- runner.errors[0].to_s.should == "app/views/invoices/show.html.haml:1 - law of demeter"
47
+ expect(runner.errors.size).to eq(3)
48
+ expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.haml:1 - law of demeter")
49
49
  end
50
50
 
51
51
  it "should law of demeter with slim" do
@@ -55,8 +55,8 @@ module RailsBestPractices
55
55
  = @invoice.user.cellphone
56
56
  EOF
57
57
  runner.review('app/views/invoices/show.html.slim', content)
58
- runner.should have(3).errors
59
- runner.errors[0].to_s.should == "app/views/invoices/show.html.slim:1 - law of demeter"
58
+ expect(runner.errors.size).to eq(3)
59
+ expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.slim:1 - law of demeter")
60
60
  end
61
61
 
62
62
  it "should no law of demeter" do
@@ -66,7 +66,7 @@ module RailsBestPractices
66
66
  <%= @invoice.user_cellphone %>
67
67
  EOF
68
68
  runner.review('app/views/invoices/show.html.erb', content)
69
- runner.should have(0).errors
69
+ expect(runner.errors.size).to eq(0)
70
70
  end
71
71
  end
72
72
 
@@ -96,8 +96,8 @@ module RailsBestPractices
96
96
  <%= @invoice.price.number %>
97
97
  EOF
98
98
  runner.review('app/views/invoices/show.html.erb', content)
99
- runner.should have(2).errors
100
- runner.errors[0].to_s.should == "app/views/invoices/show.html.erb:1 - law of demeter"
99
+ expect(runner.errors.size).to eq(2)
100
+ expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.erb:1 - law of demeter")
101
101
  end
102
102
  end
103
103
 
@@ -132,8 +132,8 @@ module RailsBestPractices
132
132
  <%= @comment.commentable.title %>
133
133
  EOF
134
134
  runner.review('app/views/comments/index.html.erb', content)
135
- runner.should have(1).errors
136
- runner.errors[0].to_s.should == "app/views/comments/index.html.erb:1 - law of demeter"
135
+ expect(runner.errors.size).to eq(1)
136
+ expect(runner.errors[0].to_s).to eq("app/views/comments/index.html.erb:1 - law of demeter")
137
137
  end
138
138
  end
139
139
 
@@ -158,7 +158,19 @@ module RailsBestPractices
158
158
  end
159
159
  EOF
160
160
  runner.review('app/controllers/comments_controller.rb', content)
161
- runner.should have(0).errors
161
+ expect(runner.errors.size).to eq(0)
162
+ end
163
+
164
+ it "should not check ignored files" do
165
+ runner = Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
166
+ reviews: LawOfDemeterReview.new(ignored_files: /app\/views\/invoices/))
167
+ content = <<-EOF
168
+ <%= @invoice.user.name %>
169
+ <%= @invoice.user.address %>
170
+ <%= @invoice.user.cellphone %>
171
+ EOF
172
+ runner.review('app/views/invoices/show.html.erb', content)
173
+ expect(runner.errors.size).to eq(0)
162
174
  end
163
175
  end
164
176
  end
@@ -13,8 +13,8 @@ module RailsBestPractices
13
13
  <% end %>
14
14
  EOF
15
15
  runner.review('app/views/posts/index.html.erb', content)
16
- runner.should have(1).errors
17
- runner.errors[0].to_s.should == "app/views/posts/index.html.erb:1 - move code into controller"
16
+ expect(runner.errors.size).to eq(1)
17
+ expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - move code into controller")
18
18
  end
19
19
 
20
20
  it "should move code into controller for assign" do
@@ -26,8 +26,8 @@ module RailsBestPractices
26
26
  <% end %>
27
27
  EOF
28
28
  runner.review('app/views/posts/index.html.erb', content)
29
- runner.should have(1).errors
30
- runner.errors[0].to_s.should == "app/views/posts/index.html.erb:1 - move code into controller"
29
+ expect(runner.errors.size).to eq(1)
30
+ expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - move code into controller")
31
31
  end
32
32
 
33
33
  it "should not move code into controller" do
@@ -38,7 +38,19 @@ module RailsBestPractices
38
38
  <% end %>
39
39
  EOF
40
40
  runner.review('app/views/posts/index.html.erb', content)
41
- runner.should have(0).errors
41
+ expect(runner.errors.size).to eq(0)
42
+ end
43
+
44
+ it "should not check ignored files" do
45
+ runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new(ignored_files: /app\/views\/post/))
46
+ content = <<-EOF
47
+ <% Post.find(:all).each do |post| %>
48
+ <%=h post.title %>
49
+ <%=h post.content %>
50
+ <% end %>
51
+ EOF
52
+ runner.review('app/views/posts/index.html.erb', content)
53
+ expect(runner.errors.size).to eq(0)
42
54
  end
43
55
  end
44
56
  end
@@ -12,8 +12,8 @@ module RailsBestPractices
12
12
  params[:default_state] ) %>
13
13
  EOF
14
14
  runner.review('app/views/posts/show.html.erb', content)
15
- runner.should have(1).errors
16
- runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)"
15
+ expect(runner.errors.size).to eq(1)
16
+ expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)")
17
17
  end
18
18
 
19
19
  it "should not move code into helper with simple arguments" do
@@ -21,7 +21,18 @@ module RailsBestPractices
21
21
  <%= select_tag :state, options_for_select( Post.STATES ) %>
22
22
  EOF
23
23
  runner.review('app/views/posts/show.html.erb', content)
24
- runner.should have(0).errors
24
+ expect(runner.errors.size).to eq(0)
25
+ end
26
+
27
+ it "should not check ignored files" do
28
+ runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new('array_count' => 2, 'ignored_files' => /app\/views\/post/))
29
+ content = <<-EOF
30
+ <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
31
+ [t(:published), "published"]],
32
+ params[:default_state] ) %>
33
+ EOF
34
+ runner.review('app/views/posts/show.html.erb', content)
35
+ expect(runner.errors.size).to eq(0)
25
36
  end
26
37
  end
27
38
  end
@@ -12,8 +12,8 @@ module RailsBestPractices
12
12
  <% end %>
13
13
  EOF
14
14
  runner.review('app/views/posts/show.html.erb', content)
15
- runner.should have(1).errors
16
- runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
15
+ expect(runner.errors.size).to eq(1)
16
+ expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)")
17
17
  end
18
18
 
19
19
  it "should move code into model with haml" do
@@ -22,8 +22,8 @@ module RailsBestPractices
22
22
  = link_to 'Edit this post', edit_post_url(@post)
23
23
  EOF
24
24
  runner.review('app/views/posts/show.html.haml', content)
25
- runner.should have(1).errors
26
- runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
25
+ expect(runner.errors.size).to eq(1)
26
+ expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)")
27
27
  end
28
28
 
29
29
  it "should move code into model with slim" do
@@ -32,8 +32,8 @@ module RailsBestPractices
32
32
  = link_to 'Edit this post', edit_post_url(@post)
33
33
  EOF
34
34
  runner.review('app/views/posts/show.html.slim', content)
35
- runner.should have(1).errors
36
- runner.errors[0].to_s.should == "app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)"
35
+ expect(runner.errors.size).to eq(1)
36
+ expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)")
37
37
  end
38
38
 
39
39
  it "should move code into model with if in one line" do
@@ -41,8 +41,8 @@ module RailsBestPractices
41
41
  <%= link_to 'Edit this post', edit_post_url(@post) if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
42
42
  EOF
43
43
  runner.review('app/views/posts/show.html.erb', content)
44
- runner.should have(1).errors
45
- runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
44
+ expect(runner.errors.size).to eq(1)
45
+ expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)")
46
46
  end
47
47
 
48
48
  it "should move code into model with '? :'" do
@@ -50,8 +50,8 @@ module RailsBestPractices
50
50
  <%= current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) ? link_to('Edit this post', edit_post_url(@post)) : '' %>
51
51
  EOF
52
52
  runner.review('app/views/posts/show.html.erb', content)
53
- runner.should have(1).errors
54
- runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
53
+ expect(runner.errors.size).to eq(1)
54
+ expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)")
55
55
  end
56
56
 
57
57
  it "should move code into model only review for current if conditional statement" do
@@ -64,7 +64,7 @@ module RailsBestPractices
64
64
  <% end %>
65
65
  EOF
66
66
  runner.review('app/views/posts/show.html.erb', content)
67
- runner.should have(0).errors
67
+ expect(runner.errors.size).to eq(0)
68
68
  end
69
69
 
70
70
  it "should not move code into model" do
@@ -74,7 +74,7 @@ module RailsBestPractices
74
74
  <% end %>
75
75
  EOF
76
76
  runner.review('app/views/posts/show.html.erb', content)
77
- runner.should have(0).errors
77
+ expect(runner.errors.size).to eq(0)
78
78
  end
79
79
 
80
80
  it "should not move code into model for multiple calls on same variable node" do
@@ -83,7 +83,18 @@ module RailsBestPractices
83
83
  <% end %>
84
84
  EOF
85
85
  runner.review('app/views/jobs/show.html.erb', content)
86
- runner.should have(0).errors
86
+ expect(runner.errors.size).to eq(0)
87
+ end
88
+
89
+ it "should not check ignored files" do
90
+ runner = Core::Runner.new(reviews: MoveCodeIntoModelReview.new(ignored_files: /app\/views\/post/))
91
+ content =<<-EOF
92
+ <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
93
+ <%= link_to 'Edit this post', edit_post_url(@post) %>
94
+ <% end %>
95
+ EOF
96
+ runner.review('app/views/posts/show.html.erb', content)
97
+ expect(runner.errors.size).to eq(0)
87
98
  end
88
99
  end
89
100
  end
@@ -20,9 +20,9 @@ module RailsBestPractices
20
20
  end
21
21
  EOF
22
22
  runner.review('app/controllers/posts_controller.rb', content)
23
- runner.should have(2).errors
24
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move finder to named_scope"
25
- runner.errors[1].to_s.should == "app/controllers/posts_controller.rb:7 - move finder to named_scope"
23
+ expect(runner.errors.size).to eq(2)
24
+ expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:3 - move finder to named_scope")
25
+ expect(runner.errors[1].to_s).to eq("app/controllers/posts_controller.rb:7 - move finder to named_scope")
26
26
  end
27
27
 
28
28
  it "should not move simple finder" do
@@ -39,7 +39,7 @@ module RailsBestPractices
39
39
  end
40
40
  EOF
41
41
  runner.review('app/controllers/posts_controller.rb', content)
42
- runner.should have(0).errors
42
+ expect(runner.errors.size).to eq(0)
43
43
  end
44
44
 
45
45
  it "should not move namd_scope" do
@@ -52,7 +52,7 @@ module RailsBestPractices
52
52
  end
53
53
  EOF
54
54
  runner.review('app/controllers/posts_controller.rb', content)
55
- runner.should have(0).errors
55
+ expect(runner.errors.size).to eq(0)
56
56
  end
57
57
 
58
58
  it "should not review model file" do
@@ -70,7 +70,26 @@ module RailsBestPractices
70
70
  end
71
71
  EOF
72
72
  runner.review('app/model/post.rb', content)
73
- runner.should have(0).errors
73
+ expect(runner.errors.size).to eq(0)
74
+ end
75
+
76
+ it "should not check ignored files" do
77
+ runner = Core::Runner.new(reviews: MoveFinderToNamedScopeReview.new(ignored_files: /app\/controllers\/posts/))
78
+ content = <<-EOF
79
+ class PostsController < ActionController::Base
80
+ def index
81
+ @public_posts = Post.find(:all, conditions: { state: 'public' },
82
+ limit: 10,
83
+ order: 'created_at desc')
84
+
85
+ @draft_posts = Post.find(:all, conditions: { state: 'draft' },
86
+ limit: 10,
87
+ order: 'created_at desc')
88
+ end
89
+ end
90
+ EOF
91
+ runner.review('app/controllers/posts_controller.rb', content)
92
+ expect(runner.errors.size).to eq(0)
74
93
  end
75
94
  end
76
95
  end
@@ -23,8 +23,8 @@ module RailsBestPractices
23
23
  end
24
24
  EOF
25
25
  runner.review('app/controllers/posts_controller.rb', content)
26
- runner.should have(1).errors
27
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:2 - move model logic into model (@post use_count > 4)"
26
+ expect(runner.errors.size).to eq(1)
27
+ expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - move model logic into model (@post use_count > 4)")
28
28
  end
29
29
 
30
30
  it "should not move model logic into model with simple model calling" do
@@ -40,7 +40,7 @@ module RailsBestPractices
40
40
  end
41
41
  EOF
42
42
  runner.review('app/controllers/posts_controller.rb', content)
43
- runner.should have(0).errors
43
+ expect(runner.errors.size).to eq(0)
44
44
  end
45
45
 
46
46
  it "should not move model logic into model with self calling" do
@@ -56,7 +56,29 @@ module RailsBestPractices
56
56
  end
57
57
  EOF
58
58
  runner.review('app/controllers/posts_controller.rb', content)
59
- runner.should have(0).errors
59
+ expect(runner.errors.size).to eq(0)
60
+ end
61
+
62
+ it "should not check ignored files" do
63
+ runner = Core::Runner.new(reviews: MoveModelLogicIntoModelReview.new(ignored_files: /app\/controllers\/posts/))
64
+ content = <<-EOF
65
+ class PostsController < ApplicationController
66
+ def publish
67
+ @post = Post.find(params[:id])
68
+ @post.update_attributes(:is_published, true)
69
+ @post.approved_by = current_user
70
+ if @post.created_at > Time.now - 7.days
71
+ @post.popular = 100
72
+ else
73
+ @post.popular = 0
74
+ end
75
+
76
+ redirect_to post_url(@post)
77
+ end
78
+ end
79
+ EOF
80
+ runner.review('app/controllers/posts_controller.rb', content)
81
+ expect(runner.errors.size).to eq(0)
60
82
  end
61
83
  end
62
84
  end
@@ -15,8 +15,8 @@ module RailsBestPractices
15
15
  end
16
16
  EOF
17
17
  runner.review('config/routes.rb', content)
18
- runner.should have(1).errors
19
- runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
18
+ expect(runner.errors.size).to eq(1)
19
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - needless deep nesting (nested_count > 2)")
20
20
  end
21
21
 
22
22
  it "should not needless deep nesting for shallow" do
@@ -28,7 +28,7 @@ module RailsBestPractices
28
28
  end
29
29
  EOF
30
30
  runner.review('config/routes.rb', content)
31
- runner.should have(0).errors
31
+ expect(runner.errors.size).to eq(0)
32
32
  end
33
33
 
34
34
  it "should needless deep nesting with resource" do
@@ -40,8 +40,8 @@ module RailsBestPractices
40
40
  end
41
41
  EOF
42
42
  runner.review('config/routes.rb', content)
43
- runner.should have(1).errors
44
- runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
43
+ expect(runner.errors.size).to eq(1)
44
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - needless deep nesting (nested_count > 2)")
45
45
  end
46
46
 
47
47
  it "should needless deep nesting with block node" do
@@ -54,8 +54,8 @@ module RailsBestPractices
54
54
  end
55
55
  EOF
56
56
  runner.review('config/routes.rb', content)
57
- runner.should have(1).errors
58
- runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
57
+ expect(runner.errors.size).to eq(1)
58
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - needless deep nesting (nested_count > 2)")
59
59
  end
60
60
 
61
61
  it "should no needless deep nesting" do
@@ -69,7 +69,7 @@ module RailsBestPractices
69
69
  end
70
70
  EOF
71
71
  runner.review('config/routes.rb', content)
72
- runner.should have(0).errors
72
+ expect(runner.errors.size).to eq(0)
73
73
  end
74
74
 
75
75
  it "should no needless deep nesting with block node" do
@@ -80,7 +80,7 @@ module RailsBestPractices
80
80
  end
81
81
  EOF
82
82
  runner.review('config/routes.rb', content)
83
- runner.should have(0).errors
83
+ expect(runner.errors.size).to eq(0)
84
84
  end
85
85
  end
86
86
 
@@ -94,8 +94,8 @@ module RailsBestPractices
94
94
  end
95
95
  EOF
96
96
  runner.review('config/routes.rb', content)
97
- runner.should have(1).errors
98
- runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
97
+ expect(runner.errors.size).to eq(1)
98
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - needless deep nesting (nested_count > 2)")
99
99
  end
100
100
 
101
101
  it "should not needless deep nesting for shallow" do
@@ -107,7 +107,7 @@ module RailsBestPractices
107
107
  end
108
108
  EOF
109
109
  runner.review('config/routes.rb', content)
110
- runner.should have(0).errors
110
+ expect(runner.errors.size).to eq(0)
111
111
  end
112
112
 
113
113
  it "should not needless deep nesting for shallow 4 levels" do
@@ -121,7 +121,7 @@ module RailsBestPractices
121
121
  end
122
122
  EOF
123
123
  runner.review('config/routes.rb', content)
124
- runner.should have(0).errors
124
+ expect(runner.errors.size).to eq(0)
125
125
  end
126
126
 
127
127
  it "should needless deep nesting with resource" do
@@ -133,8 +133,8 @@ module RailsBestPractices
133
133
  end
134
134
  EOF
135
135
  runner.review('config/routes.rb', content)
136
- runner.should have(1).errors
137
- runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
136
+ expect(runner.errors.size).to eq(1)
137
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - needless deep nesting (nested_count > 2)")
138
138
  end
139
139
 
140
140
  it "should needless deep nesting with block node" do
@@ -147,8 +147,8 @@ module RailsBestPractices
147
147
  end
148
148
  EOF
149
149
  runner.review('config/routes.rb', content)
150
- runner.should have(1).errors
151
- runner.errors[0].to_s.should == "config/routes.rb:3 - needless deep nesting (nested_count > 2)"
150
+ expect(runner.errors.size).to eq(1)
151
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:3 - needless deep nesting (nested_count > 2)")
152
152
  end
153
153
 
154
154
  it "should no needless deep nesting" do
@@ -163,9 +163,22 @@ module RailsBestPractices
163
163
  end
164
164
  EOF
165
165
  runner.review('config/routes.rb', content)
166
- runner.should have(0).errors
166
+ expect(runner.errors.size).to eq(0)
167
167
  end
168
168
  end
169
+
170
+ it "should not check ignored files" do
171
+ runner = Core::Runner.new(reviews: NeedlessDeepNestingReview.new(ignored_files: /config\/routes/))
172
+ content = <<-EOF
173
+ map.resources :posts do |post|
174
+ post.resources :comments do |comment|
175
+ comment.resources :favorites
176
+ end
177
+ end
178
+ EOF
179
+ runner.review('config/routes.rb', content)
180
+ expect(runner.errors.size).to eq(0)
181
+ end
169
182
  end
170
183
  end
171
184
  end
@@ -15,8 +15,8 @@ module RailsBestPractices
15
15
  end
16
16
  EOF
17
17
  runner.review('app/helpers/posts_helper.rb', content)
18
- runner.should have(1).errors
19
- runner.errors[0].to_s.should == "app/helpers/posts_helper.rb:3 - not rescue Exception"
18
+ expect(runner.errors.size).to eq(1)
19
+ expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:3 - not rescue Exception")
20
20
  end
21
21
 
22
22
  it "should not rescue exception in method rescue without named var" do
@@ -28,8 +28,8 @@ module RailsBestPractices
28
28
  end
29
29
  EOF
30
30
  runner.review('app/helpers/posts_helper.rb', content)
31
- runner.should have(1).errors
32
- runner.errors[0].to_s.should == "app/helpers/posts_helper.rb:3 - not rescue Exception"
31
+ expect(runner.errors.size).to eq(1)
32
+ expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:3 - not rescue Exception")
33
33
  end
34
34
 
35
35
  it "should not rescue exception in block rescue with named var" do
@@ -43,8 +43,8 @@ module RailsBestPractices
43
43
  end
44
44
  EOF
45
45
  runner.review('app/helpers/posts_helper.rb', content)
46
- runner.should have(1).errors
47
- runner.errors[0].to_s.should == "app/helpers/posts_helper.rb:4 - not rescue Exception"
46
+ expect(runner.errors.size).to eq(1)
47
+ expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:4 - not rescue Exception")
48
48
  end
49
49
 
50
50
  it "should not rescue exception in block rescue without named var" do
@@ -58,8 +58,8 @@ module RailsBestPractices
58
58
  end
59
59
  EOF
60
60
  runner.review('app/helpers/posts_helper.rb', content)
61
- runner.should have(1).errors
62
- runner.errors[0].to_s.should == "app/helpers/posts_helper.rb:4 - not rescue Exception"
61
+ expect(runner.errors.size).to eq(1)
62
+ expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:4 - not rescue Exception")
63
63
  end
64
64
 
65
65
  it "should allow rescue implicit StandardError in block rescue without named var" do
@@ -73,7 +73,7 @@ module RailsBestPractices
73
73
  end
74
74
  EOF
75
75
  runner.review('app/helpers/posts_helper.rb', content)
76
- runner.should have(0).errors
76
+ expect(runner.errors.size).to eq(0)
77
77
  end
78
78
 
79
79
  it "should allow rescue explicit StandardError in block rescue without named var" do
@@ -87,7 +87,20 @@ module RailsBestPractices
87
87
  end
88
88
  EOF
89
89
  runner.review('app/helpers/posts_helper.rb', content)
90
- runner.should have(0).errors
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: NotRescueExceptionReview.new(ignored_files: /posts_helper/))
95
+ content =<<-EOF
96
+ def my_method
97
+ do_something
98
+ rescue Exception => e
99
+ logger.error e
100
+ end
101
+ EOF
102
+ runner.review('app/helpers/posts_helper.rb', content)
103
+ expect(runner.errors.size).to eq(0)
91
104
  end
92
105
  end
93
106
  end
@@ -16,9 +16,9 @@ module RailsBestPractices
16
16
  end
17
17
  EOF
18
18
  runner.review('config/routes.rb', content)
19
- runner.should have(2).errors
20
- runner.errors[0].to_s.should == "config/routes.rb:4 - not use default route"
21
- runner.errors[1].to_s.should == "config/routes.rb:5 - not use default route"
19
+ expect(runner.errors.size).to eq(2)
20
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:4 - not use default route")
21
+ expect(runner.errors[1].to_s).to eq("config/routes.rb:5 - not use default route")
22
22
  end
23
23
 
24
24
  it "should no not use default route" do
@@ -28,7 +28,21 @@ module RailsBestPractices
28
28
  end
29
29
  EOF
30
30
  runner.review('config/routes.rb', content)
31
- runner.should have(0).errors
31
+ expect(runner.errors.size).to eq(0)
32
+ end
33
+
34
+ it "should not check ignored files" do
35
+ runner = Core::Runner.new(reviews: NotUseDefaultRouteReview.new(ignored_files: /config\/routes\.rb/))
36
+ content = <<-EOF
37
+ ActionController::Routing::Routes.draw do |map|
38
+ map.resources :posts, member: { push: :post }
39
+
40
+ map.connect ':controller/:action/:id'
41
+ map.connect ':controller/:action/:id.:format'
42
+ end
43
+ EOF
44
+ runner.review('config/routes.rb', content)
45
+ expect(runner.errors.size).to eq(0)
32
46
  end
33
47
  end
34
48
 
@@ -42,8 +56,8 @@ module RailsBestPractices
42
56
  end
43
57
  EOF
44
58
  runner.review('config/routes.rb', content)
45
- runner.should have(1).errors
46
- runner.errors[0].to_s.should == "config/routes.rb:4 - not use default route"
59
+ expect(runner.errors.size).to eq(1)
60
+ expect(runner.errors[0].to_s).to eq("config/routes.rb:4 - not use default route")
47
61
  end
48
62
 
49
63
  it "should no not use default route" do
@@ -53,7 +67,20 @@ module RailsBestPractices
53
67
  end
54
68
  EOF
55
69
  runner.review('config/routes.rb', content)
56
- runner.should have(0).errors
70
+ expect(runner.errors.size).to eq(0)
71
+ end
72
+
73
+ it "should not check ignored files" do
74
+ runner = Core::Runner.new(reviews: NotUseDefaultRouteReview.new(ignored_files: /config\/routes\.rb/))
75
+ content = <<-EOF
76
+ RailsBestpracticesCom::Application.routes.draw do |map|
77
+ resources :posts
78
+
79
+ match ':controller(/:action(/:id(.:format)))'
80
+ end
81
+ EOF
82
+ runner.review('config/routes.rb', content)
83
+ expect(runner.errors.size).to eq(0)
57
84
  end
58
85
  end
59
86
  end