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 Prepares
7
7
  describe SchemaPrepare do
8
- let(:runner) { Core::Runner.new(prepares: SchemaPrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
- it 'should parse model attributes' do
10
+ it 'parses model attributes' do
11
11
  content = <<-EOF
12
12
  ActiveRecord::Schema.define(version: 20110319172136) do
13
13
  create_table "posts", force: true do |t|
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe AddModelVirtualAttributeReview do
8
- let(:runner) { Core::Runner.new(reviews: AddModelVirtualAttributeReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should add model virtual attribute' do
10
+ it 'adds model virtual attribute' do
11
11
  content = <<-EOF
12
12
  class UsersController < ApplicationController
13
13
  def create
@@ -20,10 +20,12 @@ module RailsBestPractices
20
20
  EOF
21
21
  runner.review('app/controllers/users_controller.rb', content)
22
22
  expect(runner.errors.size).to eq(1)
23
- expect(runner.errors[0].to_s).to eq('app/controllers/users_controller.rb:2 - add model virtual attribute (for @user)')
23
+ expect(runner.errors[0].to_s).to eq(
24
+ 'app/controllers/users_controller.rb:2 - add model virtual attribute (for @user)'
25
+ )
24
26
  end
25
27
 
26
- it 'should add model virtual attribute with local assignment' do
28
+ it 'adds model virtual attribute with local assignment' do
27
29
  content = <<-EOF
28
30
  class UsersController < ApplicationController
29
31
  def create
@@ -36,10 +38,12 @@ module RailsBestPractices
36
38
  EOF
37
39
  runner.review('app/controllers/users_controller.rb', content)
38
40
  expect(runner.errors.size).to eq(1)
39
- expect(runner.errors[0].to_s).to eq('app/controllers/users_controller.rb:2 - add model virtual attribute (for user)')
41
+ expect(runner.errors[0].to_s).to eq(
42
+ 'app/controllers/users_controller.rb:2 - add model virtual attribute (for user)'
43
+ )
40
44
  end
41
45
 
42
- it 'should not add model virtual attribute with differen param' do
46
+ it 'does not add model virtual attribute with differen param' do
43
47
  content = <<-EOF
44
48
  class UsersController < ApplicationController
45
49
  def create
@@ -54,7 +58,7 @@ module RailsBestPractices
54
58
  expect(runner.errors.size).to eq(0)
55
59
  end
56
60
 
57
- it 'should not add model virtual attribute with read' do
61
+ it 'does not add model virtual attribute with read' do
58
62
  content = <<-EOF
59
63
  class UsersController < ApplicationController
60
64
  def show
@@ -70,7 +74,7 @@ module RailsBestPractices
70
74
  expect(runner.errors.size).to eq(0)
71
75
  end
72
76
 
73
- it 'should add model virtual attribute with two dimension params' do
77
+ it 'adds model virtual attribute with two dimension params' do
74
78
  content = <<-EOF
75
79
  class UsersController < ApplicationController
76
80
  def create
@@ -83,10 +87,12 @@ module RailsBestPractices
83
87
  EOF
84
88
  runner.review('app/controllers/users_controller.rb', content)
85
89
  expect(runner.errors.size).to eq(1)
86
- expect(runner.errors[0].to_s).to eq('app/controllers/users_controller.rb:2 - add model virtual attribute (for @user)')
90
+ expect(runner.errors[0].to_s).to eq(
91
+ 'app/controllers/users_controller.rb:2 - add model virtual attribute (for @user)'
92
+ )
87
93
  end
88
94
 
89
- it 'should no add model virtual attribute with two dimension params' do
95
+ it 'noes add model virtual attribute with two dimension params' do
90
96
  content = <<-EOF
91
97
  class UsersController < ApplicationController
92
98
  def create
@@ -101,8 +107,8 @@ module RailsBestPractices
101
107
  expect(runner.errors.size).to eq(0)
102
108
  end
103
109
 
104
- it 'should not check ignored files' do
105
- runner = Core::Runner.new(reviews: AddModelVirtualAttributeReview.new(ignored_files: /user/))
110
+ it 'does not check ignored files' do
111
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /user/))
106
112
  content = <<-EOF
107
113
  class UsersController < ApplicationController
108
114
  def create
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe AlwaysAddDbIndexReview do
8
- let(:runner) { Core::Runner.new(reviews: AlwaysAddDbIndexReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should always add db index' do
10
+ it 'alwayses add db index' do
11
11
  content = <<-EOF
12
12
  ActiveRecord::Schema.define(version: 20100603080629) do
13
13
  create_table "comments", force: true do |t|
@@ -28,7 +28,7 @@ module RailsBestPractices
28
28
  expect(runner.errors[1].to_s).to eq('db/schema.rb:2 - always add db index (comments => [user_id])')
29
29
  end
30
30
 
31
- it 'should always add db index with polymorphic foreign key' do
31
+ it 'alwayses add db index with polymorphic foreign key' do
32
32
  content = <<-EOF
33
33
  ActiveRecord::Schema.define(version: 20100603080629) do
34
34
  create_table "versions", force: true do |t|
@@ -41,10 +41,12 @@ module RailsBestPractices
41
41
  runner.review('db/schema.rb', content)
42
42
  runner.after_review
43
43
  expect(runner.errors.size).to eq(1)
44
- expect(runner.errors[0].to_s).to eq('db/schema.rb:2 - always add db index (versions => [versioned_id, versioned_type])')
44
+ expect(runner.errors[0].to_s).to eq(
45
+ 'db/schema.rb:2 - always add db index (versions => [versioned_id, versioned_type])'
46
+ )
45
47
  end
46
48
 
47
- it 'should always add db index with polymorphic foreign key and _type is defined before _id' do
49
+ it 'alwayses add db index with polymorphic foreign key and _type is defined before _id' do
48
50
  content = <<-EOF
49
51
  ActiveRecord::Schema.define(version: 20100603080629) do
50
52
  create_table "versions", force: true do |t|
@@ -57,10 +59,12 @@ module RailsBestPractices
57
59
  runner.review('db/schema.rb', content)
58
60
  runner.after_review
59
61
  expect(runner.errors.size).to eq(1)
60
- expect(runner.errors[0].to_s).to eq('db/schema.rb:2 - always add db index (versions => [versioned_id, versioned_type])')
62
+ expect(runner.errors[0].to_s).to eq(
63
+ 'db/schema.rb:2 - always add db index (versions => [versioned_id, versioned_type])'
64
+ )
61
65
  end
62
66
 
63
- it 'should always add db index with single index, but without polymorphic foreign key' do
67
+ it 'alwayses add db index with single index, but without polymorphic foreign key' do
64
68
  content = <<-EOF
65
69
  ActiveRecord::Schema.define(version: 20100603080629) do
66
70
  create_table "taggings", force: true do |t|
@@ -77,10 +81,12 @@ module RailsBestPractices
77
81
  runner.review('db/schema.rb', content)
78
82
  runner.after_review
79
83
  expect(runner.errors.size).to eq(1)
80
- expect(runner.errors[0].to_s).to eq('db/schema.rb:2 - always add db index (taggings => [taggable_id, taggable_type])')
84
+ expect(runner.errors[0].to_s).to eq(
85
+ 'db/schema.rb:2 - always add db index (taggings => [taggable_id, taggable_type])'
86
+ )
81
87
  end
82
88
 
83
- it 'should always add db index with polymorphic foreign key, but without single index' do
89
+ it 'alwayses add db index with polymorphic foreign key, but without single index' do
84
90
  content = <<-EOF
85
91
  ActiveRecord::Schema.define(version: 20100603080629) do
86
92
  create_table "taggings", force: true do |t|
@@ -100,7 +106,7 @@ module RailsBestPractices
100
106
  expect(runner.errors[0].to_s).to eq('db/schema.rb:2 - always add db index (taggings => [tag_id])')
101
107
  end
102
108
 
103
- it 'should always add db index only _id without non related _type column' do
109
+ it 'alwayses add db index only _id without non related _type column' do
104
110
  content = <<-EOF
105
111
  ActiveRecord::Schema.define(version: 20100603080629) do
106
112
  create_table "websites", force: true do |t|
@@ -119,7 +125,7 @@ module RailsBestPractices
119
125
  expect(runner.errors[0].to_s).to eq('db/schema.rb:2 - always add db index (websites => [user_id])')
120
126
  end
121
127
 
122
- it 'should not always add db index with column has no id' do
128
+ it 'does not always add db index with column has no id' do
123
129
  content = <<-EOF
124
130
  ActiveRecord::Schema.define(version: 20100603080629) do
125
131
  create_table "comments", force: true do |t|
@@ -133,7 +139,7 @@ module RailsBestPractices
133
139
  expect(runner.errors.size).to eq(0)
134
140
  end
135
141
 
136
- it 'should not always add db index with add_index' do
142
+ it 'does not always add db index with add_index' do
137
143
  content = <<-EOF
138
144
  ActiveRecord::Schema.define(version: 20100603080629) do
139
145
  create_table "comments", force: true do |t|
@@ -155,7 +161,7 @@ module RailsBestPractices
155
161
  expect(runner.errors.size).to eq(0)
156
162
  end
157
163
 
158
- it 'should not always add db index with t.index' do
164
+ it 'does not always add db index with t.index' do
159
165
  # e.g. schema_plus creates indices like this https://github.com/lomba/schema_plus
160
166
  content = <<-EOF
161
167
  ActiveRecord::Schema.define(version: 20100603080629) do
@@ -173,7 +179,7 @@ module RailsBestPractices
173
179
  expect(runner.errors.size).to eq(0)
174
180
  end
175
181
 
176
- it 'should not always add db index with only _type column' do
182
+ it 'does not always add db index with only _type column' do
177
183
  content = <<-EOF
178
184
  ActiveRecord::Schema.define(version: 20100603080629) do
179
185
  create_table "versions", force: true do |t|
@@ -186,7 +192,7 @@ module RailsBestPractices
186
192
  expect(runner.errors.size).to eq(0)
187
193
  end
188
194
 
189
- it 'should not always add db index with multi-column index' do
195
+ it 'does not always add db index with multi-column index' do
190
196
  content = <<-EOF
191
197
  ActiveRecord::Schema.define(version: 20100603080629) do
192
198
  create_table "versions", force: true do |t|
@@ -203,7 +209,7 @@ module RailsBestPractices
203
209
  expect(runner.errors.size).to eq(0)
204
210
  end
205
211
 
206
- it 'should not always add db index if there is an index contains more columns' do
212
+ it 'does not always add db index if there is an index contains more columns' do
207
213
  content = <<-EOF
208
214
  ActiveRecord::Schema.define(version: 20100603080629) do
209
215
  create_table "taggings", force: true do |t|
@@ -220,7 +226,7 @@ module RailsBestPractices
220
226
  expect(runner.errors.size).to eq(0)
221
227
  end
222
228
 
223
- it 'should not always add db index if two indexes for polymorphic association' do
229
+ it 'does not always add db index if two indexes for polymorphic association' do
224
230
  content = <<-EOF
225
231
  ActiveRecord::Schema.define(version: 20100603080629) do
226
232
  create_table "taggings", force: true do |t|
@@ -238,7 +244,7 @@ module RailsBestPractices
238
244
  expect(runner.errors.size).to eq(0)
239
245
  end
240
246
 
241
- it 'should not always add db index if table does not exist' do
247
+ it 'does not always add db index if table does not exist' do
242
248
  content = <<-EOF
243
249
  ActiveRecord::Schema.define(version: 20100603080629) do
244
250
  create_table "comments", force: true do |t|
@@ -251,7 +257,7 @@ module RailsBestPractices
251
257
  expect(runner.errors.size).to eq(0)
252
258
  end
253
259
 
254
- it 'should always add db index if association_name is different to foreign_key' do
260
+ it 'alwayses add db index if association_name is different to foreign_key' do
255
261
  content = <<-EOF
256
262
  class Comment < ActiveRecord::Base
257
263
  belongs_to :commentor, class_name: "User"
@@ -278,8 +284,8 @@ module RailsBestPractices
278
284
  expect(runner.errors[0].to_s).to eq('db/schema.rb:2 - always add db index (comments => [commentor_id])')
279
285
  end
280
286
 
281
- it 'should not check ignored files' do
282
- runner = Core::Runner.new(reviews: AlwaysAddDbIndexReview.new(ignored_files: /db\/schema/))
287
+ it 'does not check ignored files' do
288
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{db/schema}))
283
289
  content = <<-EOF
284
290
  ActiveRecord::Schema.define(version: 20100603080629) do
285
291
  create_table "comments", force: true do |t|
@@ -298,7 +304,7 @@ module RailsBestPractices
298
304
  expect(runner.errors.size).to eq(0)
299
305
  end
300
306
 
301
- it 'should detect index option in column creation' do
307
+ it 'detects index option in column creation' do
302
308
  content = <<-EOF
303
309
  ActiveRecord::Schema.define(version: 20100603080629) do
304
310
  create_table "comments", force: true do |t|
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe CheckDestroyReturnValueReview do
8
- let(:runner) { Core::Runner.new(reviews: CheckDestroyReturnValueReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
10
  describe 'check_destroy_return_value' do
11
- it 'should warn you if you fail to check the destroy return value' do
11
+ it 'warns you if you fail to check the destroy return value' do
12
12
  content = <<-EOF
13
13
  def my_method
14
14
  post = Posts.create do |p|
@@ -19,10 +19,12 @@ module RailsBestPractices
19
19
  EOF
20
20
  runner.review('app/helpers/posts_helper.rb', content)
21
21
  expect(runner.errors.size).to eq(1)
22
- expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:5 - check 'destroy' return value or use 'destroy!'")
22
+ expect(runner.errors[0].to_s).to eq(
23
+ "app/helpers/posts_helper.rb:5 - check 'destroy' return value or use 'destroy!'"
24
+ )
23
25
  end
24
26
 
25
- it 'should allow destroy return value if assigned to a var' do
27
+ it 'allows destroy return value if assigned to a var' do
26
28
  content = <<-EOF
27
29
  def my_method
28
30
  post = Posts.create do |p|
@@ -35,7 +37,7 @@ module RailsBestPractices
35
37
  expect(runner.errors.size).to eq(0)
36
38
  end
37
39
 
38
- it 'should allow destroy return value used in if' do
40
+ it 'allows destroy return value used in if' do
39
41
  content = <<-EOF
40
42
  def my_method
41
43
  post = Posts.create do |p|
@@ -52,7 +54,7 @@ module RailsBestPractices
52
54
  expect(runner.errors.size).to eq(0)
53
55
  end
54
56
 
55
- it 'should allow destroy return value used in elsif' do
57
+ it 'allows destroy return value used in elsif' do
56
58
  content = <<-EOF
57
59
  def my_method
58
60
  post = Posts.create do |p|
@@ -71,7 +73,7 @@ module RailsBestPractices
71
73
  expect(runner.errors.size).to eq(0)
72
74
  end
73
75
 
74
- it 'should allow destroy return value used in unless' do
76
+ it 'allows destroy return value used in unless' do
75
77
  content = <<-EOF
76
78
  def my_method
77
79
  unless @post.destroy
@@ -83,7 +85,7 @@ module RailsBestPractices
83
85
  expect(runner.errors.size).to eq(0)
84
86
  end
85
87
 
86
- it 'should allow destroy return value used in if_mod' do
88
+ it 'allows destroy return value used in if_mod' do
87
89
  content = <<-EOF
88
90
  def my_method
89
91
  post = Posts.create do |p|
@@ -96,7 +98,7 @@ module RailsBestPractices
96
98
  expect(runner.errors.size).to eq(0)
97
99
  end
98
100
 
99
- it 'should allow destroy return value used in unless_mod' do
101
+ it 'allows destroy return value used in unless_mod' do
100
102
  content = <<-EOF
101
103
  def my_method
102
104
  post = Posts.create do |p|
@@ -109,7 +111,7 @@ module RailsBestPractices
109
111
  expect(runner.errors.size).to eq(0)
110
112
  end
111
113
 
112
- it 'should allow destroy return value used in unless with &&' do
114
+ it 'allows destroy return value used in unless with &&' do
113
115
  content = <<-EOF
114
116
  def my_method
115
117
  unless some_method(1) && other_method(2) && @post.destroy
@@ -121,7 +123,7 @@ module RailsBestPractices
121
123
  expect(runner.errors.size).to eq(0)
122
124
  end
123
125
 
124
- it 'should allow destroy!' do
126
+ it 'allows destroy!' do
125
127
  content = <<-EOF
126
128
  def my_method
127
129
  post = Posts.create do |p|
@@ -135,8 +137,8 @@ module RailsBestPractices
135
137
  end
136
138
  end
137
139
 
138
- it 'should not check ignored files' do
139
- runner = Core::Runner.new(reviews: CheckDestroyReturnValueReview.new(ignored_files: /helpers/))
140
+ it 'does not check ignored files' do
141
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /helpers/))
140
142
  content = <<-EOF
141
143
  def my_method
142
144
  post = Posts.create do |p|
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe CheckSaveReturnValueReview do
8
- let(:runner) { Core::Runner.new(reviews: CheckSaveReturnValueReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
10
  describe 'check_save_return_value' do
11
- it 'should warn you if you fail to check save return value' do
11
+ it 'warns you if you fail to check save return value' do
12
12
  content = <<-EOF
13
13
  def my_method
14
14
  post = Posts.new do |p|
@@ -19,10 +19,12 @@ module RailsBestPractices
19
19
  EOF
20
20
  runner.review('app/helpers/posts_helper.rb', content)
21
21
  expect(runner.errors.size).to eq(1)
22
- expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:5 - check 'save' return value or use 'save!'")
22
+ expect(runner.errors[0].to_s).to eq(
23
+ "app/helpers/posts_helper.rb:5 - check 'save' return value or use 'save!'"
24
+ )
23
25
  end
24
26
 
25
- it 'should allow save return value assigned to var' do
27
+ it 'allows save return value assigned to var' do
26
28
  content = <<-EOF
27
29
  def my_method
28
30
  post = Posts.new do |p|
@@ -35,7 +37,7 @@ module RailsBestPractices
35
37
  expect(runner.errors.size).to eq(0)
36
38
  end
37
39
 
38
- it 'should allow save return value used in if' do
40
+ it 'allows save return value used in if' do
39
41
  content = <<-EOF
40
42
  def my_method
41
43
  post = Posts.new do |p|
@@ -52,7 +54,7 @@ module RailsBestPractices
52
54
  expect(runner.errors.size).to eq(0)
53
55
  end
54
56
 
55
- it 'should allow save return value used in elsif' do
57
+ it 'allows save return value used in elsif' do
56
58
  content = <<-EOF
57
59
  def my_method
58
60
  post = Posts.new do |p|
@@ -71,7 +73,7 @@ module RailsBestPractices
71
73
  expect(runner.errors.size).to eq(0)
72
74
  end
73
75
 
74
- it 'should allow save return value used in unless' do
76
+ it 'allows save return value used in unless' do
75
77
  content = <<-EOF
76
78
  def my_method
77
79
  unless @post.save
@@ -83,7 +85,7 @@ module RailsBestPractices
83
85
  expect(runner.errors.size).to eq(0)
84
86
  end
85
87
 
86
- it 'should allow save return value used in if_mod' do
88
+ it 'allows save return value used in if_mod' do
87
89
  content = <<-EOF
88
90
  def my_method
89
91
  post = Posts.new do |p|
@@ -96,7 +98,7 @@ module RailsBestPractices
96
98
  expect(runner.errors.size).to eq(0)
97
99
  end
98
100
 
99
- it 'should allow save return value used in unless_mod' do
101
+ it 'allows save return value used in unless_mod' do
100
102
  content = <<-EOF
101
103
  def my_method
102
104
  post = Posts.new do |p|
@@ -109,7 +111,7 @@ module RailsBestPractices
109
111
  expect(runner.errors.size).to eq(0)
110
112
  end
111
113
 
112
- it 'should allow save return value used in unless with &&' do
114
+ it 'allows save return value used in unless with &&' do
113
115
  content = <<-EOF
114
116
  def my_method
115
117
  unless some_method(1) && other_method(2) && @post.save
@@ -121,7 +123,7 @@ module RailsBestPractices
121
123
  expect(runner.errors.size).to eq(0)
122
124
  end
123
125
 
124
- it 'should allow save!' do
126
+ it 'allows save!' do
125
127
  content = <<-EOF
126
128
  def my_method
127
129
  post = Posts.new do |p|
@@ -134,7 +136,7 @@ module RailsBestPractices
134
136
  expect(runner.errors.size).to eq(0)
135
137
  end
136
138
 
137
- it 'should warn you if you fail to check update_attributes return value' do
139
+ it 'warns you if you fail to check update_attributes return value' do
138
140
  content = <<-EOF
139
141
  def my_method
140
142
  @post.update_attributes params
@@ -142,10 +144,12 @@ module RailsBestPractices
142
144
  EOF
143
145
  runner.review('app/helpers/posts_helper.rb', content)
144
146
  expect(runner.errors.size).to eq(1)
145
- expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:2 - check 'update_attributes' return value or use 'update_attributes!'")
147
+ expect(runner.errors[0].to_s).to eq(
148
+ "app/helpers/posts_helper.rb:2 - check 'update_attributes' return value or use 'update_attributes!'"
149
+ )
146
150
  end
147
151
 
148
- it 'should allow update_attributes if return value is checked' do
152
+ it 'allows update_attributes if return value is checked' do
149
153
  content = <<-EOF
150
154
  def my_method
151
155
  @post.update_attributes(params) or raise "failed to save"
@@ -176,10 +180,12 @@ module RailsBestPractices
176
180
  EOF
177
181
  runner.review('app/controllers/posts_controller.rb', content)
178
182
  expect(runner.errors.size).to eq(1)
179
- expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:12 - check 'update_attributes' return value or use 'update_attributes!'")
183
+ expect(runner.errors[0].to_s).to eq(
184
+ "app/controllers/posts_controller.rb:12 - check 'update_attributes' return value or use 'update_attributes!'"
185
+ )
180
186
  end
181
187
 
182
- it 'should warn you if you use create which is always unsafe' do
188
+ it 'warns you if you use create which is always unsafe' do
183
189
  content = <<-EOF
184
190
  class Post < ActiveRecord::Base
185
191
  end
@@ -195,10 +201,12 @@ module RailsBestPractices
195
201
  EOF
196
202
  runner.review('app/helpers/posts_helper.rb', content)
197
203
  expect(runner.errors.size).to eq(1)
198
- expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:2 - use 'create!' instead of 'create' as the latter may not always save")
204
+ expect(runner.errors[0].to_s).to eq(
205
+ "app/helpers/posts_helper.rb:2 - use 'create!' instead of 'create' as the latter may not always save"
206
+ )
199
207
  end
200
208
 
201
- it 'should warn you if you use create with a block which is always unsafe' do
209
+ it 'warns you if you use create with a block which is always unsafe' do
202
210
  content = <<-EOF
203
211
  module Blog
204
212
  class Post < ActiveRecord::Base
@@ -223,7 +231,9 @@ module RailsBestPractices
223
231
  EOF
224
232
  runner.review('app/helpers/blog/posts_helper.rb', content)
225
233
  expect(runner.errors.size).to eq(1)
226
- expect(runner.errors[0].to_s).to eq("app/helpers/blog/posts_helper.rb:4 - use 'create!' instead of 'create' as the latter may not always save")
234
+ expect(runner.errors[0].to_s).to eq(
235
+ "app/helpers/blog/posts_helper.rb:4 - use 'create!' instead of 'create' as the latter may not always save"
236
+ )
227
237
  end
228
238
 
229
239
  it 'allows create called on non-model classes' do
@@ -241,8 +251,8 @@ module RailsBestPractices
241
251
  end
242
252
  end
243
253
 
244
- it 'should not check ignored files' do
245
- runner = Core::Runner.new(reviews: CheckSaveReturnValueReview.new(ignored_files: /helpers/))
254
+ it 'does not check ignored files' do
255
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /helpers/))
246
256
  content = <<-EOF
247
257
  def my_method
248
258
  post = Posts.new do |p|