rails_best_practices 1.20.0 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +30 -26
  4. data/Guardfile +2 -0
  5. data/Rakefile +2 -0
  6. data/lib/rails_best_practices.rb +1 -2
  7. data/lib/rails_best_practices/analyzer.rb +56 -46
  8. data/lib/rails_best_practices/core/check.rb +39 -32
  9. data/lib/rails_best_practices/core/checks_loader.rb +8 -6
  10. data/lib/rails_best_practices/core/configs.rb +1 -2
  11. data/lib/rails_best_practices/core/controllers.rb +1 -2
  12. data/lib/rails_best_practices/core/error.rb +1 -1
  13. data/lib/rails_best_practices/core/helpers.rb +1 -2
  14. data/lib/rails_best_practices/core/mailers.rb +1 -2
  15. data/lib/rails_best_practices/core/methods.rb +21 -16
  16. data/lib/rails_best_practices/core/model_associations.rb +9 -4
  17. data/lib/rails_best_practices/core/models.rb +1 -2
  18. data/lib/rails_best_practices/core/modules.rb +1 -1
  19. data/lib/rails_best_practices/core/routes.rb +2 -2
  20. data/lib/rails_best_practices/core/runner.rb +29 -33
  21. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  22. data/lib/rails_best_practices/option_parser.rb +17 -6
  23. data/lib/rails_best_practices/prepares.rb +1 -1
  24. data/lib/rails_best_practices/prepares/controller_prepare.rb +15 -3
  25. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
  26. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  27. data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -2
  28. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -0
  29. data/lib/rails_best_practices/prepares/model_prepare.rb +52 -12
  30. data/lib/rails_best_practices/prepares/route_prepare.rb +16 -10
  31. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +15 -13
  32. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +34 -29
  33. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +14 -5
  34. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +19 -8
  35. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +5 -5
  36. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +4 -4
  37. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +7 -8
  38. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +6 -6
  39. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +6 -7
  41. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +7 -8
  42. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +12 -10
  43. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +5 -5
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +5 -2
  46. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +6 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -4
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +29 -9
  49. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +3 -3
  50. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +17 -15
  51. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -2
  52. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -3
  53. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -1
  54. data/lib/rails_best_practices/reviews/use_model_association_review.rb +5 -5
  55. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +9 -8
  56. data/lib/rails_best_practices/reviews/use_observer_review.rb +9 -9
  57. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +26 -26
  58. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +8 -7
  59. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +17 -15
  60. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  61. data/lib/rails_best_practices/version.rb +1 -1
  62. data/rails_best_practices.gemspec +35 -36
  63. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  64. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  65. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  66. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  67. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  68. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  69. data/spec/rails_best_practices/core/error_spec.rb +21 -21
  70. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  71. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  72. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  73. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  74. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  75. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  76. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  77. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  78. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  79. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  80. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  82. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  83. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +11 -10
  84. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  85. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  86. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  87. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  88. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +2 -2
  89. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  90. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  91. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  92. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  93. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +138 -77
  94. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  95. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  96. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  97. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  98. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  99. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  100. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  101. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  103. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  104. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +21 -14
  105. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  106. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  107. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +26 -16
  108. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  109. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  110. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  111. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  112. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  113. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  114. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  115. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -19
  116. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +44 -31
  118. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +17 -12
  119. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +46 -44
  120. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  121. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -10
  122. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  123. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  124. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  125. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  126. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  127. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +21 -17
  128. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  129. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +9 -7
  130. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  131. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  132. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  133. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +10 -8
  134. metadata +7 -7
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe MoveFinderToNamedScopeReview do
8
- let(:runner) { Core::Runner.new(reviews: MoveFinderToNamedScopeReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should move finder to named_scope' do
10
+ it 'moves finder to named_scope' do
11
11
  content = <<-EOF
12
12
  class PostsController < ActionController::Base
13
13
  def index
@@ -27,7 +27,7 @@ module RailsBestPractices
27
27
  expect(runner.errors[1].to_s).to eq('app/controllers/posts_controller.rb:7 - move finder to named_scope')
28
28
  end
29
29
 
30
- it 'should not move simple finder' do
30
+ it 'does not move simple finder' do
31
31
  content = <<-EOF
32
32
  class PostsController < ActionController::Base
33
33
  def index
@@ -44,7 +44,7 @@ module RailsBestPractices
44
44
  expect(runner.errors.size).to eq(0)
45
45
  end
46
46
 
47
- it 'should not move namd_scope' do
47
+ it 'does not move namd_scope' do
48
48
  content = <<-EOF
49
49
  class PostsController < ActionController::Base
50
50
  def index
@@ -57,7 +57,7 @@ module RailsBestPractices
57
57
  expect(runner.errors.size).to eq(0)
58
58
  end
59
59
 
60
- it 'should not review model file' do
60
+ it 'does not review model file' do
61
61
  content = <<-EOF
62
62
  class Post < ActiveRecord::Base
63
63
  def published
@@ -75,8 +75,8 @@ module RailsBestPractices
75
75
  expect(runner.errors.size).to eq(0)
76
76
  end
77
77
 
78
- it 'should not check ignored files' do
79
- runner = Core::Runner.new(reviews: MoveFinderToNamedScopeReview.new(ignored_files: /app\/controllers\/posts/))
78
+ it 'does not check ignored files' do
79
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/controllers/posts}))
80
80
  content = <<-EOF
81
81
  class PostsController < ActionController::Base
82
82
  def index
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe MoveModelLogicIntoModelReview do
8
- let(:runner) { Core::Runner.new(reviews: MoveModelLogicIntoModelReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should move model logic into model' do
10
+ it 'moves model logic into model' do
11
11
  content = <<-EOF
12
12
  class PostsController < ApplicationController
13
13
  def publish
@@ -26,10 +26,12 @@ module RailsBestPractices
26
26
  EOF
27
27
  runner.review('app/controllers/posts_controller.rb', content)
28
28
  expect(runner.errors.size).to eq(1)
29
- expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - move model logic into model (@post use_count > 4)')
29
+ expect(runner.errors[0].to_s).to eq(
30
+ 'app/controllers/posts_controller.rb:2 - move model logic into model (@post use_count > 4)'
31
+ )
30
32
  end
31
33
 
32
- it 'should not move model logic into model with simple model calling' do
34
+ it 'does not move model logic into model with simple model calling' do
33
35
  content = <<-EOF
34
36
  class PostsController < ApplicationController
35
37
  def publish
@@ -45,7 +47,7 @@ module RailsBestPractices
45
47
  expect(runner.errors.size).to eq(0)
46
48
  end
47
49
 
48
- it 'should not move model logic into model with self calling' do
50
+ it 'does not move model logic into model with self calling' do
49
51
  content = <<-EOF
50
52
  class PostsController < ApplicationController
51
53
  def publish
@@ -61,8 +63,8 @@ module RailsBestPractices
61
63
  expect(runner.errors.size).to eq(0)
62
64
  end
63
65
 
64
- it 'should not check ignored files' do
65
- runner = Core::Runner.new(reviews: MoveModelLogicIntoModelReview.new(ignored_files: /app\/controllers\/posts/))
66
+ it 'does not check ignored files' do
67
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/controllers/posts}))
66
68
  content = <<-EOF
67
69
  class PostsController < ApplicationController
68
70
  def publish
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe NeedlessDeepNestingReview do
8
- let(:runner) { Core::Runner.new(reviews: NeedlessDeepNestingReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should needless deep nesting' do
10
+ it 'needlesses deep nesting' do
11
11
  content = <<-EOF
12
12
  resources :posts do
13
13
  resources :comments do
@@ -20,7 +20,7 @@ module RailsBestPractices
20
20
  expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - needless deep nesting (nested_count > 2)')
21
21
  end
22
22
 
23
- it 'should not needless deep nesting for shallow' do
23
+ it 'does not needless deep nesting for shallow' do
24
24
  content = <<-EOF
25
25
  resources :posts, shallow: true do
26
26
  resources :comments do
@@ -32,7 +32,7 @@ module RailsBestPractices
32
32
  expect(runner.errors.size).to eq(0)
33
33
  end
34
34
 
35
- it 'should not needless deep nesting for shallow 4 levels' do
35
+ it 'does not needless deep nesting for shallow 4 levels' do
36
36
  content = <<-EOF
37
37
  resources :applications, shallow: true, only: [:index, :show, :create] do
38
38
  resources :events, only: [:index, :show, :create, :subscribe, :push] do
@@ -46,7 +46,7 @@ module RailsBestPractices
46
46
  expect(runner.errors.size).to eq(0)
47
47
  end
48
48
 
49
- it 'should needless deep nesting with resource' do
49
+ it 'needlesses deep nesting with resource' do
50
50
  content = <<-EOF
51
51
  resources :posts do
52
52
  resources :comments do
@@ -59,7 +59,7 @@ module RailsBestPractices
59
59
  expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - needless deep nesting (nested_count > 2)')
60
60
  end
61
61
 
62
- it 'should needless deep nesting with block node' do
62
+ it 'needlesses deep nesting with block node' do
63
63
  content = <<-EOF
64
64
  resources :posts do
65
65
  resources :comments do
@@ -73,7 +73,7 @@ module RailsBestPractices
73
73
  expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - needless deep nesting (nested_count > 2)')
74
74
  end
75
75
 
76
- it 'should no needless deep nesting' do
76
+ it 'noes needless deep nesting' do
77
77
  content = <<-EOF
78
78
  resources :posts do
79
79
  resources :comments
@@ -88,8 +88,8 @@ module RailsBestPractices
88
88
  expect(runner.errors.size).to eq(0)
89
89
  end
90
90
 
91
- it 'should not check ignored files' do
92
- runner = Core::Runner.new(reviews: NeedlessDeepNestingReview.new(ignored_files: /config\/routes/))
91
+ it 'does not check ignored files' do
92
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{config/routes}))
93
93
  content = <<-EOF
94
94
  map.resources :posts do |post|
95
95
  post.resources :comments do |comment|
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe NotRescueExceptionReview do
8
- let(:runner) { Core::Runner.new(reviews: NotRescueExceptionReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
10
  describe 'not_rescue_exception' do
11
- it 'should not rescue exception in method rescue with named var' do
11
+ it 'does not rescue exception in method rescue with named var' do
12
12
  content = <<-EOF
13
13
  def my_method
14
14
  do_something
@@ -21,7 +21,7 @@ module RailsBestPractices
21
21
  expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:3 - Don't rescue Exception")
22
22
  end
23
23
 
24
- it 'should not rescue exception in method rescue without named var' do
24
+ it 'does not rescue exception in method rescue without named var' do
25
25
  content = <<-EOF
26
26
  def my_method
27
27
  do_something
@@ -34,7 +34,7 @@ module RailsBestPractices
34
34
  expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:3 - Don't rescue Exception")
35
35
  end
36
36
 
37
- it 'should not rescue exception in block rescue with named var' do
37
+ it 'does not rescue exception in block rescue with named var' do
38
38
  content = <<-EOF
39
39
  def my_method
40
40
  begin
@@ -49,7 +49,7 @@ module RailsBestPractices
49
49
  expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:4 - Don't rescue Exception")
50
50
  end
51
51
 
52
- it 'should not rescue exception in block rescue without named var' do
52
+ it 'does not rescue exception in block rescue without named var' do
53
53
  content = <<-EOF
54
54
  def my_method
55
55
  begin
@@ -64,7 +64,7 @@ module RailsBestPractices
64
64
  expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:4 - Don't rescue Exception")
65
65
  end
66
66
 
67
- it 'should allow rescue implicit StandardError in block rescue without named var' do
67
+ it 'allows rescue implicit StandardError in block rescue without named var' do
68
68
  content = <<-EOF
69
69
  def my_method
70
70
  begin
@@ -78,7 +78,7 @@ module RailsBestPractices
78
78
  expect(runner.errors.size).to eq(0)
79
79
  end
80
80
 
81
- it 'should allow rescue explicit StandardError in block rescue without named var' do
81
+ it 'allows rescue explicit StandardError in block rescue without named var' do
82
82
  content = <<-EOF
83
83
  def my_method
84
84
  begin
@@ -92,8 +92,8 @@ module RailsBestPractices
92
92
  expect(runner.errors.size).to eq(0)
93
93
  end
94
94
 
95
- it 'should not check ignored files' do
96
- runner = Core::Runner.new(reviews: NotRescueExceptionReview.new(ignored_files: /posts_helper/))
95
+ it 'does not check ignored files' do
96
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_helper/))
97
97
  content = <<-EOF
98
98
  def my_method
99
99
  do_something
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe NotUseDefaultRouteReview do
8
- let(:runner) { Core::Runner.new(reviews: NotUseDefaultRouteReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should not use default route' do
10
+ it 'does not use default route' do
11
11
  content = <<-EOF
12
12
  RailsBestpracticesCom::Application.routes.draw do |map|
13
13
  resources :posts
@@ -20,7 +20,7 @@ module RailsBestPractices
20
20
  expect(runner.errors[0].to_s).to eq('config/routes.rb:4 - not use default route')
21
21
  end
22
22
 
23
- it 'should no not use default route' do
23
+ it 'noes not use default route' do
24
24
  content = <<-EOF
25
25
  RailsBestpracticesCom::Application.routes.draw do |map|
26
26
  resources :posts
@@ -30,8 +30,8 @@ module RailsBestPractices
30
30
  expect(runner.errors.size).to eq(0)
31
31
  end
32
32
 
33
- it 'should not check ignored files' do
34
- runner = Core::Runner.new(reviews: NotUseDefaultRouteReview.new(ignored_files: /config\/routes\.rb/))
33
+ it 'does not check ignored files' do
34
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{config/routes\.rb}))
35
35
  content = <<-EOF
36
36
  RailsBestpracticesCom::Application.routes.draw do |map|
37
37
  resources :posts
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe NotUseTimeAgoInWordsReview do
8
- let(:runner) { Core::Runner.new(reviews: NotUseTimeAgoInWordsReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
10
  describe 'time_ago_in_words' do
11
- it 'should not use in views' do
11
+ it 'does not use in views' do
12
12
  content = <<-EOF
13
13
  <%= time_ago_in_words(post.created_at) %>
14
14
  EOF
@@ -17,7 +17,7 @@ module RailsBestPractices
17
17
  expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - not use time_ago_in_words')
18
18
  end
19
19
 
20
- it 'should not use in helpers' do
20
+ it 'does not use in helpers' do
21
21
  content = <<-EOF
22
22
  def timeago
23
23
  content_tag(:p, time_ago_in_words(post.created_at))
@@ -30,7 +30,7 @@ module RailsBestPractices
30
30
  end
31
31
 
32
32
  describe 'distance_of_time_in_words_to_now' do
33
- it 'should not use in views' do
33
+ it 'does not use in views' do
34
34
  content = <<-EOF
35
35
  <%= distance_of_time_in_words_to_now(post.created_at) %>
36
36
  EOF
@@ -39,7 +39,7 @@ module RailsBestPractices
39
39
  expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - not use time_ago_in_words')
40
40
  end
41
41
 
42
- it 'should not use in helpers' do
42
+ it 'does not use in helpers' do
43
43
  content = <<-EOF
44
44
  def timeago
45
45
  content_tag(:p, distance_of_time_in_words_to_now(post.created_at))
@@ -51,8 +51,8 @@ module RailsBestPractices
51
51
  end
52
52
  end
53
53
 
54
- it 'should not check ignored files' do
55
- runner = Core::Runner.new(reviews: NotUseTimeAgoInWordsReview.new(ignored_files: /posts_helper/))
54
+ it 'does not check ignored files' do
55
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_helper/))
56
56
  content = <<-EOF
57
57
  def timeago
58
58
  content_tag(:p, time_ago_in_words(post.created_at))
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe OveruseRouteCustomizationsReview do
8
- let(:runner) { Core::Runner.new(reviews: OveruseRouteCustomizationsReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should overuse route customizations' do
10
+ it 'overuses route customizations' do
11
11
  content = <<-EOF
12
12
  RailsBestpracticesCom::Application.routes.draw do
13
13
  resources :posts do
@@ -28,7 +28,7 @@ module RailsBestPractices
28
28
  expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - overuse route customizations (customize_count > 3)')
29
29
  end
30
30
 
31
- it 'should overuse route customizations another way' do
31
+ it 'overuses route customizations another way' do
32
32
  content = <<-EOF
33
33
  RailsBestpracticesCom::Application.routes.draw do
34
34
  resources :posts do
@@ -44,7 +44,7 @@ module RailsBestPractices
44
44
  expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - overuse route customizations (customize_count > 3)')
45
45
  end
46
46
 
47
- it 'should not overuse route customizations without customization' do
47
+ it 'does not overuse route customizations without customization' do
48
48
  content = <<-EOF
49
49
  RailsBestpracticesCom::Application.routes.draw do
50
50
  resources :posts
@@ -54,7 +54,7 @@ module RailsBestPractices
54
54
  expect(runner.errors.size).to eq(0)
55
55
  end
56
56
 
57
- it 'should not overuse route customizations when customize route is only one' do
57
+ it 'does not overuse route customizations when customize route is only one' do
58
58
  content = <<-EOF
59
59
  RailsBestpracticesCom::Application.routes.draw do
60
60
  resources :posts do
@@ -68,8 +68,8 @@ module RailsBestPractices
68
68
  expect(runner.errors.size).to eq(0)
69
69
  end
70
70
 
71
- it 'should not check ignored files' do
72
- runner = Core::Runner.new(reviews: OveruseRouteCustomizationsReview.new(ignored_files: /config\/routes\.rb/))
71
+ it 'does not check ignored files' do
72
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{config/routes\.rb}))
73
73
  content = <<-EOF
74
74
  ActionController::Routing::Routes.draw do |map|
75
75
  map.resources :posts, member: { comments: :get,
@@ -5,12 +5,14 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe ProtectMassAssignmentReview do
8
- let(:runner) {
9
- Core::Runner.new(prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
10
- reviews: ProtectMassAssignmentReview.new)
11
- }
8
+ let(:runner) do
9
+ Core::Runner.new(
10
+ prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
11
+ reviews: described_class.new
12
+ )
13
+ end
12
14
 
13
- it 'should protect mass assignment' do
15
+ it 'protects mass assignment' do
14
16
  content = <<-EOF
15
17
  class User < ActiveRecord::Base
16
18
  end
@@ -20,7 +22,7 @@ module RailsBestPractices
20
22
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:1 - protect mass assignment')
21
23
  end
22
24
 
23
- it 'should not protect mass assignment if attr_accessible is used with arguments and user set config.active_record.whitelist_attributes' do
25
+ it 'does not protect mass assignment if attr_accessible is used with arguments and user set config.active_record.whitelist_attributes' do
24
26
  content = <<-EOF
25
27
  module RailsBestPracticesCom
26
28
  class Application < Rails::Application
@@ -38,7 +40,7 @@ module RailsBestPractices
38
40
  expect(runner.errors.size).to eq(0)
39
41
  end
40
42
 
41
- it 'should not protect mass assignment if attr_accessible is used without arguments and user set config.active_record.whitelist_attributes' do
43
+ it 'does not protect mass assignment if attr_accessible is used without arguments and user set config.active_record.whitelist_attributes' do
42
44
  content = <<-EOF
43
45
  module RailsBestPracticesCom
44
46
  class Application < Rails::Application
@@ -56,7 +58,7 @@ module RailsBestPractices
56
58
  expect(runner.errors.size).to eq(0)
57
59
  end
58
60
 
59
- it 'should not protect mass assignment with attr_protected if user set config.active_record.whitelist_attributes' do
61
+ it 'does not protect mass assignment with attr_protected if user set config.active_record.whitelist_attributes' do
60
62
  content = <<-EOF
61
63
  module RailsBestPracticesCom
62
64
  class Application < Rails::Application
@@ -74,7 +76,7 @@ module RailsBestPractices
74
76
  expect(runner.errors.size).to eq(0)
75
77
  end
76
78
 
77
- it 'should not protect mass assignment if using devise' do
79
+ it 'does not protect mass assignment if using devise' do
78
80
  content = <<-EOF
79
81
  class User < ActiveRecord::Base
80
82
  devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
@@ -84,7 +86,7 @@ module RailsBestPractices
84
86
  expect(runner.errors.size).to eq(0)
85
87
  end
86
88
 
87
- it 'should not protect mass assignment if using authlogic with configuration' do
89
+ it 'does not protect mass assignment if using authlogic with configuration' do
88
90
  content = <<-EOF
89
91
  class User < ActiveRecord::Base
90
92
  acts_as_authentic do |c|
@@ -96,7 +98,7 @@ module RailsBestPractices
96
98
  expect(runner.errors.size).to eq(0)
97
99
  end
98
100
 
99
- it 'should not protect mass assignment if using authlogic without configuration' do
101
+ it 'does not protect mass assignment if using authlogic without configuration' do
100
102
  content = <<-EOF
101
103
  class User < ActiveRecord::Base
102
104
  acts_as_authentic
@@ -106,7 +108,7 @@ module RailsBestPractices
106
108
  expect(runner.errors.size).to eq(0)
107
109
  end
108
110
 
109
- it 'should not protect mass assignment if checking non ActiveRecord::Base inherited model' do
111
+ it 'does not protect mass assignment if checking non ActiveRecord::Base inherited model' do
110
112
  content = <<-EOF
111
113
  class User < Person
112
114
  end
@@ -116,7 +118,7 @@ module RailsBestPractices
116
118
  end
117
119
 
118
120
  context 'strong_parameters' do
119
- it 'should not protect mass assignment for strong_parameters' do
121
+ it 'does not protect mass assignment for strong_parameters' do
120
122
  content = <<-EOF
121
123
  class User < ActiveRecord::Base
122
124
  include ActiveModel::ForbiddenAttributesProtection
@@ -126,7 +128,7 @@ module RailsBestPractices
126
128
  expect(runner.errors.size).to eq(0)
127
129
  end
128
130
 
129
- it 'should not protect mass assignment for strong_parameters' do
131
+ it 'does not protect mass assignment for strong_parameters' do
130
132
  content = <<-EOF
131
133
  class AR
132
134
  ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
@@ -143,7 +145,7 @@ module RailsBestPractices
143
145
  end
144
146
 
145
147
  context 'activerecord 4' do
146
- it 'should not protect mass assignment for activerecord 4' do
148
+ it 'does not protect mass assignment for activerecord 4' do
147
149
  content = <<-EOF
148
150
  GEM
149
151
  remote: https://rubygems.org
@@ -159,7 +161,7 @@ module RailsBestPractices
159
161
  expect(runner.errors.size).to eq(0)
160
162
  end
161
163
 
162
- it 'should protect mass assignment for activerecord 3' do
164
+ it 'protects mass assignment for activerecord 3' do
163
165
  content = <<-EOF
164
166
  GEM
165
167
  remote: https://rubygems.org
@@ -176,9 +178,12 @@ module RailsBestPractices
176
178
  end
177
179
  end
178
180
 
179
- it 'should not check ignored files' do
180
- runner = Core::Runner.new(prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
181
- reviews: ProtectMassAssignmentReview.new(ignored_files: /app\/models\/user\.rb/))
181
+ it 'does not check ignored files' do
182
+ runner =
183
+ Core::Runner.new(
184
+ prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
185
+ reviews: described_class.new(ignored_files: %r{app/models/user\.rb})
186
+ )
182
187
  content = <<-EOF
183
188
  class User < ActiveRecord::Base
184
189
  end