rails_best_practices 1.19.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Guardfile +2 -2
  4. data/Rakefile +8 -8
  5. data/bin/rails_best_practices +1 -1
  6. data/lib/rails_best_practices/analyzer.rb +45 -45
  7. data/lib/rails_best_practices/command.rb +40 -40
  8. data/lib/rails_best_practices/core/check.rb +15 -15
  9. data/lib/rails_best_practices/core/klasses.rb +1 -1
  10. data/lib/rails_best_practices/core/methods.rb +7 -7
  11. data/lib/rails_best_practices/core/model_associations.rb +3 -3
  12. data/lib/rails_best_practices/core/modules.rb +1 -1
  13. data/lib/rails_best_practices/core/routes.rb +2 -2
  14. data/lib/rails_best_practices/core/runner.rb +3 -3
  15. data/lib/rails_best_practices/core_ext/erubis.rb +4 -4
  16. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -2
  17. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -2
  18. data/lib/rails_best_practices/prepares/config_prepare.rb +1 -1
  19. data/lib/rails_best_practices/prepares/controller_prepare.rb +8 -8
  20. data/lib/rails_best_practices/prepares/helper_prepare.rb +1 -1
  21. data/lib/rails_best_practices/prepares/initializer_prepare.rb +4 -4
  22. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -1
  23. data/lib/rails_best_practices/prepares/model_prepare.rb +19 -19
  24. data/lib/rails_best_practices/prepares/route_prepare.rb +34 -34
  25. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  26. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
  27. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +7 -7
  28. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +1 -1
  29. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +3 -3
  30. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +3 -3
  31. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +1 -1
  32. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +6 -6
  33. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +2 -2
  34. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +4 -4
  35. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -3
  36. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
  37. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
  38. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +2 -2
  39. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +4 -4
  41. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -2
  42. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +4 -4
  43. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +3 -3
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -2
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +9 -9
  46. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +3 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -11
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +1 -1
  49. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +8 -7
  50. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
  51. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -2
  52. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +22 -22
  53. data/lib/rails_best_practices/reviews/review.rb +2 -2
  54. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +3 -3
  55. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +4 -4
  56. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -2
  57. data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
  58. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +2 -2
  59. data/lib/rails_best_practices/reviews/use_observer_review.rb +3 -3
  60. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +1 -1
  61. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +3 -3
  62. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -2
  63. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +5 -5
  64. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -4
  65. data/lib/rails_best_practices/version.rb +1 -1
  66. data/rails_best_practices.gemspec +24 -24
  67. data/spec/rails_best_practices/analyzer_spec.rb +43 -43
  68. data/spec/rails_best_practices/core/check_spec.rb +2 -2
  69. data/spec/rails_best_practices/core/checks_loader_spec.rb +4 -4
  70. data/spec/rails_best_practices/core/error_spec.rb +16 -16
  71. data/spec/rails_best_practices/core/except_methods_spec.rb +15 -15
  72. data/spec/rails_best_practices/core/gems_spec.rb +9 -9
  73. data/spec/rails_best_practices/core/klasses_spec.rb +17 -17
  74. data/spec/rails_best_practices/core/methods_spec.rb +28 -28
  75. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -10
  76. data/spec/rails_best_practices/core/model_attributes_spec.rb +10 -10
  77. data/spec/rails_best_practices/core/modules_spec.rb +10 -10
  78. data/spec/rails_best_practices/core/routes_spec.rb +10 -10
  79. data/spec/rails_best_practices/core/runner_spec.rb +4 -4
  80. data/spec/rails_best_practices/core_ext/erubis_spec.rb +7 -7
  81. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +7 -7
  82. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  83. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  84. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -3
  85. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +26 -26
  86. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -3
  87. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +6 -6
  88. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +5 -5
  89. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  90. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +108 -108
  91. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +77 -77
  92. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +8 -8
  93. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +10 -10
  94. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +27 -27
  95. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +11 -11
  96. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +17 -17
  97. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  98. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +4 -4
  99. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +8 -8
  100. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +10 -10
  101. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +16 -16
  103. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  104. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +4 -4
  105. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +13 -13
  106. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  107. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +5 -5
  108. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +10 -10
  109. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +8 -8
  110. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +4 -4
  111. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +11 -11
  112. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  113. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +16 -16
  114. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +5 -5
  115. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -33
  116. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +7 -7
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +106 -106
  118. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +5 -5
  119. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +8 -8
  120. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +29 -29
  121. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +15 -15
  122. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +15 -15
  123. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  125. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +29 -29
  126. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  127. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +28 -28
  129. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -9
  130. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +23 -23
  131. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +6 -6
  132. data/spec/spec_helper.rb +1 -1
  133. metadata +7 -7
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe UseBeforeFilterReview do
6
6
  let(:runner) { Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2)) }
7
7
 
8
- it "should use before_filter" do
8
+ it 'should use before_filter' do
9
9
  content = <<-EOF
10
10
  class PostsController < ApplicationController
11
11
  def show
@@ -29,10 +29,10 @@ module RailsBestPractices
29
29
  EOF
30
30
  runner.review('app/controllers/posts_controller.rb', content)
31
31
  expect(runner.errors.size).to eq(1)
32
- 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")
32
+ 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')
33
33
  end
34
34
 
35
- it "should not use before_filter when equal to customize count" do
35
+ it 'should not use before_filter when equal to customize count' do
36
36
  content = <<-EOF
37
37
  class PostsController < ApplicationController
38
38
  def show
@@ -48,7 +48,7 @@ module RailsBestPractices
48
48
  expect(runner.errors.size).to eq(0)
49
49
  end
50
50
 
51
- it "should not use before_filter" do
51
+ it 'should not use before_filter' do
52
52
  content = <<-EOF
53
53
  class PostsController < ApplicationController
54
54
  before_filter :find_post, only: [:show, :edit, :update, :destroy]
@@ -71,7 +71,7 @@ module RailsBestPractices
71
71
  expect(runner.errors.size).to eq(0)
72
72
  end
73
73
 
74
- it "should not use before_filter by nil" do
74
+ it 'should not use before_filter by nil' do
75
75
  content = <<-EOF
76
76
  class PostsController < ApplicationController
77
77
  def show; end
@@ -84,7 +84,7 @@ module RailsBestPractices
84
84
  expect(runner.errors.size).to eq(0)
85
85
  end
86
86
 
87
- it "should not use before_filter for protected/private methods" do
87
+ it 'should not use before_filter for protected/private methods' do
88
88
  content =<<-EOF
89
89
  class PostsController < ApplicationController
90
90
  protected
@@ -103,7 +103,7 @@ module RailsBestPractices
103
103
  expect(runner.errors.size).to eq(0)
104
104
  end
105
105
 
106
- it "should not check ignored files" do
106
+ it 'should not check ignored files' do
107
107
  runner = Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2, ignored_files: /posts_controller/))
108
108
  content = <<-EOF
109
109
  class PostsController < ApplicationController
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe UseModelAssociationReview do
6
6
  let(:runner) { Core::Runner.new(reviews: UseModelAssociationReview.new) }
7
7
 
8
- it "should use model association for instance variable" do
8
+ it 'should use model association for instance variable' do
9
9
  content = <<-EOF
10
10
  class PostsController < ApplicationController
11
11
  def create
@@ -17,10 +17,10 @@ module RailsBestPractices
17
17
  EOF
18
18
  runner.review('app/controllers/posts_controller.rb', content)
19
19
  expect(runner.errors.size).to eq(1)
20
- expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - use model association (for @post)")
20
+ expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - use model association (for @post)')
21
21
  end
22
22
 
23
- it "should not use model association without association assign" do
23
+ it 'should not use model association without association assign' do
24
24
  content = <<-EOF
25
25
  class PostsController < ApplicationController
26
26
  def create
@@ -33,7 +33,7 @@ module RailsBestPractices
33
33
  expect(runner.errors.size).to eq(0)
34
34
  end
35
35
 
36
- it "should use model association for local variable" do
36
+ it 'should use model association for local variable' do
37
37
  content = <<-EOF
38
38
  class PostsController < ApplicationController
39
39
  def create
@@ -45,10 +45,10 @@ module RailsBestPractices
45
45
  EOF
46
46
  runner.review('app/controllers/posts_controller.rb', content)
47
47
  expect(runner.errors.size).to eq(1)
48
- expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - use model association (for post)")
48
+ expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - use model association (for post)')
49
49
  end
50
50
 
51
- it "should not use model association" do
51
+ it 'should not use model association' do
52
52
  content = <<-EOF
53
53
  class PostsController < ApplicationController
54
54
  def create
@@ -61,7 +61,7 @@ module RailsBestPractices
61
61
  expect(runner.errors.size).to eq(0)
62
62
  end
63
63
 
64
- it "should not check ignored files" do
64
+ it 'should not check ignored files' do
65
65
  runner = Core::Runner.new(reviews: UseModelAssociationReview.new(ignored_files: /posts_controller/))
66
66
  content = <<-EOF
67
67
  class PostsController < ApplicationController
@@ -5,10 +5,10 @@ module RailsBestPractices
5
5
  describe UseMultipartAlternativeAsContentTypeOfEmailReview do
6
6
  let(:runner) { Core::Runner.new(prepares: Prepares::GemfilePrepare.new, reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
7
7
 
8
- before(:each) { allow(Core::Runner).to receive(:base_path).and_return(".") }
8
+ before(:each) { allow(Core::Runner).to receive(:base_path).and_return('.') }
9
9
 
10
10
  def mock_email_files(entry_files)
11
- allow(Dir).to receive(:entries).with("./app/views/project_mailer").and_return(entry_files)
11
+ allow(Dir).to receive(:entries).with('./app/views/project_mailer').and_return(entry_files)
12
12
  end
13
13
 
14
14
  before do
@@ -28,7 +28,7 @@ GEM
28
28
  runner.prepare('Gemfile.lock', content)
29
29
  end
30
30
 
31
- context "project_mailer" do
31
+ context 'project_mailer' do
32
32
  let(:content) {
33
33
  <<-EOF
34
34
  class ProjectMailer < ActionMailer::Base
@@ -43,75 +43,75 @@ GEM
43
43
  EOF
44
44
  }
45
45
 
46
- context "erb" do
47
- it "should use mulipart/alternative as content_type of email" do
48
- mock_email_files(["send_email.html.erb"])
46
+ context 'erb' do
47
+ it 'should use mulipart/alternative as content_type of email' do
48
+ mock_email_files(['send_email.html.erb'])
49
49
  runner.review('app/mailers/project_mailer.rb', content)
50
50
  expect(runner.errors.size).to eq(1)
51
- expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
51
+ expect(runner.errors[0].to_s).to eq('app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email')
52
52
  end
53
53
 
54
- it "should not use multiple/alternative as content_type of email when only plain text" do
55
- mock_email_files(["send_email.text.erb"])
54
+ it 'should not use multiple/alternative as content_type of email when only plain text' do
55
+ mock_email_files(['send_email.text.erb'])
56
56
  runner.review('app/mailers/project_mailer.rb', content)
57
57
  expect(runner.errors.size).to eq(0)
58
58
  end
59
59
 
60
- it "should not use multipart/alternative as content_type of email" do
61
- mock_email_files(["send_email.text.erb", "send_email.html.erb"])
60
+ it 'should not use multipart/alternative as content_type of email' do
61
+ mock_email_files(['send_email.text.erb', 'send_email.html.erb'])
62
62
  runner.review('app/mailers/project_mailer.rb', content)
63
63
  expect(runner.errors.size).to eq(0)
64
64
  end
65
65
  end
66
66
 
67
- context "haml" do
68
- it "should use mulipart/alternative as content_type of email" do
69
- mock_email_files(["send_email.html.haml"])
67
+ context 'haml' do
68
+ it 'should use mulipart/alternative as content_type of email' do
69
+ mock_email_files(['send_email.html.haml'])
70
70
  runner.review('app/mailers/project_mailer.rb', content)
71
71
  expect(runner.errors.size).to eq(1)
72
- expect(runner.errors[0].to_s).to eq("app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email")
72
+ expect(runner.errors[0].to_s).to eq('app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email')
73
73
  end
74
74
 
75
- it "should not use multiple/alternative as content_type of email when only plain text" do
76
- mock_email_files(["send_email.text.haml"])
75
+ it 'should not use multiple/alternative as content_type of email when only plain text' do
76
+ mock_email_files(['send_email.text.haml'])
77
77
  runner.review('app/mailers/project_mailer.rb', content)
78
78
  expect(runner.errors.size).to eq(0)
79
79
  end
80
80
 
81
- it "should not use multipart/alternative as content_type of email" do
82
- mock_email_files(["send_email.html.haml", "send_email.text.haml"])
81
+ it 'should not use multipart/alternative as content_type of email' do
82
+ mock_email_files(['send_email.html.haml', 'send_email.text.haml'])
83
83
  runner.review('app/mailers/project_mailer.rb', content)
84
84
  expect(runner.errors.size).to eq(0)
85
85
  end
86
86
 
87
- it "should not use multipart/alternative as content_type of email with text locale" do
88
- mock_email_files(["send_email.html.haml", "send_email.de.text.haml"])
87
+ it 'should not use multipart/alternative as content_type of email with text locale' do
88
+ mock_email_files(['send_email.html.haml', 'send_email.de.text.haml'])
89
89
  runner.review('app/mailers/project_mailer.rb', content)
90
90
  expect(runner.errors.size).to eq(0)
91
91
  end
92
92
 
93
- it "should not use multipart/alternative as content_type of email with html locale" do
94
- mock_email_files(["send_email.de.html.haml", "send_email.text.haml"])
93
+ it 'should not use multipart/alternative as content_type of email with html locale' do
94
+ mock_email_files(['send_email.de.html.haml', 'send_email.text.haml'])
95
95
  runner.review('app/mailers/project_mailer.rb', content)
96
96
  expect(runner.errors.size).to eq(0)
97
97
  end
98
98
  end
99
99
 
100
- context "haml/erb mix" do
101
- it "should not suggest using multipart/alternative when mixing html.haml and text.erb" do
102
- mock_email_files(["send_email.html.haml", "send_email.text.erb"])
100
+ context 'haml/erb mix' do
101
+ it 'should not suggest using multipart/alternative when mixing html.haml and text.erb' do
102
+ mock_email_files(['send_email.html.haml', 'send_email.text.erb'])
103
103
  runner.review('app/mailers/project_mailer.rb', content)
104
104
  expect(runner.errors.size).to eq(0)
105
105
 
106
- mock_email_files(["send_email.html.erb", "send_email.text.haml"])
106
+ mock_email_files(['send_email.html.erb', 'send_email.text.haml'])
107
107
  runner.review('app/mailers/project_mailer.rb', content)
108
108
  expect(runner.errors.size).to eq(0)
109
109
  end
110
110
  end
111
111
 
112
- it "should not check ignored files" do
112
+ it 'should not check ignored files' do
113
113
  runner = Core::Runner.new(reviews: UseMultipartAlternativeAsContentTypeOfEmailReview.new(ignored_files: /project_mailer/))
114
- mock_email_files(["send_email.html.haml"])
114
+ mock_email_files(['send_email.html.haml'])
115
115
  runner.review('app/mailers/project_mailer.rb', content)
116
116
  expect(runner.errors.size).to eq(0)
117
117
  end
@@ -13,7 +13,7 @@ module RailsBestPractices
13
13
  runner.prepare('app/models/project_mailer.rb', content)
14
14
  end
15
15
 
16
- it "should use observer" do
16
+ it 'should use observer' do
17
17
  content =<<-EOF
18
18
  class Project < ActiveRecord::Base
19
19
  after_create :send_create_notification
@@ -28,10 +28,10 @@ module RailsBestPractices
28
28
  EOF
29
29
  runner.review('app/models/project.rb', content)
30
30
  expect(runner.errors.size).to eq(1)
31
- expect(runner.errors[0].to_s).to eq("app/models/project.rb:5 - use observer")
31
+ expect(runner.errors[0].to_s).to eq('app/models/project.rb:5 - use observer')
32
32
  end
33
33
 
34
- it "should not use observer without callback" do
34
+ it 'should not use observer without callback' do
35
35
  content =<<-EOF
36
36
  class Project < ActiveRecord::Base
37
37
  private
@@ -46,7 +46,7 @@ module RailsBestPractices
46
46
  expect(runner.errors.size).to eq(0)
47
47
  end
48
48
 
49
- it "should use observer with two after_create" do
49
+ it 'should use observer with two after_create' do
50
50
  content =<<-EOF
51
51
  class Project < ActiveRecord::Base
52
52
  after_create :send_create_notification, :update_author
@@ -64,10 +64,10 @@ module RailsBestPractices
64
64
  EOF
65
65
  runner.review('app/models/project.rb', content)
66
66
  expect(runner.errors.size).to eq(1)
67
- expect(runner.errors[0].to_s).to eq("app/models/project.rb:5 - use observer")
67
+ expect(runner.errors[0].to_s).to eq('app/models/project.rb:5 - use observer')
68
68
  end
69
69
 
70
- it "should not raise when initiate an object in callback" do
70
+ it 'should not raise when initiate an object in callback' do
71
71
  content =<<-EOF
72
72
  class Project < ActiveRecord::Base
73
73
  after_create ProjectMailer.new
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe UseParenthesesInMethodDefReview do
6
6
  let(:runner) { Core::Runner.new(reviews: UseParenthesesInMethodDefReview.new) }
7
7
 
8
- it "should find missing parentheses" do
8
+ it 'should find missing parentheses' do
9
9
  content = <<-EOF
10
10
  class PostsController < ApplicationController
11
11
  def edit foo, bar
@@ -14,9 +14,9 @@ module RailsBestPractices
14
14
  EOF
15
15
  runner.review('app/controllers/posts_controller.rb', content)
16
16
  expect(runner.errors.size).to eq(1)
17
- expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions")
17
+ expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions')
18
18
  end
19
- it "should find parentheses with no error" do
19
+ it 'should find parentheses with no error' do
20
20
  content = <<-EOF
21
21
  class PostsController < ApplicationController
22
22
  def edit(foo, bar)
@@ -26,7 +26,7 @@ module RailsBestPractices
26
26
  runner.review('app/controllers/posts_controller.rb', content)
27
27
  expect(runner.errors.size).to eq(0)
28
28
  end
29
- it "should not throw an error without parameters" do
29
+ it 'should not throw an error without parameters' do
30
30
  content = <<-EOF
31
31
  class PostsController < ApplicationController
32
32
  def edit
@@ -37,7 +37,7 @@ module RailsBestPractices
37
37
  expect(runner.errors.size).to eq(0)
38
38
  end
39
39
 
40
- it "should not check ignored files" do
40
+ it 'should not check ignored files' do
41
41
  runner = Core::Runner.new(reviews: UseParenthesesInMethodDefReview.new(ignored_files: /posts_controller/))
42
42
  content = <<-EOF
43
43
  class PostsController < ApplicationController
@@ -28,7 +28,7 @@ module RailsBestPractices
28
28
  runner.prepare('db/schema.rb', content)
29
29
  end
30
30
 
31
- it "should use query attribute by blank call" do
31
+ it 'should use query attribute by blank call' do
32
32
  content = <<-EOF
33
33
  <% if @user.login.blank? %>
34
34
  <%= link_to 'login', new_session_path %>
@@ -36,16 +36,16 @@ module RailsBestPractices
36
36
  EOF
37
37
  runner.review('app/views/users/show.html.erb', content)
38
38
  expect(runner.errors.size).to eq(1)
39
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
39
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
40
40
  end
41
41
 
42
- it "should use query attribute by blank call with if in one line" do
42
+ it 'should use query attribute by blank call with if in one line' do
43
43
  content = <<-EOF
44
44
  <%= link_to 'login', new_session_path if @user.login.blank? %>
45
45
  EOF
46
46
  runner.review('app/views/users/show.html.erb', content)
47
47
  expect(runner.errors.size).to eq(1)
48
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
48
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
49
49
  end
50
50
 
51
51
  it "should use query attribute by blank call with '? :'" do
@@ -54,10 +54,10 @@ module RailsBestPractices
54
54
  EOF
55
55
  runner.review('app/views/users/show.html.erb', content)
56
56
  expect(runner.errors.size).to eq(1)
57
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
57
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
58
58
  end
59
59
 
60
- it "should use query attribute by comparing empty string" do
60
+ it 'should use query attribute by comparing empty string' do
61
61
  content = <<-EOF
62
62
  <% if @user.login == "" %>
63
63
  <%= link_to 'login', new_session_path %>
@@ -65,10 +65,10 @@ module RailsBestPractices
65
65
  EOF
66
66
  runner.review('app/views/users/show.html.erb', content)
67
67
  expect(runner.errors.size).to eq(1)
68
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
68
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
69
69
  end
70
70
 
71
- it "should use query attribute by nil call" do
71
+ it 'should use query attribute by nil call' do
72
72
  content = <<-EOF
73
73
  <% if @user.login.nil? %>
74
74
  <%= link_to 'login', new_session_path %>
@@ -76,10 +76,10 @@ module RailsBestPractices
76
76
  EOF
77
77
  runner.review('app/views/users/show.html.erb', content)
78
78
  expect(runner.errors.size).to eq(1)
79
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
79
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
80
80
  end
81
81
 
82
- it "should use query attribute by present call" do
82
+ it 'should use query attribute by present call' do
83
83
  content = <<-EOF
84
84
  <% if @user.login.present? %>
85
85
  <%= @user.login %>
@@ -87,10 +87,10 @@ module RailsBestPractices
87
87
  EOF
88
88
  runner.review('app/views/users/show.html.erb', content)
89
89
  expect(runner.errors.size).to eq(1)
90
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
90
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
91
91
  end
92
92
 
93
- it "should use query attribute within and conditions" do
93
+ it 'should use query attribute within and conditions' do
94
94
  content = <<-EOF
95
95
  <% if @user.active? && @user.login.present? %>
96
96
  <%= @user.login %>
@@ -98,10 +98,10 @@ module RailsBestPractices
98
98
  EOF
99
99
  runner.review('app/views/users/show.html.erb', content)
100
100
  expect(runner.errors.size).to eq(1)
101
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
101
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
102
102
  end
103
103
 
104
- it "should use query attribute within or conditions" do
104
+ it 'should use query attribute within or conditions' do
105
105
  content = <<-EOF
106
106
  <% if @user.active? or @user.login != "" %>
107
107
  <%= @user.login %>
@@ -109,10 +109,10 @@ module RailsBestPractices
109
109
  EOF
110
110
  runner.review('app/views/users/show.html.erb', content)
111
111
  expect(runner.errors.size).to eq(1)
112
- expect(runner.errors[0].to_s).to eq("app/views/users/show.html.erb:1 - use query attribute (@user.login?)")
112
+ expect(runner.errors[0].to_s).to eq('app/views/users/show.html.erb:1 - use query attribute (@user.login?)')
113
113
  end
114
114
 
115
- it "should not use query attribute" do
115
+ it 'should not use query attribute' do
116
116
  content = <<-EOF
117
117
  <% if @user.login? %>
118
118
  <%= @user.login %>
@@ -122,7 +122,7 @@ module RailsBestPractices
122
122
  expect(runner.errors.size).to eq(0)
123
123
  end
124
124
 
125
- it "should not use query attribute for number" do
125
+ it 'should not use query attribute for number' do
126
126
  content =<<-EOF
127
127
  <% unless @user.age.blank? %>
128
128
  <%= @user.age %>
@@ -132,7 +132,7 @@ module RailsBestPractices
132
132
  expect(runner.errors.size).to eq(0)
133
133
  end
134
134
 
135
- it "should not review for pluralize attribute" do
135
+ it 'should not review for pluralize attribute' do
136
136
  content = <<-EOF
137
137
  <% if @user.roles.blank? %>
138
138
  <%= @user.login %>
@@ -142,7 +142,7 @@ module RailsBestPractices
142
142
  expect(runner.errors.size).to eq(0)
143
143
  end
144
144
 
145
- it "should not review non model class" do
145
+ it 'should not review non model class' do
146
146
  content = <<-EOF
147
147
  <% if @person.login.present? %>
148
148
  <%= @person.login %>
@@ -152,8 +152,8 @@ module RailsBestPractices
152
152
  expect(runner.errors.size).to eq(0)
153
153
  end
154
154
 
155
- context "association" do
156
- it "should not review belongs_to association" do
155
+ context 'association' do
156
+ it 'should not review belongs_to association' do
157
157
  content = <<-EOF
158
158
  <% if @user.location.present? %>
159
159
  <%= @user.location.name %>
@@ -163,7 +163,7 @@ module RailsBestPractices
163
163
  expect(runner.errors.size).to eq(0)
164
164
  end
165
165
 
166
- it "should not review belongs_to category" do
166
+ it 'should not review belongs_to category' do
167
167
  content = <<-EOF
168
168
  <% if @user.category.present? %>
169
169
  <%= @user.category.name %>
@@ -173,7 +173,7 @@ module RailsBestPractices
173
173
  expect(runner.errors.size).to eq(0)
174
174
  end
175
175
 
176
- it "should not review has_one association" do
176
+ it 'should not review has_one association' do
177
177
  content = <<-EOF
178
178
  <% if @user.phone.present? %>
179
179
  <%= @user.phone.number %>
@@ -183,7 +183,7 @@ module RailsBestPractices
183
183
  expect(runner.errors.size).to eq(0)
184
184
  end
185
185
 
186
- it "should not review has_many association" do
186
+ it 'should not review has_many association' do
187
187
  content = <<-EOF
188
188
  <% if @user.projects.present? %>
189
189
  <%= @user.projects.first.name %>
@@ -194,7 +194,7 @@ module RailsBestPractices
194
194
  end
195
195
  end
196
196
 
197
- it "should not review for class method" do
197
+ it 'should not review for class method' do
198
198
  content = <<-EOF
199
199
  <% if User.name.present? %>
200
200
  <%= User.name %>
@@ -204,7 +204,7 @@ module RailsBestPractices
204
204
  expect(runner.errors.size).to eq(0)
205
205
  end
206
206
 
207
- it "should not review for non attribute call" do
207
+ it 'should not review for non attribute call' do
208
208
  content = <<-EOF
209
209
  if @user.login(false).nil?
210
210
  puts @user.login(false)
@@ -214,7 +214,7 @@ module RailsBestPractices
214
214
  expect(runner.errors.size).to eq(0)
215
215
  end
216
216
 
217
- it "should not raise error for common conditional statement" do
217
+ it 'should not raise error for common conditional statement' do
218
218
  content = <<-EOF
219
219
  if voteable.is_a? Answer
220
220
  puts voteable.title
@@ -223,7 +223,7 @@ module RailsBestPractices
223
223
  expect { runner.review('app/models/users_controller.rb', content) }.not_to raise_error
224
224
  end
225
225
 
226
- it "should not check ignored files" do
226
+ it 'should not check ignored files' do
227
227
  runner = Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
228
228
  reviews: UseQueryAttributeReview.new(ignored_files: /users\/show/))
229
229
  content = <<-EOF