rails_best_practices 1.19.2 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.travis.yml +2 -3
  4. data/CHANGELOG.md +7 -7
  5. data/Gemfile +3 -5
  6. data/Gemfile.lock +125 -0
  7. data/Guardfile +2 -0
  8. data/README.md +6 -6
  9. data/Rakefile +2 -17
  10. data/assets/result.html.erb +2 -0
  11. data/lib/rails_best_practices.rb +3 -2
  12. data/lib/rails_best_practices/analyzer.rb +61 -49
  13. data/lib/rails_best_practices/cli.rb +22 -0
  14. data/lib/rails_best_practices/command.rb +1 -131
  15. data/lib/rails_best_practices/core/check.rb +64 -56
  16. data/lib/rails_best_practices/core/checks_loader.rb +24 -23
  17. data/lib/rails_best_practices/core/configs.rb +1 -2
  18. data/lib/rails_best_practices/core/controllers.rb +1 -2
  19. data/lib/rails_best_practices/core/error.rb +1 -1
  20. data/lib/rails_best_practices/core/helpers.rb +1 -2
  21. data/lib/rails_best_practices/core/mailers.rb +1 -2
  22. data/lib/rails_best_practices/core/methods.rb +27 -21
  23. data/lib/rails_best_practices/core/model_associations.rb +10 -5
  24. data/lib/rails_best_practices/core/models.rb +1 -2
  25. data/lib/rails_best_practices/core/modules.rb +1 -1
  26. data/lib/rails_best_practices/core/routes.rb +2 -2
  27. data/lib/rails_best_practices/core/runner.rb +67 -73
  28. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  29. data/lib/rails_best_practices/option_parser.rb +156 -0
  30. data/lib/rails_best_practices/prepares.rb +1 -1
  31. data/lib/rails_best_practices/prepares/controller_prepare.rb +24 -17
  32. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -2
  33. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  34. data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
  35. data/lib/rails_best_practices/prepares/mailer_prepare.rb +2 -1
  36. data/lib/rails_best_practices/prepares/model_prepare.rb +63 -23
  37. data/lib/rails_best_practices/prepares/route_prepare.rb +28 -21
  38. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  39. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +38 -34
  40. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +94 -89
  41. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +15 -5
  42. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +20 -8
  43. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
  44. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
  45. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +16 -16
  46. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +12 -12
  47. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +10 -11
  48. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +25 -24
  49. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +4 -4
  50. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +9 -10
  51. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +10 -11
  52. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +24 -22
  53. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
  54. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  55. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
  56. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +8 -8
  57. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +35 -32
  58. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
  59. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +26 -19
  60. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +12 -10
  61. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +38 -18
  62. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +11 -11
  63. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +77 -74
  64. data/lib/rails_best_practices/reviews/review.rb +2 -1
  65. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -3
  66. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +12 -12
  67. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +18 -15
  68. data/lib/rails_best_practices/reviews/use_model_association_review.rb +15 -15
  69. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +24 -22
  70. data/lib/rails_best_practices/reviews/use_observer_review.rb +28 -28
  71. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
  72. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +68 -66
  73. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -8
  74. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +16 -14
  75. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  76. data/lib/rails_best_practices/version.rb +1 -1
  77. data/rails_best_practices.gemspec +38 -43
  78. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  79. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  80. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  82. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  83. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  84. data/spec/rails_best_practices/core/error_spec.rb +21 -18
  85. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  86. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  87. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  88. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  89. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  90. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  91. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  92. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  93. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  94. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  95. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  96. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  97. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  98. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +32 -31
  99. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  100. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  101. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  102. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  103. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +17 -17
  104. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  105. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  106. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  107. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  108. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +141 -76
  109. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  110. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  111. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  112. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  113. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  114. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  115. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  116. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +13 -13
  117. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  118. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  119. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +29 -22
  120. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  121. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  122. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +32 -22
  123. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  125. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  126. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  127. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  129. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  130. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -17
  131. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  132. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +64 -31
  133. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +21 -14
  134. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +57 -53
  135. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  136. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +20 -14
  137. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  138. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  139. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  140. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  141. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  142. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +35 -31
  143. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  144. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +10 -8
  145. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  146. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  147. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  148. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +61 -59
  149. metadata +16 -18
@@ -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,33 +5,33 @@ 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)
14
14
  end
15
15
 
16
16
  before do
17
- content = <<-EOF
18
- GEM
19
- remote: https://rubygems.org
20
- specs:
21
- rails (3.2.13)
22
- actionmailer (= 3.2.13)
23
- actionpack (= 3.2.13)
24
- activerecord (= 3.2.13)
25
- activeresource (= 3.2.13)
26
- activesupport (= 3.2.13)
27
- bundler (~> 1.0)
28
- railties (= 3.2.13)
29
- EOF
30
- runner.prepare('Gemfile.lock', content)
17
+ content = <<~EOF
18
+ GEM
19
+ remote: https://rubygems.org
20
+ specs:
21
+ rails (3.2.13)
22
+ actionmailer (= 3.2.13)
23
+ actionpack (= 3.2.13)
24
+ activerecord (= 3.2.13)
25
+ activeresource (= 3.2.13)
26
+ activesupport (= 3.2.13)
27
+ bundler (~> 1.0)
28
+ railties (= 3.2.13)
29
+ EOF
30
+ runner.prepare('Gemfile.lock', content)
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 @@ GEM
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 @@ GEM
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 @@ GEM
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 @@ GEM
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,9 +41,9 @@ 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
- content = <<-EOF
44
+ it 'does not check ignored files' do
45
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_controller/))
46
+ content = <<-EOF
45
47
  class PostsController < ApplicationController
46
48
  def edit foo, bar
47
49
  end
@@ -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 %>