rails_best_practices 1.19.1 → 1.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Guardfile +1 -1
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/bin/rails_best_practices +2 -1
- data/lib/rails_best_practices.rb +2 -1
- data/lib/rails_best_practices/analyzer.rb +13 -12
- data/lib/rails_best_practices/colorize.rb +2 -0
- data/lib/rails_best_practices/command.rb +6 -5
- data/lib/rails_best_practices/core.rb +2 -1
- data/lib/rails_best_practices/core/check.rb +19 -17
- data/lib/rails_best_practices/core/checks_loader.rb +3 -2
- data/lib/rails_best_practices/core/configs.rb +2 -1
- data/lib/rails_best_practices/core/controllers.rb +4 -1
- data/lib/rails_best_practices/core/error.rb +3 -2
- data/lib/rails_best_practices/core/gems.rb +4 -3
- data/lib/rails_best_practices/core/helpers.rb +4 -1
- data/lib/rails_best_practices/core/klasses.rb +3 -2
- data/lib/rails_best_practices/core/mailers.rb +2 -1
- data/lib/rails_best_practices/core/methods.rb +9 -10
- data/lib/rails_best_practices/core/model_associations.rb +6 -5
- data/lib/rails_best_practices/core/model_attributes.rb +2 -1
- data/lib/rails_best_practices/core/models.rb +2 -1
- data/lib/rails_best_practices/core/modules.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +2 -1
- data/lib/rails_best_practices/core/runner.rb +7 -6
- data/lib/rails_best_practices/core_ext/erubis.rb +4 -5
- data/lib/rails_best_practices/lexicals.rb +2 -1
- data/lib/rails_best_practices/lexicals/long_line_check.rb +2 -1
- data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -1
- data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -1
- data/lib/rails_best_practices/prepares.rb +2 -1
- data/lib/rails_best_practices/prepares/config_prepare.rb +3 -2
- data/lib/rails_best_practices/prepares/controller_prepare.rb +9 -8
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/helper_prepare.rb +4 -3
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +3 -2
- data/lib/rails_best_practices/prepares/model_prepare.rb +12 -12
- data/lib/rails_best_practices/prepares/route_prepare.rb +8 -7
- data/lib/rails_best_practices/prepares/schema_prepare.rb +3 -2
- data/lib/rails_best_practices/reviews.rb +2 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +7 -4
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +8 -7
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +4 -3
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +5 -4
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -1
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -1
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +2 -1
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +3 -2
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -1
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +5 -4
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -1
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -1
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -2
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +4 -3
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -1
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -10
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +4 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +6 -5
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
- data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -1
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +8 -8
- data/lib/rails_best_practices/reviews/review.rb +4 -3
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -2
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +5 -4
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +5 -5
- data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +4 -3
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +4 -3
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
- data/lib/rails_best_practices/version.rb +3 -2
- data/rails_best_practices.gemspec +11 -10
- data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +3 -2
- data/spec/rails_best_practices/analyzer_spec.rb +6 -8
- data/spec/rails_best_practices/core/check_spec.rb +2 -0
- data/spec/rails_best_practices/core/checks_loader_spec.rb +2 -0
- data/spec/rails_best_practices/core/configs_spec.rb +2 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +2 -0
- data/spec/rails_best_practices/core/error_spec.rb +2 -0
- data/spec/rails_best_practices/core/except_methods_spec.rb +2 -0
- data/spec/rails_best_practices/core/gems_spec.rb +2 -0
- data/spec/rails_best_practices/core/helpers_spec.rb +2 -0
- data/spec/rails_best_practices/core/klasses_spec.rb +2 -0
- data/spec/rails_best_practices/core/mailers_spec.rb +2 -0
- data/spec/rails_best_practices/core/methods_spec.rb +6 -4
- data/spec/rails_best_practices/core/model_associations_spec.rb +4 -2
- data/spec/rails_best_practices/core/model_attributes_spec.rb +2 -0
- data/spec/rails_best_practices/core/models_spec.rb +2 -0
- data/spec/rails_best_practices/core/modules_spec.rb +2 -0
- data/spec/rails_best_practices/core/routes_spec.rb +4 -2
- data/spec/rails_best_practices/core/runner_spec.rb +2 -0
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +3 -1
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +8 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +8 -6
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +9 -7
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +23 -21
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +7 -5
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +4 -2
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +56 -54
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +39 -37
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +12 -10
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +20 -18
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +11 -9
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +21 -19
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -4
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -31
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +13 -11
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +65 -63
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +24 -22
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -11
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +26 -26
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -7,7 +9,7 @@ module RailsBestPractices
|
|
7
9
|
|
8
10
|
context 'resources' do
|
9
11
|
it 'should add resources route' do
|
10
|
-
content
|
12
|
+
content = <<-EOF
|
11
13
|
RailsBestPracticesCom::Application.routes.draw do
|
12
14
|
resources :posts
|
13
15
|
end
|
@@ -19,7 +21,7 @@ module RailsBestPractices
|
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'should add multiple resources route' do
|
22
|
-
content
|
24
|
+
content = <<-EOF
|
23
25
|
RailsBestPracticesCom::Application.routes.draw do
|
24
26
|
resources :posts, :users
|
25
27
|
end
|
@@ -30,7 +32,7 @@ module RailsBestPractices
|
|
30
32
|
end
|
31
33
|
|
32
34
|
it 'should add resources route with explict controller' do
|
33
|
-
content
|
35
|
+
content = <<-EOF
|
34
36
|
RailsBestPracticesCom::Application.routes.draw do
|
35
37
|
resources :posts, controller: :blog_posts
|
36
38
|
end
|
@@ -42,7 +44,7 @@ module RailsBestPractices
|
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'should add resources route with only option' do
|
45
|
-
content
|
47
|
+
content = <<-EOF
|
46
48
|
RailsBestPracticesCom::Application.routes.draw do
|
47
49
|
resources :posts, only: [:index, :show, :new, :create]
|
48
50
|
end
|
@@ -54,7 +56,7 @@ module RailsBestPractices
|
|
54
56
|
end
|
55
57
|
|
56
58
|
it 'should add resources route with except option' do
|
57
|
-
content
|
59
|
+
content = <<-EOF
|
58
60
|
RailsBestPracticesCom::Application.routes.draw do
|
59
61
|
resources :posts, except: [:edit, :update, :destroy]
|
60
62
|
end
|
@@ -66,7 +68,7 @@ module RailsBestPractices
|
|
66
68
|
end
|
67
69
|
|
68
70
|
it 'should not add resources routes with only: :none' do
|
69
|
-
content
|
71
|
+
content = <<-EOF
|
70
72
|
RailsBestPracticesCom::Application.routes.draw do
|
71
73
|
resources :posts, only: :none
|
72
74
|
end
|
@@ -77,7 +79,7 @@ module RailsBestPractices
|
|
77
79
|
end
|
78
80
|
|
79
81
|
it 'should not add resources routes with except: :all' do
|
80
|
-
content
|
82
|
+
content = <<-EOF
|
81
83
|
RailsBestPracticesCom::Application.routes.draw do
|
82
84
|
resources :posts, except: :all
|
83
85
|
end
|
@@ -88,7 +90,7 @@ module RailsBestPractices
|
|
88
90
|
end
|
89
91
|
|
90
92
|
it 'should add resources routes with members' do
|
91
|
-
content
|
93
|
+
content = <<-EOF
|
92
94
|
RailsBestPracticesCom::Application.routes.draw do
|
93
95
|
namespace :admin do
|
94
96
|
resources :posts, :only => [:edit, :update] do
|
@@ -110,7 +112,7 @@ module RailsBestPractices
|
|
110
112
|
end
|
111
113
|
|
112
114
|
it 'should add resources routes with members inline' do
|
113
|
-
content
|
115
|
+
content = <<-EOF
|
114
116
|
RailsBestPracticesCom::Application.routes.draw do
|
115
117
|
namespace :admin do
|
116
118
|
resources :posts, :only => [:edit, :update] do
|
@@ -130,7 +132,7 @@ module RailsBestPractices
|
|
130
132
|
end
|
131
133
|
|
132
134
|
it 'should add connect route' do
|
133
|
-
content
|
135
|
+
content = <<-EOF
|
134
136
|
ActionController::Routing::Routes.draw do |map|
|
135
137
|
map.connect 'vote', controller: "votes", action: "create", method: :post
|
136
138
|
end
|
@@ -141,7 +143,7 @@ module RailsBestPractices
|
|
141
143
|
end
|
142
144
|
|
143
145
|
it 'should add named route' do
|
144
|
-
content
|
146
|
+
content = <<-EOF
|
145
147
|
ActionController::Routing::Routes.draw do |map|
|
146
148
|
map.login '/player/login', controller: 'sessions', action: 'new', conditions: { method: :get }
|
147
149
|
end
|
@@ -154,7 +156,7 @@ module RailsBestPractices
|
|
154
156
|
|
155
157
|
context 'resource' do
|
156
158
|
it 'should add resource route' do
|
157
|
-
content
|
159
|
+
content = <<-EOF
|
158
160
|
RailsBestPracticesCom::Application.routes.draw do
|
159
161
|
resource :posts
|
160
162
|
end
|
@@ -166,7 +168,7 @@ module RailsBestPractices
|
|
166
168
|
end
|
167
169
|
|
168
170
|
it 'should add multiple resource route' do
|
169
|
-
content
|
171
|
+
content = <<-EOF
|
170
172
|
RailsBestPracticesCom::Application.routes.draw do
|
171
173
|
resource :posts, :users
|
172
174
|
end
|
@@ -177,7 +179,7 @@ module RailsBestPractices
|
|
177
179
|
end
|
178
180
|
|
179
181
|
it 'should add resource route with only option' do
|
180
|
-
content
|
182
|
+
content = <<-EOF
|
181
183
|
RailsBestPracticesCom::Application.routes.draw do
|
182
184
|
resource :posts, only: [:show, :new, :create]
|
183
185
|
end
|
@@ -189,7 +191,7 @@ module RailsBestPractices
|
|
189
191
|
end
|
190
192
|
|
191
193
|
it 'should add resource route with except option' do
|
192
|
-
content
|
194
|
+
content = <<-EOF
|
193
195
|
RailsBestPracticesCom::Application.routes.draw do
|
194
196
|
resource :posts, except: [:edit, :update, :destroy]
|
195
197
|
end
|
@@ -201,7 +203,7 @@ module RailsBestPractices
|
|
201
203
|
end
|
202
204
|
|
203
205
|
it 'should not add resource routes with only: :none' do
|
204
|
-
content
|
206
|
+
content = <<-EOF
|
205
207
|
RailsBestPracticesCom::Application.routes.draw do
|
206
208
|
resource :posts, only: :none
|
207
209
|
end
|
@@ -212,7 +214,7 @@ module RailsBestPractices
|
|
212
214
|
end
|
213
215
|
|
214
216
|
it 'should not add resource routes with except: :all' do
|
215
|
-
content
|
217
|
+
content = <<-EOF
|
216
218
|
RailsBestPracticesCom::Application.routes.draw do
|
217
219
|
resource :posts, except: :all
|
218
220
|
end
|
@@ -223,7 +225,7 @@ module RailsBestPractices
|
|
223
225
|
end
|
224
226
|
|
225
227
|
it 'should add resource routes with get/post/put/patch/delete routes' do
|
226
|
-
content
|
228
|
+
content = <<-EOF
|
227
229
|
RailsBestPracticesCom::Application.routes.draw do
|
228
230
|
resources :posts, only: [:show] do
|
229
231
|
get :list, on: :collection
|
@@ -246,7 +248,7 @@ module RailsBestPractices
|
|
246
248
|
end
|
247
249
|
|
248
250
|
it 'should add custom resources routes with {}' do
|
249
|
-
content
|
251
|
+
content = <<-EOF
|
250
252
|
RailsBestPracticesCom::Application.routes.draw do
|
251
253
|
resources :posts, only: [:show] { get :inactive, on: :collection }
|
252
254
|
end
|
@@ -258,7 +260,7 @@ module RailsBestPractices
|
|
258
260
|
end
|
259
261
|
|
260
262
|
it 'should add resources routes with get %w() routes' do
|
261
|
-
content
|
263
|
+
content = <<-EOF
|
262
264
|
RailsBestPracticesCom::Application.routes.draw do
|
263
265
|
resources :posts, only: [:show] do
|
264
266
|
collection do
|
@@ -274,7 +276,7 @@ module RailsBestPractices
|
|
274
276
|
end
|
275
277
|
|
276
278
|
it 'should add route with nested routes' do
|
277
|
-
content
|
279
|
+
content = <<-EOF
|
278
280
|
RailsBestPracticesCom::Application.routes.draw do
|
279
281
|
resources :posts
|
280
282
|
resources :comments
|
@@ -287,7 +289,7 @@ module RailsBestPractices
|
|
287
289
|
end
|
288
290
|
|
289
291
|
it 'should add route with namespace' do
|
290
|
-
content
|
292
|
+
content = <<-EOF
|
291
293
|
RailsBestPracticesCom::Application.routes.draw do
|
292
294
|
namespace :admin do
|
293
295
|
namespace :test do
|
@@ -302,7 +304,7 @@ module RailsBestPractices
|
|
302
304
|
end
|
303
305
|
|
304
306
|
it 'should add route with namespace, but without resources' do
|
305
|
-
content
|
307
|
+
content = <<-EOF
|
306
308
|
RailsBestPracticesCom::Appllication.routes.draw do
|
307
309
|
namespace :something do
|
308
310
|
get *%w(route_one route_two)
|
@@ -316,7 +318,7 @@ module RailsBestPractices
|
|
316
318
|
end
|
317
319
|
|
318
320
|
it 'should add route with scope' do
|
319
|
-
content
|
321
|
+
content = <<-EOF
|
320
322
|
RailsBestPracticesCom::Application.routes.draw do
|
321
323
|
scope module: "admin" do
|
322
324
|
resources :posts, only: [:index]
|
@@ -346,7 +348,7 @@ module RailsBestPractices
|
|
346
348
|
end
|
347
349
|
|
348
350
|
it 'should add route for direct get/post' do
|
349
|
-
content
|
351
|
+
content = <<-EOF
|
350
352
|
RailsBestPracticesCom::Application.routes.draw do
|
351
353
|
get 'posts/show'
|
352
354
|
post '/posts' => 'posts#create'
|
@@ -362,7 +364,7 @@ module RailsBestPractices
|
|
362
364
|
end
|
363
365
|
|
364
366
|
it 'should add routes for another get/post' do
|
365
|
-
content
|
367
|
+
content = <<-EOF
|
366
368
|
RailsBestPracticesCom::Application.routes.draw
|
367
369
|
get "/login", to: 'sessions#new', as: :login
|
368
370
|
end
|
@@ -374,7 +376,7 @@ module RailsBestPractices
|
|
374
376
|
end
|
375
377
|
|
376
378
|
it 'should add match route' do
|
377
|
-
content
|
379
|
+
content = <<-EOF
|
378
380
|
RailsBestPracticesCom::Application.routes.draw do
|
379
381
|
match '/auth/:provider/callback' => 'authentications#create'
|
380
382
|
end
|
@@ -385,7 +387,7 @@ module RailsBestPractices
|
|
385
387
|
end
|
386
388
|
|
387
389
|
it 'should add match route with all actions' do
|
388
|
-
content
|
390
|
+
content = <<-EOF
|
389
391
|
RailsBestPracticesCom::Application.routes.draw do
|
390
392
|
match 'internal/:action/*whatever', controller: "internal"
|
391
393
|
end
|
@@ -396,7 +398,7 @@ module RailsBestPractices
|
|
396
398
|
end
|
397
399
|
|
398
400
|
it 'should add root route' do
|
399
|
-
content
|
401
|
+
content = <<-EOF
|
400
402
|
RailsBestPracticesCom::Application.routes.draw do
|
401
403
|
root to: 'home#index'
|
402
404
|
end
|
@@ -407,7 +409,7 @@ module RailsBestPractices
|
|
407
409
|
end
|
408
410
|
|
409
411
|
it 'should add root shortcut route' do
|
410
|
-
content
|
412
|
+
content = <<-EOF
|
411
413
|
RailsBestPracticesCom::Application.routes.draw do
|
412
414
|
root 'home#index'
|
413
415
|
end
|
@@ -418,7 +420,7 @@ module RailsBestPractices
|
|
418
420
|
end
|
419
421
|
|
420
422
|
it 'should do nothing for default route' do
|
421
|
-
content
|
423
|
+
content = <<-EOF
|
422
424
|
RailsBestPracticesCom::Application.routes.draw do
|
423
425
|
match ':controller(/:action(/:id(.:format)))'
|
424
426
|
end
|
@@ -429,7 +431,7 @@ module RailsBestPractices
|
|
429
431
|
end
|
430
432
|
|
431
433
|
it 'should do nothing for redirect' do
|
432
|
-
content
|
434
|
+
content = <<-EOF
|
433
435
|
RailsBestPracticesCom::Application.routes.draw do
|
434
436
|
match "/stories/:name" => redirect("/posts/%{name}")
|
435
437
|
match "/stories" => redirect {|p, req| "/posts/\#{req.subdomain}" }
|
@@ -441,7 +443,7 @@ module RailsBestPractices
|
|
441
443
|
end
|
442
444
|
|
443
445
|
it 'should parse customize route in nested resources' do
|
444
|
-
content
|
446
|
+
content = <<-EOF
|
445
447
|
RailsBestPracticesCom::Application.routes.draw do
|
446
448
|
resources :posts do
|
447
449
|
resources :comments
|
@@ -455,7 +457,7 @@ module RailsBestPractices
|
|
455
457
|
end
|
456
458
|
|
457
459
|
it 'should parse custom route for resource with explicit to and different action name' do
|
458
|
-
content
|
460
|
+
content = <<-EOF
|
459
461
|
RailsBestPracticesCom::Application.routes.draw do
|
460
462
|
resources :posts do
|
461
463
|
get :halt, to: 'posts#stop'
|
@@ -468,7 +470,7 @@ module RailsBestPractices
|
|
468
470
|
end
|
469
471
|
|
470
472
|
it 'should parse custom route for resource with symbol action name' do
|
471
|
-
content
|
473
|
+
content = <<-EOF
|
472
474
|
RailsBestPracticesCom::Application.routes.draw do
|
473
475
|
resources :posts do
|
474
476
|
get :halt, to: :stop
|
@@ -481,7 +483,7 @@ module RailsBestPractices
|
|
481
483
|
end
|
482
484
|
|
483
485
|
it 'should not take former resources for direct get/post' do
|
484
|
-
content
|
486
|
+
content = <<-EOF
|
485
487
|
RailsBestPracticesCom::Application.routes.draw do
|
486
488
|
resources :posts
|
487
489
|
post "sprints/stop"
|
@@ -493,7 +495,7 @@ module RailsBestPractices
|
|
493
495
|
end
|
494
496
|
|
495
497
|
it 'should not parse wrong route' do
|
496
|
-
content
|
498
|
+
content = <<-EOF
|
497
499
|
RailsBestPracticesCom::Application.routes.draw do
|
498
500
|
match ':controller/:action' => '#index', as: :auto_complete
|
499
501
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -6,7 +8,7 @@ module RailsBestPractices
|
|
6
8
|
let(:runner) { Core::Runner.new(prepares: SchemaPrepare.new) }
|
7
9
|
|
8
10
|
it 'should parse model attributes' do
|
9
|
-
content
|
11
|
+
content = <<-EOF
|
10
12
|
ActiveRecord::Schema.define(version: 20110319172136) do
|
11
13
|
create_table "posts", force: true do |t|
|
12
14
|
t.string "title"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -219,7 +221,7 @@ module RailsBestPractices
|
|
219
221
|
end
|
220
222
|
|
221
223
|
it 'should not always add db index if two indexes for polymorphic association' do
|
222
|
-
content
|
224
|
+
content = <<-EOF
|
223
225
|
ActiveRecord::Schema.define(version: 20100603080629) do
|
224
226
|
create_table "taggings", force: true do |t|
|
225
227
|
t.integer "tagger_id"
|
@@ -237,7 +239,7 @@ module RailsBestPractices
|
|
237
239
|
end
|
238
240
|
|
239
241
|
it 'should not always add db index if table does not exist' do
|
240
|
-
content
|
242
|
+
content = <<-EOF
|
241
243
|
ActiveRecord::Schema.define(version: 20100603080629) do
|
242
244
|
create_table "comments", force: true do |t|
|
243
245
|
t.integer "post_id"
|
@@ -250,18 +252,18 @@ module RailsBestPractices
|
|
250
252
|
end
|
251
253
|
|
252
254
|
it 'should always add db index if association_name is different to foreign_key' do
|
253
|
-
content
|
255
|
+
content = <<-EOF
|
254
256
|
class Comment < ActiveRecord::Base
|
255
257
|
belongs_to :commentor, class_name: "User"
|
256
258
|
end
|
257
259
|
EOF
|
258
260
|
runner.prepare('app/models/comment.rb', content)
|
259
|
-
content
|
261
|
+
content = <<-EOF
|
260
262
|
class User < ActiveRecord::Base
|
261
263
|
end
|
262
264
|
EOF
|
263
265
|
runner.prepare('app/models/user.rb', content)
|
264
|
-
content
|
266
|
+
content = <<-EOF
|
265
267
|
ActiveRecord::Schema.define(version: 20100603080629) do
|
266
268
|
create_table "comments", force: true do |t|
|
267
269
|
t.integer "commentor_id"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -7,7 +9,7 @@ module RailsBestPractices
|
|
7
9
|
|
8
10
|
describe 'check_destroy_return_value' do
|
9
11
|
it 'should warn you if you fail to check the destroy return value' do
|
10
|
-
content
|
12
|
+
content = <<-EOF
|
11
13
|
def my_method
|
12
14
|
post = Posts.create do |p|
|
13
15
|
p.title = "foo"
|
@@ -21,7 +23,7 @@ module RailsBestPractices
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'should allow destroy return value if assigned to a var' do
|
24
|
-
content
|
26
|
+
content = <<-EOF
|
25
27
|
def my_method
|
26
28
|
post = Posts.create do |p|
|
27
29
|
p.title = "foo"
|
@@ -34,7 +36,7 @@ module RailsBestPractices
|
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'should allow destroy return value used in if' do
|
37
|
-
content
|
39
|
+
content = <<-EOF
|
38
40
|
def my_method
|
39
41
|
post = Posts.create do |p|
|
40
42
|
p.title = "foo"
|
@@ -51,7 +53,7 @@ module RailsBestPractices
|
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'should allow destroy return value used in elsif' do
|
54
|
-
content
|
56
|
+
content = <<-EOF
|
55
57
|
def my_method
|
56
58
|
post = Posts.create do |p|
|
57
59
|
p.title = "foo"
|
@@ -70,7 +72,7 @@ module RailsBestPractices
|
|
70
72
|
end
|
71
73
|
|
72
74
|
it 'should allow destroy return value used in unless' do
|
73
|
-
content
|
75
|
+
content = <<-EOF
|
74
76
|
def my_method
|
75
77
|
unless @post.destroy
|
76
78
|
raise "could not destroy"
|
@@ -82,7 +84,7 @@ module RailsBestPractices
|
|
82
84
|
end
|
83
85
|
|
84
86
|
it 'should allow destroy return value used in if_mod' do
|
85
|
-
content
|
87
|
+
content = <<-EOF
|
86
88
|
def my_method
|
87
89
|
post = Posts.create do |p|
|
88
90
|
p.title = "foo"
|
@@ -95,7 +97,7 @@ module RailsBestPractices
|
|
95
97
|
end
|
96
98
|
|
97
99
|
it 'should allow destroy return value used in unless_mod' do
|
98
|
-
content
|
100
|
+
content = <<-EOF
|
99
101
|
def my_method
|
100
102
|
post = Posts.create do |p|
|
101
103
|
p.title = "foo"
|
@@ -108,7 +110,7 @@ module RailsBestPractices
|
|
108
110
|
end
|
109
111
|
|
110
112
|
it 'should allow destroy return value used in unless with &&' do
|
111
|
-
content
|
113
|
+
content = <<-EOF
|
112
114
|
def my_method
|
113
115
|
unless some_method(1) && other_method(2) && @post.destroy
|
114
116
|
raise "could not destroy"
|
@@ -120,7 +122,7 @@ module RailsBestPractices
|
|
120
122
|
end
|
121
123
|
|
122
124
|
it 'should allow destroy!' do
|
123
|
-
content
|
125
|
+
content = <<-EOF
|
124
126
|
def my_method
|
125
127
|
post = Posts.create do |p|
|
126
128
|
p.title = "foo"
|
@@ -135,7 +137,7 @@ module RailsBestPractices
|
|
135
137
|
|
136
138
|
it 'should not check ignored files' do
|
137
139
|
runner = Core::Runner.new(reviews: CheckDestroyReturnValueReview.new(ignored_files: /helpers/))
|
138
|
-
content
|
140
|
+
content = <<-EOF
|
139
141
|
def my_method
|
140
142
|
post = Posts.create do |p|
|
141
143
|
p.title = "foo"
|