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 UseBeforeFilterReview do
8
- let(:runner) { Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2)) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new(customize_count: 2)) }
9
9
 
10
- it 'should use before_filter' do
10
+ it 'uses before_filter' do
11
11
  content = <<-EOF
12
12
  class PostsController < ApplicationController
13
13
  def show
@@ -31,10 +31,12 @@ module RailsBestPractices
31
31
  EOF
32
32
  runner.review('app/controllers/posts_controller.rb', content)
33
33
  expect(runner.errors.size).to eq(1)
34
- 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')
34
+ expect(runner.errors[0].to_s).to eq(
35
+ 'app/controllers/posts_controller.rb:2,6,10,15 - use before_filter for show,edit,update,destroy'
36
+ )
35
37
  end
36
38
 
37
- it 'should not use before_filter when equal to customize count' do
39
+ it 'does not use before_filter when equal to customize count' do
38
40
  content = <<-EOF
39
41
  class PostsController < ApplicationController
40
42
  def show
@@ -50,7 +52,7 @@ module RailsBestPractices
50
52
  expect(runner.errors.size).to eq(0)
51
53
  end
52
54
 
53
- it 'should not use before_filter' do
55
+ it 'does not use before_filter' do
54
56
  content = <<-EOF
55
57
  class PostsController < ApplicationController
56
58
  before_filter :find_post, only: [:show, :edit, :update, :destroy]
@@ -73,7 +75,7 @@ module RailsBestPractices
73
75
  expect(runner.errors.size).to eq(0)
74
76
  end
75
77
 
76
- it 'should not use before_filter by nil' do
78
+ it 'does not use before_filter by nil' do
77
79
  content = <<-EOF
78
80
  class PostsController < ApplicationController
79
81
  def show; end
@@ -86,7 +88,7 @@ module RailsBestPractices
86
88
  expect(runner.errors.size).to eq(0)
87
89
  end
88
90
 
89
- it 'should not use before_filter for protected/private methods' do
91
+ it 'does not use before_filter for protected/private methods' do
90
92
  content = <<-EOF
91
93
  class PostsController < ApplicationController
92
94
  protected
@@ -105,8 +107,8 @@ module RailsBestPractices
105
107
  expect(runner.errors.size).to eq(0)
106
108
  end
107
109
 
108
- it 'should not check ignored files' do
109
- runner = Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2, ignored_files: /posts_controller/))
110
+ it 'does not check ignored files' do
111
+ runner = Core::Runner.new(reviews: described_class.new(customize_count: 2, ignored_files: /posts_controller/))
110
112
  content = <<-EOF
111
113
  class PostsController < ApplicationController
112
114
  def show
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe UseModelAssociationReview do
8
- let(:runner) { Core::Runner.new(reviews: UseModelAssociationReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should use model association for instance variable' do
10
+ it 'uses model association for instance variable' do
11
11
  content = <<-EOF
12
12
  class PostsController < ApplicationController
13
13
  def create
@@ -22,7 +22,7 @@ module RailsBestPractices
22
22
  expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - use model association (for @post)')
23
23
  end
24
24
 
25
- it 'should not use model association without association assign' do
25
+ it 'does not use model association without association assign' do
26
26
  content = <<-EOF
27
27
  class PostsController < ApplicationController
28
28
  def create
@@ -35,7 +35,7 @@ module RailsBestPractices
35
35
  expect(runner.errors.size).to eq(0)
36
36
  end
37
37
 
38
- it 'should use model association for local variable' do
38
+ it 'uses model association for local variable' do
39
39
  content = <<-EOF
40
40
  class PostsController < ApplicationController
41
41
  def create
@@ -50,7 +50,7 @@ module RailsBestPractices
50
50
  expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - use model association (for post)')
51
51
  end
52
52
 
53
- it 'should not use model association' do
53
+ it 'does not use model association' do
54
54
  content = <<-EOF
55
55
  class PostsController < ApplicationController
56
56
  def create
@@ -63,8 +63,8 @@ module RailsBestPractices
63
63
  expect(runner.errors.size).to eq(0)
64
64
  end
65
65
 
66
- it 'should not check ignored files' do
67
- runner = Core::Runner.new(reviews: UseModelAssociationReview.new(ignored_files: /posts_controller/))
66
+ it 'does not check ignored files' do
67
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_controller/))
68
68
  content = <<-EOF
69
69
  class PostsController < ApplicationController
70
70
  def create
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe UseMultipartAlternativeAsContentTypeOfEmailReview do
8
- let(:runner) { Core::Runner.new(prepares: Prepares::GemfilePrepare.new, reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
8
+ let(:runner) { Core::Runner.new(prepares: Prepares::GemfilePrepare.new, reviews: described_class.new) }
9
9
 
10
- before(:each) { allow(Core::Runner).to receive(:base_path).and_return('.') }
10
+ before { allow(Core::Runner).to receive(:base_path).and_return('.') }
11
11
 
12
12
  def mock_email_files(entry_files)
13
13
  allow(Dir).to receive(:entries).with('./app/views/project_mailer').and_return(entry_files)
@@ -31,7 +31,7 @@ module RailsBestPractices
31
31
  end
32
32
 
33
33
  context 'project_mailer' do
34
- let(:content) {
34
+ let(:content) do
35
35
  <<-EOF
36
36
  class ProjectMailer < ActionMailer::Base
37
37
  def send_email(email)
@@ -43,23 +43,25 @@ module RailsBestPractices
43
43
  end
44
44
  end
45
45
  EOF
46
- }
46
+ end
47
47
 
48
48
  context 'erb' do
49
- it 'should use mulipart/alternative as content_type of email' do
49
+ it 'uses mulipart/alternative as content_type of email' do
50
50
  mock_email_files(['send_email.html.erb'])
51
51
  runner.review('app/mailers/project_mailer.rb', content)
52
52
  expect(runner.errors.size).to eq(1)
53
- expect(runner.errors[0].to_s).to eq('app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email')
53
+ expect(runner.errors[0].to_s).to eq(
54
+ 'app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email'
55
+ )
54
56
  end
55
57
 
56
- it 'should not use multiple/alternative as content_type of email when only plain text' do
58
+ it 'does not use multiple/alternative as content_type of email when only plain text' do
57
59
  mock_email_files(['send_email.text.erb'])
58
60
  runner.review('app/mailers/project_mailer.rb', content)
59
61
  expect(runner.errors.size).to eq(0)
60
62
  end
61
63
 
62
- it 'should not use multipart/alternative as content_type of email' do
64
+ it 'does not use multipart/alternative as content_type of email' do
63
65
  mock_email_files(['send_email.text.erb', 'send_email.html.erb'])
64
66
  runner.review('app/mailers/project_mailer.rb', content)
65
67
  expect(runner.errors.size).to eq(0)
@@ -67,32 +69,34 @@ module RailsBestPractices
67
69
  end
68
70
 
69
71
  context 'haml' do
70
- it 'should use mulipart/alternative as content_type of email' do
72
+ it 'uses mulipart/alternative as content_type of email' do
71
73
  mock_email_files(['send_email.html.haml'])
72
74
  runner.review('app/mailers/project_mailer.rb', content)
73
75
  expect(runner.errors.size).to eq(1)
74
- expect(runner.errors[0].to_s).to eq('app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email')
76
+ expect(runner.errors[0].to_s).to eq(
77
+ 'app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email'
78
+ )
75
79
  end
76
80
 
77
- it 'should not use multiple/alternative as content_type of email when only plain text' do
81
+ it 'does not use multiple/alternative as content_type of email when only plain text' do
78
82
  mock_email_files(['send_email.text.haml'])
79
83
  runner.review('app/mailers/project_mailer.rb', content)
80
84
  expect(runner.errors.size).to eq(0)
81
85
  end
82
86
 
83
- it 'should not use multipart/alternative as content_type of email' do
87
+ it 'does not use multipart/alternative as content_type of email' do
84
88
  mock_email_files(['send_email.html.haml', 'send_email.text.haml'])
85
89
  runner.review('app/mailers/project_mailer.rb', content)
86
90
  expect(runner.errors.size).to eq(0)
87
91
  end
88
92
 
89
- it 'should not use multipart/alternative as content_type of email with text locale' do
93
+ it 'does not use multipart/alternative as content_type of email with text locale' do
90
94
  mock_email_files(['send_email.html.haml', 'send_email.de.text.haml'])
91
95
  runner.review('app/mailers/project_mailer.rb', content)
92
96
  expect(runner.errors.size).to eq(0)
93
97
  end
94
98
 
95
- it 'should not use multipart/alternative as content_type of email with html locale' do
99
+ it 'does not use multipart/alternative as content_type of email with html locale' do
96
100
  mock_email_files(['send_email.de.html.haml', 'send_email.text.haml'])
97
101
  runner.review('app/mailers/project_mailer.rb', content)
98
102
  expect(runner.errors.size).to eq(0)
@@ -100,7 +104,7 @@ module RailsBestPractices
100
104
  end
101
105
 
102
106
  context 'haml/erb mix' do
103
- it 'should not suggest using multipart/alternative when mixing html.haml and text.erb' do
107
+ it 'does not suggest using multipart/alternative when mixing html.haml and text.erb' do
104
108
  mock_email_files(['send_email.html.haml', 'send_email.text.erb'])
105
109
  runner.review('app/mailers/project_mailer.rb', content)
106
110
  expect(runner.errors.size).to eq(0)
@@ -111,8 +115,8 @@ module RailsBestPractices
111
115
  end
112
116
  end
113
117
 
114
- it 'should not check ignored files' do
115
- runner = Core::Runner.new(reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new(ignored_files: /project_mailer/))
118
+ it 'does not check ignored files' do
119
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /project_mailer/))
116
120
  mock_email_files(['send_email.html.haml'])
117
121
  runner.review('app/mailers/project_mailer.rb', content)
118
122
  expect(runner.errors.size).to eq(0)
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe UseObserverReview do
8
- let(:runner) { Core::Runner.new(prepares: Prepares::MailerPrepare.new, reviews: UseObserverReview.new) }
8
+ let(:runner) { Core::Runner.new(prepares: Prepares::MailerPrepare.new, reviews: described_class.new) }
9
9
 
10
- before :each do
10
+ before do
11
11
  content = <<-EOF
12
12
  class ProjectMailer < ActionMailer::Base
13
13
  end
@@ -15,7 +15,7 @@ module RailsBestPractices
15
15
  runner.prepare('app/models/project_mailer.rb', content)
16
16
  end
17
17
 
18
- it 'should use observer' do
18
+ it 'uses observer' do
19
19
  content = <<-EOF
20
20
  class Project < ActiveRecord::Base
21
21
  after_create :send_create_notification
@@ -33,7 +33,7 @@ module RailsBestPractices
33
33
  expect(runner.errors[0].to_s).to eq('app/models/project.rb:5 - use observer')
34
34
  end
35
35
 
36
- it 'should not use observer without callback' do
36
+ it 'does not use observer without callback' do
37
37
  content = <<-EOF
38
38
  class Project < ActiveRecord::Base
39
39
  private
@@ -48,7 +48,7 @@ module RailsBestPractices
48
48
  expect(runner.errors.size).to eq(0)
49
49
  end
50
50
 
51
- it 'should use observer with two after_create' do
51
+ it 'uses observer with two after_create' do
52
52
  content = <<-EOF
53
53
  class Project < ActiveRecord::Base
54
54
  after_create :send_create_notification, :update_author
@@ -69,7 +69,7 @@ module RailsBestPractices
69
69
  expect(runner.errors[0].to_s).to eq('app/models/project.rb:5 - use observer')
70
70
  end
71
71
 
72
- it 'should not raise when initiate an object in callback' do
72
+ it 'does not raise when initiate an object in callback' do
73
73
  content = <<-EOF
74
74
  class Project < ActiveRecord::Base
75
75
  after_create ProjectMailer.new
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe UseParenthesesInMethodDefReview do
8
- let(:runner) { Core::Runner.new(reviews: UseParenthesesInMethodDefReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should find missing parentheses' do
10
+ it 'finds missing parentheses' do
11
11
  content = <<-EOF
12
12
  class PostsController < ApplicationController
13
13
  def edit foo, bar
@@ -16,9 +16,11 @@ module RailsBestPractices
16
16
  EOF
17
17
  runner.review('app/controllers/posts_controller.rb', content)
18
18
  expect(runner.errors.size).to eq(1)
19
- expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions')
19
+ expect(runner.errors[0].to_s).to eq(
20
+ 'app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions'
21
+ )
20
22
  end
21
- it 'should find parentheses with no error' do
23
+ it 'finds parentheses with no error' do
22
24
  content = <<-EOF
23
25
  class PostsController < ApplicationController
24
26
  def edit(foo, bar)
@@ -28,7 +30,7 @@ module RailsBestPractices
28
30
  runner.review('app/controllers/posts_controller.rb', content)
29
31
  expect(runner.errors.size).to eq(0)
30
32
  end
31
- it 'should not throw an error without parameters' do
33
+ it 'does not throw an error without parameters' do
32
34
  content = <<-EOF
33
35
  class PostsController < ApplicationController
34
36
  def edit
@@ -39,8 +41,8 @@ module RailsBestPractices
39
41
  expect(runner.errors.size).to eq(0)
40
42
  end
41
43
 
42
- it 'should not check ignored files' do
43
- runner = Core::Runner.new(reviews: UseParenthesesInMethodDefReview.new(ignored_files: /posts_controller/))
44
+ it 'does not check ignored files' do
45
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_controller/))
44
46
  content = <<-EOF
45
47
  class PostsController < ApplicationController
46
48
  def edit foo, bar
@@ -5,9 +5,13 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe UseQueryAttributeReview do
8
- let(:runner) { Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new], reviews: UseQueryAttributeReview.new) }
8
+ let(:runner) do
9
+ Core::Runner.new(
10
+ prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new], reviews: described_class.new
11
+ )
12
+ end
9
13
 
10
- before :each do
14
+ before do
11
15
  content = <<-EOF
12
16
  class User < ActiveRecord::Base
13
17
  has_many :projects
@@ -30,7 +34,7 @@ module RailsBestPractices
30
34
  runner.prepare('db/schema.rb', content)
31
35
  end
32
36
 
33
- it 'should use query attribute by blank call' do
37
+ it 'uses query attribute by blank call' do
34
38
  content = <<-EOF
35
39
  <% if @user.login.blank? %>
36
40
  <%= link_to 'login', new_session_path %>
@@ -41,7 +45,7 @@ module RailsBestPractices
41
45
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
42
46
  end
43
47
 
44
- it 'should use query attribute by blank call with if in one line' do
48
+ it 'uses query attribute by blank call with if in one line' do
45
49
  content = <<-EOF
46
50
  <%= link_to 'login', new_session_path if @user.login.blank? %>
47
51
  EOF
@@ -50,7 +54,7 @@ module RailsBestPractices
50
54
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
51
55
  end
52
56
 
53
- it "should use query attribute by blank call with '? :'" do
57
+ it "uses query attribute by blank call with '? :'" do
54
58
  content = <<-EOF
55
59
  <%= @user.login.blank? ? link_to('login', new_session_path) : '' %>
56
60
  EOF
@@ -59,7 +63,7 @@ module RailsBestPractices
59
63
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
60
64
  end
61
65
 
62
- it 'should use query attribute by comparing empty string' do
66
+ it 'uses query attribute by comparing empty string' do
63
67
  content = <<-EOF
64
68
  <% if @user.login == "" %>
65
69
  <%= link_to 'login', new_session_path %>
@@ -70,7 +74,7 @@ module RailsBestPractices
70
74
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
71
75
  end
72
76
 
73
- it 'should use query attribute by nil call' do
77
+ it 'uses query attribute by nil call' do
74
78
  content = <<-EOF
75
79
  <% if @user.login.nil? %>
76
80
  <%= link_to 'login', new_session_path %>
@@ -81,7 +85,7 @@ module RailsBestPractices
81
85
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
82
86
  end
83
87
 
84
- it 'should use query attribute by present call' do
88
+ it 'uses query attribute by present call' do
85
89
  content = <<-EOF
86
90
  <% if @user.login.present? %>
87
91
  <%= @user.login %>
@@ -92,7 +96,7 @@ module RailsBestPractices
92
96
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
93
97
  end
94
98
 
95
- it 'should use query attribute within and conditions' do
99
+ it 'uses query attribute within and conditions' do
96
100
  content = <<-EOF
97
101
  <% if @user.active? && @user.login.present? %>
98
102
  <%= @user.login %>
@@ -103,7 +107,7 @@ module RailsBestPractices
103
107
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
104
108
  end
105
109
 
106
- it 'should use query attribute within or conditions' do
110
+ it 'uses query attribute within or conditions' do
107
111
  content = <<-EOF
108
112
  <% if @user.active? or @user.login != "" %>
109
113
  <%= @user.login %>
@@ -114,7 +118,7 @@ module RailsBestPractices
114
118
  expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
115
119
  end
116
120
 
117
- it 'should not use query attribute' do
121
+ it 'does not use query attribute' do
118
122
  content = <<-EOF
119
123
  <% if @user.login? %>
120
124
  <%= @user.login %>
@@ -124,7 +128,7 @@ module RailsBestPractices
124
128
  expect(runner.errors.size).to eq(0)
125
129
  end
126
130
 
127
- it 'should not use query attribute for number' do
131
+ it 'does not use query attribute for number' do
128
132
  content = <<-EOF
129
133
  <% unless @user.age.blank? %>
130
134
  <%= @user.age %>
@@ -134,7 +138,7 @@ module RailsBestPractices
134
138
  expect(runner.errors.size).to eq(0)
135
139
  end
136
140
 
137
- it 'should not review for pluralize attribute' do
141
+ it 'does not review for pluralize attribute' do
138
142
  content = <<-EOF
139
143
  <% if @user.roles.blank? %>
140
144
  <%= @user.login %>
@@ -144,7 +148,7 @@ module RailsBestPractices
144
148
  expect(runner.errors.size).to eq(0)
145
149
  end
146
150
 
147
- it 'should not review non model class' do
151
+ it 'does not review non model class' do
148
152
  content = <<-EOF
149
153
  <% if @person.login.present? %>
150
154
  <%= @person.login %>
@@ -155,7 +159,7 @@ module RailsBestPractices
155
159
  end
156
160
 
157
161
  context 'association' do
158
- it 'should not review belongs_to association' do
162
+ it 'does not review belongs_to association' do
159
163
  content = <<-EOF
160
164
  <% if @user.location.present? %>
161
165
  <%= @user.location.name %>
@@ -165,7 +169,7 @@ module RailsBestPractices
165
169
  expect(runner.errors.size).to eq(0)
166
170
  end
167
171
 
168
- it 'should not review belongs_to category' do
172
+ it 'does not review belongs_to category' do
169
173
  content = <<-EOF
170
174
  <% if @user.category.present? %>
171
175
  <%= @user.category.name %>
@@ -175,7 +179,7 @@ module RailsBestPractices
175
179
  expect(runner.errors.size).to eq(0)
176
180
  end
177
181
 
178
- it 'should not review has_one association' do
182
+ it 'does not review has_one association' do
179
183
  content = <<-EOF
180
184
  <% if @user.phone.present? %>
181
185
  <%= @user.phone.number %>
@@ -185,7 +189,7 @@ module RailsBestPractices
185
189
  expect(runner.errors.size).to eq(0)
186
190
  end
187
191
 
188
- it 'should not review has_many association' do
192
+ it 'does not review has_many association' do
189
193
  content = <<-EOF
190
194
  <% if @user.projects.present? %>
191
195
  <%= @user.projects.first.name %>
@@ -196,7 +200,7 @@ module RailsBestPractices
196
200
  end
197
201
  end
198
202
 
199
- it 'should not review for class method' do
203
+ it 'does not review for class method' do
200
204
  content = <<-EOF
201
205
  <% if User.name.present? %>
202
206
  <%= User.name %>
@@ -206,7 +210,7 @@ module RailsBestPractices
206
210
  expect(runner.errors.size).to eq(0)
207
211
  end
208
212
 
209
- it 'should not review for non attribute call' do
213
+ it 'does not review for non attribute call' do
210
214
  content = <<-EOF
211
215
  if @user.login(false).nil?
212
216
  puts @user.login(false)
@@ -216,7 +220,7 @@ module RailsBestPractices
216
220
  expect(runner.errors.size).to eq(0)
217
221
  end
218
222
 
219
- it 'should not raise error for common conditional statement' do
223
+ it 'does not raise error for common conditional statement' do
220
224
  content = <<-EOF
221
225
  if voteable.is_a? Answer
222
226
  puts voteable.title
@@ -225,9 +229,12 @@ module RailsBestPractices
225
229
  expect { runner.review('app/models/users_controller.rb', content) }.not_to raise_error
226
230
  end
227
231
 
228
- it 'should not check ignored files' do
229
- runner = Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
230
- reviews: UseQueryAttributeReview.new(ignored_files: /users\/show/))
232
+ it 'does not check ignored files' do
233
+ runner =
234
+ Core::Runner.new(
235
+ prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
236
+ reviews: described_class.new(ignored_files: %r{users/show})
237
+ )
231
238
  content = <<-EOF
232
239
  <% if @user.login.blank? %>
233
240
  <%= link_to 'login', new_session_path %>