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,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe RestrictAutoGeneratedRoutesReview do
8
- let(:runner) { Core::Runner.new(prepares: Prepares::ControllerPrepare.new, reviews: RestrictAutoGeneratedRoutesReview.new) }
8
+ let(:runner) { Core::Runner.new(prepares: Prepares::ControllerPrepare.new, reviews: described_class.new) }
9
9
 
10
10
  describe 'resources' do
11
- before :each do
11
+ before do
12
12
  content = <<-EOF
13
13
  class PostsController < ApplicationController
14
14
  def show; end
@@ -22,7 +22,7 @@ module RailsBestPractices
22
22
  runner.prepare('app/controllers/posts_controller.rb', content)
23
23
  end
24
24
 
25
- it 'should restrict auto-generated routes' do
25
+ it 'restricts auto-generated routes' do
26
26
  content = <<-EOF
27
27
  RailsBestPracticesCom::Application.routes.draw do
28
28
  resources :posts
@@ -30,10 +30,12 @@ module RailsBestPractices
30
30
  EOF
31
31
  runner.review('config/routes.rb', content)
32
32
  expect(runner.errors.size).to eq(1)
33
- expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])')
33
+ expect(runner.errors[0].to_s).to eq(
34
+ 'config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])'
35
+ )
34
36
  end
35
37
 
36
- it 'should not restrict auto-generated routes with only' do
38
+ it 'does not restrict auto-generated routes with only' do
37
39
  content = <<-EOF
38
40
  RailsBestPracticesCom::Application.routes.draw do
39
41
  resources :posts, only: %w(show new create edit update destroy)
@@ -43,7 +45,7 @@ module RailsBestPractices
43
45
  expect(runner.errors.size).to eq(0)
44
46
  end
45
47
 
46
- it 'should not restrict auto-generated routes with except' do
48
+ it 'does not restrict auto-generated routes with except' do
47
49
  content = <<-EOF
48
50
  RailsBestPracticesCom::Application.routes.draw do
49
51
  resources :posts, except: :index
@@ -54,7 +56,7 @@ module RailsBestPractices
54
56
  end
55
57
 
56
58
  describe 'specify a controller' do
57
- it 'should restrict auto-generated routes' do
59
+ it 'restricts auto-generated routes' do
58
60
  content = <<-EOF
59
61
  RailsBestPracticesCom::Application.routes.draw do
60
62
  resources :articles, controller: "posts"
@@ -62,7 +64,9 @@ module RailsBestPractices
62
64
  EOF
63
65
  runner.review('config/routes.rb', content)
64
66
  expect(runner.errors.size).to eq(1)
65
- expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes articles (except: [:index])')
67
+ expect(runner.errors[0].to_s).to eq(
68
+ 'config/routes.rb:2 - restrict auto-generated routes articles (except: [:index])'
69
+ )
66
70
  end
67
71
  end
68
72
 
@@ -81,7 +85,7 @@ module RailsBestPractices
81
85
  runner.prepare('app/controllers/admin/comments_controller.rb', content)
82
86
  end
83
87
 
84
- it 'should restrict auto-generated routes' do
88
+ it 'restricts auto-generated routes' do
85
89
  content = <<-EOF
86
90
  RailsBestPracticesCom::Application.routes.draw do
87
91
  namespace :admin do
@@ -91,10 +95,12 @@ module RailsBestPractices
91
95
  EOF
92
96
  runner.review('config/routes.rb', content)
93
97
  expect(runner.errors.size).to eq(1)
94
- expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])')
98
+ expect(runner.errors[0].to_s).to eq(
99
+ 'config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])'
100
+ )
95
101
  end
96
102
 
97
- it 'should restrict auto-generated routes with scope :module' do
103
+ it 'restricts auto-generated routes with scope :module' do
98
104
  content = <<-EOF
99
105
  RailsBestPracticesCom::Application.routes.draw do
100
106
  scope module: :admin do
@@ -104,10 +110,12 @@ module RailsBestPractices
104
110
  EOF
105
111
  runner.review('config/routes.rb', content)
106
112
  expect(runner.errors.size).to eq(1)
107
- expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])')
113
+ expect(runner.errors[0].to_s).to eq(
114
+ 'config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])'
115
+ )
108
116
  end
109
117
 
110
- it 'should restrict auto-generated routes with resources :module' do
118
+ it 'restricts auto-generated routes with resources :module' do
111
119
  content = <<-EOF
112
120
  RailsBestPracticesCom::Application.routes.draw do
113
121
  resources :comments, module: :admin
@@ -115,12 +123,14 @@ module RailsBestPractices
115
123
  EOF
116
124
  runner.review('config/routes.rb', content)
117
125
  expect(runner.errors.size).to eq(1)
118
- expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes admin/comments (except: [:index])')
126
+ expect(runner.errors[0].to_s).to eq(
127
+ 'config/routes.rb:2 - restrict auto-generated routes admin/comments (except: [:index])'
128
+ )
119
129
  end
120
130
  end
121
131
 
122
132
  describe 'nested routes' do
123
- before :each do
133
+ before do
124
134
  content = <<-EOF
125
135
  class CommentsController < ApplicationController
126
136
  def index; end
@@ -135,7 +145,7 @@ module RailsBestPractices
135
145
  runner.prepare('app/controllers/comments_controller.rb', content)
136
146
  end
137
147
 
138
- it 'should restrict auto-generated routes' do
148
+ it 'restricts auto-generated routes' do
139
149
  content = <<-EOF
140
150
  RailsBestPracticesCom::Application.routes.draw do
141
151
  resources :posts do
@@ -145,10 +155,12 @@ module RailsBestPractices
145
155
  EOF
146
156
  runner.review('config/routes.rb', content)
147
157
  expect(runner.errors.size).to eq(1)
148
- expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])')
158
+ expect(runner.errors[0].to_s).to eq(
159
+ 'config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])'
160
+ )
149
161
  end
150
162
 
151
- it 'should not restrict auto-generated routes with only' do
163
+ it 'does not restrict auto-generated routes with only' do
152
164
  content = <<-EOF
153
165
  RailsBestPracticesCom::Application.routes.draw do
154
166
  resources :posts, only: %w(show new create edit update destroy) do
@@ -160,7 +172,7 @@ module RailsBestPractices
160
172
  expect(runner.errors.size).to eq(0)
161
173
  end
162
174
 
163
- it 'should not restrict auto-generated routes with except' do
175
+ it 'does not restrict auto-generated routes with except' do
164
176
  content = <<-EOF
165
177
  RailsBestPracticesCom::Application.routes.draw do
166
178
  resources :posts, except: :index do
@@ -175,7 +187,7 @@ module RailsBestPractices
175
187
  end
176
188
 
177
189
  describe 'resource' do
178
- before :each do
190
+ before do
179
191
  content = <<-EOF
180
192
  class AccountsController < ApplicationController
181
193
  def show; end
@@ -188,7 +200,7 @@ module RailsBestPractices
188
200
  runner.prepare('app/controllers/accounts_controller.rb', content)
189
201
  end
190
202
 
191
- it 'should restrict auto-generated routes' do
203
+ it 'restricts auto-generated routes' do
192
204
  content = <<-EOF
193
205
  ActionController::Routing::Routes.draw do |map|
194
206
  map.resource :account
@@ -196,10 +208,12 @@ module RailsBestPractices
196
208
  EOF
197
209
  runner.review('config/routes.rb', content)
198
210
  expect(runner.errors.size).to eq(1)
199
- expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])')
211
+ expect(runner.errors[0].to_s).to eq(
212
+ 'config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])'
213
+ )
200
214
  end
201
215
 
202
- it 'should not restrict auto-generated routes with only' do
216
+ it 'does not restrict auto-generated routes with only' do
203
217
  content = <<-EOF
204
218
  ActionController::Routing::Routes.draw do |map|
205
219
  map.resource :account, only: %w(show new create edit update)
@@ -209,7 +223,7 @@ module RailsBestPractices
209
223
  expect(runner.errors.size).to eq(0)
210
224
  end
211
225
 
212
- it 'should not restrict auto-generated routes with except' do
226
+ it 'does not restrict auto-generated routes with except' do
213
227
  content = <<-EOF
214
228
  ActionController::Routing::Routes.draw do |map|
215
229
  map.resource :account, except: :destroy
@@ -219,9 +233,12 @@ module RailsBestPractices
219
233
  expect(runner.errors.size).to eq(0)
220
234
  end
221
235
 
222
- it 'should not check ignored files' do
223
- runner = Core::Runner.new(prepares: Prepares::ControllerPrepare.new,
224
- reviews: RestrictAutoGeneratedRoutesReview.new(ignored_files: /config\/routes\.rb/))
236
+ it 'does not check ignored files' do
237
+ runner =
238
+ Core::Runner.new(
239
+ prepares: Prepares::ControllerPrepare.new,
240
+ reviews: described_class.new(ignored_files: %r{config/routes\.rb})
241
+ )
225
242
 
226
243
  content = <<-EOF
227
244
  ActionController::Routing::Routes.draw do |map|
@@ -234,7 +251,11 @@ module RailsBestPractices
234
251
  end
235
252
 
236
253
  context 'api_only = true' do
237
- let(:runner) { Core::Runner.new(prepares: [Prepares::ConfigPrepare.new, Prepares::ControllerPrepare.new], reviews: RestrictAutoGeneratedRoutesReview.new) }
254
+ let(:runner) do
255
+ Core::Runner.new(
256
+ prepares: [Prepares::ConfigPrepare.new, Prepares::ControllerPrepare.new], reviews: described_class.new
257
+ )
258
+ end
238
259
 
239
260
  before do
240
261
  content = <<-EOF
@@ -256,7 +277,7 @@ module RailsBestPractices
256
277
  runner.prepare('app/controllers/posts_controller.rb', content)
257
278
  end
258
279
 
259
- it 'should restrict auto-generated routes' do
280
+ it 'restricts auto-generated routes' do
260
281
  content = <<-EOF
261
282
  RailsBestPracticesCom::Application.routes.draw do
262
283
  resources :posts
@@ -264,10 +285,12 @@ module RailsBestPractices
264
285
  EOF
265
286
  runner.review('config/routes.rb', content)
266
287
  expect(runner.errors.size).to eq(1)
267
- expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])')
288
+ expect(runner.errors[0].to_s).to eq(
289
+ 'config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])'
290
+ )
268
291
  end
269
292
 
270
- it 'should not restrict auto-generated routes with only' do
293
+ it 'does not restrict auto-generated routes with only' do
271
294
  content = <<-EOF
272
295
  RailsBestPracticesCom::Application.routes.draw do
273
296
  resources :posts, only: %w(show create update destroy)
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe SimplifyRenderInControllersReview do
8
- let(:runner) { Core::Runner.new(reviews: SimplifyRenderInControllersReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should simplify render action view' do
10
+ it 'simplifies render action view' do
11
11
  content = <<-EOF
12
12
  def edit
13
13
  render action: :edit
@@ -18,7 +18,7 @@ module RailsBestPractices
18
18
  expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - simplify render in controllers')
19
19
  end
20
20
 
21
- it "should simplify render actions's template" do
21
+ it "simplifies render actions's template" do
22
22
  content = <<-EOF
23
23
  def edit
24
24
  render template: 'books/edit'
@@ -29,7 +29,7 @@ module RailsBestPractices
29
29
  expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - simplify render in controllers')
30
30
  end
31
31
 
32
- it 'should simplify render an arbitrary file' do
32
+ it 'simplifies render an arbitrary file' do
33
33
  content = <<-EOF
34
34
  def edit
35
35
  render file: '/path/to/rails/app/views/books/edit'
@@ -40,7 +40,7 @@ module RailsBestPractices
40
40
  expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - simplify render in controllers')
41
41
  end
42
42
 
43
- it 'should not simplify render action view' do
43
+ it 'does not simplify render action view' do
44
44
  content = <<-EOF
45
45
  render :edit
46
46
  EOF
@@ -48,7 +48,7 @@ module RailsBestPractices
48
48
  expect(runner.errors.size).to eq(0)
49
49
  end
50
50
 
51
- it "should not simplify render actions's template" do
51
+ it "does not simplify render actions's template" do
52
52
  content = <<-EOF
53
53
  def edit
54
54
  render 'books/edit'
@@ -58,7 +58,7 @@ module RailsBestPractices
58
58
  expect(runner.errors.size).to eq(0)
59
59
  end
60
60
 
61
- it 'should not simplify render an arbitrary file' do
61
+ it 'does not simplify render an arbitrary file' do
62
62
  content = <<-EOF
63
63
  def edit
64
64
  render '/path/to/rails/app/views/books/edit'
@@ -68,8 +68,8 @@ module RailsBestPractices
68
68
  expect(runner.errors.size).to eq(0)
69
69
  end
70
70
 
71
- it 'should not check ignored files' do
72
- runner = Core::Runner.new(reviews: SimplifyRenderInControllersReview.new(ignored_files: /posts_controller/))
71
+ it 'does not check ignored files' do
72
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_controller/))
73
73
  content = <<-EOF
74
74
  def edit
75
75
  render action: :edit
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe SimplifyRenderInViewsReview do
8
- let(:runner) { Core::Runner.new(reviews: SimplifyRenderInViewsReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should simplify render simple partial' do
10
+ it 'simplifies render simple partial' do
11
11
  content = <<-EOF
12
12
  <%= render partial: 'sidebar' %>
13
13
  EOF
@@ -16,7 +16,7 @@ module RailsBestPractices
16
16
  expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
17
17
  end
18
18
 
19
- it 'should simplify render partial with object' do
19
+ it 'simplifies render partial with object' do
20
20
  content = <<-EOF
21
21
  <%= render partial: 'post', object: @post %>
22
22
  EOF
@@ -25,7 +25,7 @@ module RailsBestPractices
25
25
  expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
26
26
  end
27
27
 
28
- it 'should simplify render partial with collection' do
28
+ it 'simplifies render partial with collection' do
29
29
  content = <<-EOF
30
30
  <%= render partial: 'posts', collection: @posts %>
31
31
  EOF
@@ -34,7 +34,7 @@ module RailsBestPractices
34
34
  expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
35
35
  end
36
36
 
37
- it 'should simplify render partial with local variables' do
37
+ it 'simplifies render partial with local variables' do
38
38
  content = <<-EOF
39
39
  <%= render partial: 'comment', locals: { parent: post } %>
40
40
  EOF
@@ -43,7 +43,7 @@ module RailsBestPractices
43
43
  expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
44
44
  end
45
45
 
46
- it 'should not simplify render simple partial' do
46
+ it 'does not simplify render simple partial' do
47
47
  content = <<-EOF
48
48
  <%= render 'sidebar' %>
49
49
  <%= render 'shared/sidebar' %>
@@ -52,7 +52,7 @@ module RailsBestPractices
52
52
  expect(runner.errors.size).to eq(0)
53
53
  end
54
54
 
55
- it 'should not simplify render partial with object' do
55
+ it 'does not simplify render partial with object' do
56
56
  content = <<-EOF
57
57
  <%= render @post %>
58
58
  EOF
@@ -60,7 +60,7 @@ module RailsBestPractices
60
60
  expect(runner.errors.size).to eq(0)
61
61
  end
62
62
 
63
- it 'should not simplify render partial with collection' do
63
+ it 'does not simplify render partial with collection' do
64
64
  content = <<-EOF
65
65
  <%= render @posts %>
66
66
  EOF
@@ -68,7 +68,7 @@ module RailsBestPractices
68
68
  expect(runner.errors.size).to eq(0)
69
69
  end
70
70
 
71
- it 'should not simplify render partial with local variables' do
71
+ it 'does not simplify render partial with local variables' do
72
72
  content = <<-EOF
73
73
  <%= render 'comment', parent: post %>
74
74
  EOF
@@ -76,7 +76,7 @@ module RailsBestPractices
76
76
  expect(runner.errors.size).to eq(0)
77
77
  end
78
78
 
79
- it 'should not simplify render partial with complex partial' do
79
+ it 'does not simplify render partial with complex partial' do
80
80
  content = <<-EOF
81
81
  <%= render partial: 'shared/post', object: @post %>
82
82
  EOF
@@ -84,7 +84,7 @@ module RailsBestPractices
84
84
  expect(runner.errors.size).to eq(0)
85
85
  end
86
86
 
87
- it 'should not simplify render partial with layout option' do
87
+ it 'does not simplify render partial with layout option' do
88
88
  content = <<-EOF
89
89
  <%= render partial: 'post', layout: 'post' %>
90
90
  EOF
@@ -92,8 +92,8 @@ module RailsBestPractices
92
92
  expect(runner.errors.size).to eq(0)
93
93
  end
94
94
 
95
- it 'should not check ignored files' do
96
- runner = Core::Runner.new(reviews: SimplifyRenderInViewsReview.new(ignored_files: /views\/posts\/index/))
95
+ it 'does not check ignored files' do
96
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{views/posts/index}))
97
97
  content = <<-EOF
98
98
  <%= render partial: 'sidebar' %>
99
99
  EOF
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe UseBeforeFilterReview do
8
- let(:runner) { Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2)) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new(customize_count: 2)) }
9
9
 
10
- it 'should use before_filter' do
10
+ it 'uses before_filter' do
11
11
  content = <<-EOF
12
12
  class PostsController < ApplicationController
13
13
  def show
@@ -31,10 +31,12 @@ module RailsBestPractices
31
31
  EOF
32
32
  runner.review('app/controllers/posts_controller.rb', content)
33
33
  expect(runner.errors.size).to eq(1)
34
- expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2,6,10,15 - use before_filter for show,edit,update,destroy')
34
+ expect(runner.errors[0].to_s).to eq(
35
+ 'app/controllers/posts_controller.rb:2,6,10,15 - use before_filter for show,edit,update,destroy'
36
+ )
35
37
  end
36
38
 
37
- it 'should not use before_filter when equal to customize count' do
39
+ it 'does not use before_filter when equal to customize count' do
38
40
  content = <<-EOF
39
41
  class PostsController < ApplicationController
40
42
  def show
@@ -50,7 +52,7 @@ module RailsBestPractices
50
52
  expect(runner.errors.size).to eq(0)
51
53
  end
52
54
 
53
- it 'should not use before_filter' do
55
+ it 'does not use before_filter' do
54
56
  content = <<-EOF
55
57
  class PostsController < ApplicationController
56
58
  before_filter :find_post, only: [:show, :edit, :update, :destroy]
@@ -73,7 +75,7 @@ module RailsBestPractices
73
75
  expect(runner.errors.size).to eq(0)
74
76
  end
75
77
 
76
- it 'should not use before_filter by nil' do
78
+ it 'does not use before_filter by nil' do
77
79
  content = <<-EOF
78
80
  class PostsController < ApplicationController
79
81
  def show; end
@@ -86,7 +88,7 @@ module RailsBestPractices
86
88
  expect(runner.errors.size).to eq(0)
87
89
  end
88
90
 
89
- it 'should not use before_filter for protected/private methods' do
91
+ it 'does not use before_filter for protected/private methods' do
90
92
  content = <<-EOF
91
93
  class PostsController < ApplicationController
92
94
  protected
@@ -105,8 +107,8 @@ module RailsBestPractices
105
107
  expect(runner.errors.size).to eq(0)
106
108
  end
107
109
 
108
- it 'should not check ignored files' do
109
- runner = Core::Runner.new(reviews: UseBeforeFilterReview.new(customize_count: 2, ignored_files: /posts_controller/))
110
+ it 'does not check ignored files' do
111
+ runner = Core::Runner.new(reviews: described_class.new(customize_count: 2, ignored_files: /posts_controller/))
110
112
  content = <<-EOF
111
113
  class PostsController < ApplicationController
112
114
  def show