rails_best_practices 1.14.4 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/README.md +26 -6
- data/lib/rails_best_practices/core/check.rb +15 -2
- data/lib/rails_best_practices/core/klasses.rb +13 -3
- data/lib/rails_best_practices/core/model_associations.rb +1 -1
- data/lib/rails_best_practices/core/runner.rb +2 -0
- data/lib/rails_best_practices/lexicals/long_line_check.rb +1 -1
- data/lib/rails_best_practices/prepares/route_prepare.rb +17 -1
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +2 -2
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +1 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +1 -1
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +1 -2
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +1 -1
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +15 -26
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -2
- data/lib/rails_best_practices/version.rb +1 -1
- data/spec/rails_best_practices/analyzer_spec.rb +11 -11
- data/spec/rails_best_practices/core/check_spec.rb +1 -1
- data/spec/rails_best_practices/core/error_spec.rb +6 -6
- data/spec/rails_best_practices/core/klasses_spec.rb +26 -2
- data/spec/rails_best_practices/core/methods_spec.rb +18 -18
- data/spec/rails_best_practices/core/model_associations_spec.rb +6 -6
- data/spec/rails_best_practices/core/model_attributes_spec.rb +6 -6
- data/spec/rails_best_practices/core/modules_spec.rb +3 -3
- data/spec/rails_best_practices/core/routes_spec.rb +4 -4
- data/spec/rails_best_practices/core/runner_spec.rb +1 -1
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +18 -6
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +18 -5
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +17 -5
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +13 -13
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +44 -44
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +102 -78
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +25 -9
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +43 -23
- data/spec/rails_best_practices/reviews/check_save_return_value_spec.rb +34 -20
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +16 -5
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +25 -3
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +18 -7
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +30 -7
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +24 -8
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +24 -12
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +17 -5
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +14 -3
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +24 -13
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +25 -6
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +26 -4
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +31 -18
- data/spec/rails_best_practices/reviews/not_rescue_exception_spec.rb +23 -10
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +34 -7
- data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +19 -8
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +33 -19
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +25 -13
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +14 -4
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +91 -23
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +20 -5
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +66 -41
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +28 -4
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -7
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +45 -32
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +20 -9
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +23 -14
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +34 -7
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +21 -6
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +124 -79
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +12 -12
- data/spec/rails_best_practices/reviews/use_parenthesis_in_method_def_spec.rb +16 -4
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +39 -27
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +22 -8
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +39 -21
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +66 -7
- metadata +36 -37
- data/.ruby-gemset +0 -1
@@ -15,8 +15,8 @@ module RailsBestPractices
|
|
15
15
|
EOF
|
16
16
|
runner.prepare('config/routes.rb', content)
|
17
17
|
routes = Prepares.routes
|
18
|
-
routes.size.
|
19
|
-
routes.map(&:to_s).
|
18
|
+
expect(routes.size).to eq(7)
|
19
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"])
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should add multiple resources route" do
|
@@ -27,7 +27,7 @@ module RailsBestPractices
|
|
27
27
|
EOF
|
28
28
|
runner.prepare('config/routes.rb', content)
|
29
29
|
routes = Prepares.routes
|
30
|
-
routes.size.
|
30
|
+
expect(routes.size).to eq(14)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should add resources route with explict controller" do
|
@@ -38,8 +38,8 @@ module RailsBestPractices
|
|
38
38
|
EOF
|
39
39
|
runner.prepare('config/routes.rb', content)
|
40
40
|
routes = Prepares.routes
|
41
|
-
routes.size.
|
42
|
-
routes.map(&:to_s).
|
41
|
+
expect(routes.size).to eq(7)
|
42
|
+
expect(routes.map(&:to_s)).to eq(["BlogPostsController#index", "BlogPostsController#show", "BlogPostsController#new", "BlogPostsController#create", "BlogPostsController#edit", "BlogPostsController#update", "BlogPostsController#destroy"])
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should add resources route with only option" do
|
@@ -50,8 +50,8 @@ module RailsBestPractices
|
|
50
50
|
EOF
|
51
51
|
runner.prepare('config/routes.rb', content)
|
52
52
|
routes = Prepares.routes
|
53
|
-
routes.size.
|
54
|
-
routes.map(&:to_s).
|
53
|
+
expect(routes.size).to eq(4)
|
54
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"])
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should add resources route with except option" do
|
@@ -62,8 +62,8 @@ module RailsBestPractices
|
|
62
62
|
EOF
|
63
63
|
runner.prepare('config/routes.rb', content)
|
64
64
|
routes = Prepares.routes
|
65
|
-
routes.size.
|
66
|
-
routes.map(&:to_s).
|
65
|
+
expect(routes.size).to eq(4)
|
66
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"])
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should not add resources routes with only: :none" do
|
@@ -74,7 +74,7 @@ module RailsBestPractices
|
|
74
74
|
EOF
|
75
75
|
runner.prepare('config/routes.rb', content)
|
76
76
|
routes = Prepares.routes
|
77
|
-
routes.size.
|
77
|
+
expect(routes.size).to eq(0)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should not add resources routes with except: :all" do
|
@@ -85,7 +85,7 @@ module RailsBestPractices
|
|
85
85
|
EOF
|
86
86
|
runner.prepare('config/routes.rb', content)
|
87
87
|
routes = Prepares.routes
|
88
|
-
routes.size.
|
88
|
+
expect(routes.size).to eq(0)
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should add resource routes with hash collection/member routes" do
|
@@ -96,8 +96,8 @@ module RailsBestPractices
|
|
96
96
|
EOF
|
97
97
|
runner.prepare('config/routes.rb', content)
|
98
98
|
routes = Prepares.routes
|
99
|
-
routes.size.
|
100
|
-
routes.map(&:to_s).
|
99
|
+
expect(routes.size).to eq(5)
|
100
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "PostsController#list"])
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should add resource routes with array collection/member routes" do
|
@@ -108,8 +108,8 @@ module RailsBestPractices
|
|
108
108
|
EOF
|
109
109
|
runner.prepare('config/routes.rb', content)
|
110
110
|
routes = Prepares.routes
|
111
|
-
routes.size.
|
112
|
-
routes.map(&:to_s).
|
111
|
+
expect(routes.size).to eq(5)
|
112
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "PostsController#list"])
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should add route with nested routes" do
|
@@ -122,7 +122,7 @@ module RailsBestPractices
|
|
122
122
|
EOF
|
123
123
|
runner.prepare('config/routes.rb', content)
|
124
124
|
routes = Prepares.routes
|
125
|
-
routes.size.
|
125
|
+
expect(routes.size).to eq(14)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should add route with namespace" do
|
@@ -137,7 +137,7 @@ module RailsBestPractices
|
|
137
137
|
EOF
|
138
138
|
runner.prepare('config/routes.rb', content)
|
139
139
|
routes = Prepares.routes
|
140
|
-
routes.map(&:to_s).
|
140
|
+
expect(routes.map(&:to_s)).to eq(["Admin::Test::PostsController#index"])
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -150,8 +150,8 @@ module RailsBestPractices
|
|
150
150
|
EOF
|
151
151
|
runner.prepare('config/routes.rb', content)
|
152
152
|
routes = Prepares.routes
|
153
|
-
routes.size.
|
154
|
-
routes.map(&:to_s).
|
153
|
+
expect(routes.size).to eq(6)
|
154
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"])
|
155
155
|
end
|
156
156
|
|
157
157
|
it "should add multiple resource route" do
|
@@ -162,7 +162,7 @@ module RailsBestPractices
|
|
162
162
|
EOF
|
163
163
|
runner.prepare('config/routes.rb', content)
|
164
164
|
routes = Prepares.routes
|
165
|
-
routes.size.
|
165
|
+
expect(routes.size).to eq(12)
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should add resource route with only option" do
|
@@ -173,8 +173,8 @@ module RailsBestPractices
|
|
173
173
|
EOF
|
174
174
|
runner.prepare('config/routes.rb', content)
|
175
175
|
routes = Prepares.routes
|
176
|
-
routes.size.
|
177
|
-
routes.map(&:to_s).
|
176
|
+
expect(routes.size).to eq(3)
|
177
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#new", "PostsController#create"])
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should add resource route with except option" do
|
@@ -185,8 +185,8 @@ module RailsBestPractices
|
|
185
185
|
EOF
|
186
186
|
runner.prepare('config/routes.rb', content)
|
187
187
|
routes = Prepares.routes
|
188
|
-
routes.size.
|
189
|
-
routes.map(&:to_s).
|
188
|
+
expect(routes.size).to eq(3)
|
189
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#new", "PostsController#create"])
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should not add resource routes with only: :none" do
|
@@ -197,7 +197,7 @@ module RailsBestPractices
|
|
197
197
|
EOF
|
198
198
|
runner.prepare('config/routes.rb', content)
|
199
199
|
routes = Prepares.routes
|
200
|
-
routes.size.
|
200
|
+
expect(routes.size).to eq(0)
|
201
201
|
end
|
202
202
|
|
203
203
|
it "should not add resource routes with except: :all" do
|
@@ -208,7 +208,7 @@ module RailsBestPractices
|
|
208
208
|
EOF
|
209
209
|
runner.prepare('config/routes.rb', content)
|
210
210
|
routes = Prepares.routes
|
211
|
-
routes.size.
|
211
|
+
expect(routes.size).to eq(0)
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
@@ -220,7 +220,7 @@ module RailsBestPractices
|
|
220
220
|
EOF
|
221
221
|
runner.prepare('config/routes.rb', content)
|
222
222
|
routes = Prepares.routes
|
223
|
-
routes.map(&:to_s).
|
223
|
+
expect(routes.map(&:to_s)).to eq(["VotesController#create"])
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should add connect route with all actions" do
|
@@ -231,7 +231,7 @@ module RailsBestPractices
|
|
231
231
|
EOF
|
232
232
|
runner.prepare('config/routes.rb', content)
|
233
233
|
routes = Prepares.routes
|
234
|
-
routes.map(&:to_s).
|
234
|
+
expect(routes.map(&:to_s)).to eq(["InternalController#*"])
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should add named route" do
|
@@ -242,7 +242,7 @@ module RailsBestPractices
|
|
242
242
|
EOF
|
243
243
|
runner.prepare('config/routes.rb', content)
|
244
244
|
routes = Prepares.routes
|
245
|
-
routes.map(&:to_s).
|
245
|
+
expect(routes.map(&:to_s)).to eq(["SessionsController#new"])
|
246
246
|
end
|
247
247
|
|
248
248
|
it "should add named route with with_options" do
|
@@ -255,7 +255,7 @@ module RailsBestPractices
|
|
255
255
|
EOF
|
256
256
|
runner.prepare('config/routes.rb', content)
|
257
257
|
routes = Prepares.routes
|
258
|
-
routes.map(&:to_s).
|
258
|
+
expect(routes.map(&:to_s)).to eq(["AdminSessionController#new"])
|
259
259
|
end
|
260
260
|
|
261
261
|
it "should not take former resources for direct get/post" do
|
@@ -267,7 +267,7 @@ module RailsBestPractices
|
|
267
267
|
EOF
|
268
268
|
runner.prepare('config/routes.rb', content)
|
269
269
|
routes = Prepares.routes
|
270
|
-
routes.last.to_s.
|
270
|
+
expect(routes.last.to_s).to eq("SprintsController#stop")
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -281,8 +281,8 @@ module RailsBestPractices
|
|
281
281
|
EOF
|
282
282
|
runner.prepare('config/routes.rb', content)
|
283
283
|
routes = Prepares.routes
|
284
|
-
routes.size.
|
285
|
-
routes.map(&:to_s).
|
284
|
+
expect(routes.size).to eq(7)
|
285
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"])
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should add multiple resources route" do
|
@@ -293,7 +293,7 @@ module RailsBestPractices
|
|
293
293
|
EOF
|
294
294
|
runner.prepare('config/routes.rb', content)
|
295
295
|
routes = Prepares.routes
|
296
|
-
routes.size.
|
296
|
+
expect(routes.size).to eq(14)
|
297
297
|
end
|
298
298
|
|
299
299
|
it "should add resources route with explict controller" do
|
@@ -304,8 +304,8 @@ module RailsBestPractices
|
|
304
304
|
EOF
|
305
305
|
runner.prepare('config/routes.rb', content)
|
306
306
|
routes = Prepares.routes
|
307
|
-
routes.size.
|
308
|
-
routes.map(&:to_s).
|
307
|
+
expect(routes.size).to eq(7)
|
308
|
+
expect(routes.map(&:to_s)).to eq(["BlogPostsController#index", "BlogPostsController#show", "BlogPostsController#new", "BlogPostsController#create", "BlogPostsController#edit", "BlogPostsController#update", "BlogPostsController#destroy"])
|
309
309
|
end
|
310
310
|
|
311
311
|
it "should add resources route with only option" do
|
@@ -316,8 +316,8 @@ module RailsBestPractices
|
|
316
316
|
EOF
|
317
317
|
runner.prepare('config/routes.rb', content)
|
318
318
|
routes = Prepares.routes
|
319
|
-
routes.size.
|
320
|
-
routes.map(&:to_s).
|
319
|
+
expect(routes.size).to eq(4)
|
320
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"])
|
321
321
|
end
|
322
322
|
|
323
323
|
it "should add resources route with except option" do
|
@@ -328,8 +328,8 @@ module RailsBestPractices
|
|
328
328
|
EOF
|
329
329
|
runner.prepare('config/routes.rb', content)
|
330
330
|
routes = Prepares.routes
|
331
|
-
routes.size.
|
332
|
-
routes.map(&:to_s).
|
331
|
+
expect(routes.size).to eq(4)
|
332
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"])
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should not add resources routes with only: :none" do
|
@@ -340,7 +340,7 @@ module RailsBestPractices
|
|
340
340
|
EOF
|
341
341
|
runner.prepare('config/routes.rb', content)
|
342
342
|
routes = Prepares.routes
|
343
|
-
routes.size.
|
343
|
+
expect(routes.size).to eq(0)
|
344
344
|
end
|
345
345
|
|
346
346
|
it "should not add resources routes with except: :all" do
|
@@ -351,7 +351,7 @@ module RailsBestPractices
|
|
351
351
|
EOF
|
352
352
|
runner.prepare('config/routes.rb', content)
|
353
353
|
routes = Prepares.routes
|
354
|
-
routes.size.
|
354
|
+
expect(routes.size).to eq(0)
|
355
355
|
end
|
356
356
|
|
357
357
|
it "should add resources routes with members" do
|
@@ -369,11 +369,11 @@ module RailsBestPractices
|
|
369
369
|
EOF
|
370
370
|
runner.prepare('config/routes.rb', content)
|
371
371
|
routes = Prepares.routes
|
372
|
-
routes.map(&:to_s).
|
372
|
+
expect(routes.map(&:to_s)).to eq([
|
373
373
|
"Admin::PostsController#edit",
|
374
374
|
"Admin::PostsController#update",
|
375
375
|
"Admin::PostsController#link_to_post",
|
376
|
-
"Admin::PostsController#extra_update"]
|
376
|
+
"Admin::PostsController#extra_update"])
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should add connect route" do
|
@@ -384,7 +384,7 @@ module RailsBestPractices
|
|
384
384
|
EOF
|
385
385
|
runner.prepare('config/routes.rb', content)
|
386
386
|
routes = Prepares.routes
|
387
|
-
routes.map(&:to_s).
|
387
|
+
expect(routes.map(&:to_s)).to eq(["VotesController#create"])
|
388
388
|
end
|
389
389
|
|
390
390
|
it "should add named route" do
|
@@ -395,7 +395,7 @@ module RailsBestPractices
|
|
395
395
|
EOF
|
396
396
|
runner.prepare('config/routes.rb', content)
|
397
397
|
routes = Prepares.routes
|
398
|
-
routes.map(&:to_s).
|
398
|
+
expect(routes.map(&:to_s)).to eq(["SessionsController#new"])
|
399
399
|
end
|
400
400
|
end
|
401
401
|
|
@@ -408,8 +408,8 @@ module RailsBestPractices
|
|
408
408
|
EOF
|
409
409
|
runner.prepare('config/routes.rb', content)
|
410
410
|
routes = Prepares.routes
|
411
|
-
routes.size.
|
412
|
-
routes.map(&:to_s).
|
411
|
+
expect(routes.size).to eq(6)
|
412
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"])
|
413
413
|
end
|
414
414
|
|
415
415
|
it "should add multiple resource route" do
|
@@ -420,7 +420,7 @@ module RailsBestPractices
|
|
420
420
|
EOF
|
421
421
|
runner.prepare('config/routes.rb', content)
|
422
422
|
routes = Prepares.routes
|
423
|
-
routes.size.
|
423
|
+
expect(routes.size).to eq(12)
|
424
424
|
end
|
425
425
|
|
426
426
|
it "should add resource route with only option" do
|
@@ -431,8 +431,8 @@ module RailsBestPractices
|
|
431
431
|
EOF
|
432
432
|
runner.prepare('config/routes.rb', content)
|
433
433
|
routes = Prepares.routes
|
434
|
-
routes.size.
|
435
|
-
routes.map(&:to_s).
|
434
|
+
expect(routes.size).to eq(3)
|
435
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#new", "PostsController#create"])
|
436
436
|
end
|
437
437
|
|
438
438
|
it "should add resource route with except option" do
|
@@ -443,8 +443,8 @@ module RailsBestPractices
|
|
443
443
|
EOF
|
444
444
|
runner.prepare('config/routes.rb', content)
|
445
445
|
routes = Prepares.routes
|
446
|
-
routes.size.
|
447
|
-
routes.map(&:to_s).
|
446
|
+
expect(routes.size).to eq(3)
|
447
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#new", "PostsController#create"])
|
448
448
|
end
|
449
449
|
|
450
450
|
it "should not add resource routes with only: :none" do
|
@@ -455,7 +455,7 @@ module RailsBestPractices
|
|
455
455
|
EOF
|
456
456
|
runner.prepare('config/routes.rb', content)
|
457
457
|
routes = Prepares.routes
|
458
|
-
routes.size.
|
458
|
+
expect(routes.size).to eq(0)
|
459
459
|
end
|
460
460
|
|
461
461
|
it "should not add resource routes with except: :all" do
|
@@ -466,7 +466,7 @@ module RailsBestPractices
|
|
466
466
|
EOF
|
467
467
|
runner.prepare('config/routes.rb', content)
|
468
468
|
routes = Prepares.routes
|
469
|
-
routes.size.
|
469
|
+
expect(routes.size).to eq(0)
|
470
470
|
end
|
471
471
|
|
472
472
|
it "should add resource routes with get/post/put/delete routes" do
|
@@ -487,8 +487,8 @@ module RailsBestPractices
|
|
487
487
|
EOF
|
488
488
|
runner.prepare('config/routes.rb', content)
|
489
489
|
routes = Prepares.routes
|
490
|
-
routes.size.
|
491
|
-
routes.map(&:to_s).
|
490
|
+
expect(routes.size).to eq(6)
|
491
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#list", "PostsController#search", "PostsController#available", "PostsController#create", "PostsController#update"])
|
492
492
|
end
|
493
493
|
|
494
494
|
it "should add custom resources routes with {}" do
|
@@ -499,8 +499,8 @@ module RailsBestPractices
|
|
499
499
|
EOF
|
500
500
|
runner.prepare('config/routes.rb', content)
|
501
501
|
routes = Prepares.routes
|
502
|
-
routes.size.
|
503
|
-
routes.map(&:to_s).
|
502
|
+
expect(routes.size).to eq(2)
|
503
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#inactive"])
|
504
504
|
end
|
505
505
|
|
506
506
|
it "should add resources routes with get %w() routes" do
|
@@ -515,8 +515,8 @@ module RailsBestPractices
|
|
515
515
|
EOF
|
516
516
|
runner.prepare('config/routes.rb', content)
|
517
517
|
routes = Prepares.routes
|
518
|
-
routes.size.
|
519
|
-
routes.map(&:to_s).
|
518
|
+
expect(routes.size).to eq(3)
|
519
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#latest", "PostsController#popular"])
|
520
520
|
end
|
521
521
|
|
522
522
|
it "should add route with nested routes" do
|
@@ -529,7 +529,7 @@ module RailsBestPractices
|
|
529
529
|
EOF
|
530
530
|
runner.prepare('config/routes.rb', content)
|
531
531
|
routes = Prepares.routes
|
532
|
-
routes.size.
|
532
|
+
expect(routes.size).to eq(14)
|
533
533
|
end
|
534
534
|
|
535
535
|
it "should add route with namespace" do
|
@@ -544,7 +544,7 @@ module RailsBestPractices
|
|
544
544
|
EOF
|
545
545
|
runner.prepare('config/routes.rb', content)
|
546
546
|
routes = Prepares.routes
|
547
|
-
routes.map(&:to_s).
|
547
|
+
expect(routes.map(&:to_s)).to eq(["Admin::Test::PostsController#index"])
|
548
548
|
end
|
549
549
|
|
550
550
|
it "should add route with namespace, but without resources" do
|
@@ -558,7 +558,7 @@ module RailsBestPractices
|
|
558
558
|
EOF
|
559
559
|
runner.prepare('config/routes.rb', content)
|
560
560
|
routes = Prepares.routes
|
561
|
-
routes.map(&:to_s).
|
561
|
+
expect(routes.map(&:to_s)).to eq(["SomethingController#route_one", "SomethingController#route_two", "SomethingController#custom_action"])
|
562
562
|
end
|
563
563
|
|
564
564
|
it "should add route with scope" do
|
@@ -581,13 +581,13 @@ module RailsBestPractices
|
|
581
581
|
EOF
|
582
582
|
runner.prepare('config/routes.rb', content)
|
583
583
|
routes = Prepares.routes
|
584
|
-
routes.map(&:to_s).
|
584
|
+
expect(routes.map(&:to_s)).to eq([
|
585
585
|
"Admin::PostsController#index",
|
586
586
|
"Admin::DiscussionsController#index",
|
587
587
|
"CommentsController#index",
|
588
588
|
"UsersController#show",
|
589
589
|
"UsersController#preview"
|
590
|
-
]
|
590
|
+
])
|
591
591
|
end
|
592
592
|
end
|
593
593
|
|
@@ -603,8 +603,8 @@ module RailsBestPractices
|
|
603
603
|
EOF
|
604
604
|
runner.prepare('config/routes.rb', content)
|
605
605
|
routes = Prepares.routes
|
606
|
-
routes.size.
|
607
|
-
routes.map(&:to_s).
|
606
|
+
expect(routes.size).to eq(5)
|
607
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "HighVoltage::PagesController#show"])
|
608
608
|
end
|
609
609
|
|
610
610
|
it "should add routes for another get/post" do
|
@@ -615,8 +615,8 @@ module RailsBestPractices
|
|
615
615
|
EOF
|
616
616
|
runner.prepare('config/routes.rb', content)
|
617
617
|
routes = Prepares.routes
|
618
|
-
routes.size.
|
619
|
-
routes.first.to_s.
|
618
|
+
expect(routes.size).to eq(1)
|
619
|
+
expect(routes.first.to_s).to eq("SessionsController#new")
|
620
620
|
end
|
621
621
|
|
622
622
|
it "should add match route" do
|
@@ -627,7 +627,7 @@ module RailsBestPractices
|
|
627
627
|
EOF
|
628
628
|
runner.prepare('config/routes.rb', content)
|
629
629
|
routes = Prepares.routes
|
630
|
-
routes.map(&:to_s).
|
630
|
+
expect(routes.map(&:to_s)).to eq(["AuthenticationsController#create"])
|
631
631
|
end
|
632
632
|
|
633
633
|
it "should add match route with all actions" do
|
@@ -638,7 +638,7 @@ module RailsBestPractices
|
|
638
638
|
EOF
|
639
639
|
runner.prepare('config/routes.rb', content)
|
640
640
|
routes = Prepares.routes
|
641
|
-
routes.map(&:to_s).
|
641
|
+
expect(routes.map(&:to_s)).to eq(["InternalController#*"])
|
642
642
|
end
|
643
643
|
|
644
644
|
it "should add root route" do
|
@@ -649,7 +649,18 @@ module RailsBestPractices
|
|
649
649
|
EOF
|
650
650
|
runner.prepare('config/routes.rb', content)
|
651
651
|
routes = Prepares.routes
|
652
|
-
routes.map(&:to_s).
|
652
|
+
expect(routes.map(&:to_s)).to eq(["HomeController#index"])
|
653
|
+
end
|
654
|
+
|
655
|
+
it "should add root shortcut route" do
|
656
|
+
content =<<-EOF
|
657
|
+
RailsBestPracticesCom::Application.routes.draw do
|
658
|
+
root 'home#index'
|
659
|
+
end
|
660
|
+
EOF
|
661
|
+
runner.prepare('config/routes.rb', content)
|
662
|
+
routes = Prepares.routes
|
663
|
+
expect(routes.map(&:to_s)).to eq(["HomeController#index"])
|
653
664
|
end
|
654
665
|
|
655
666
|
it "should do nothing for default route" do
|
@@ -660,7 +671,7 @@ module RailsBestPractices
|
|
660
671
|
EOF
|
661
672
|
runner.prepare('config/routes.rb', content)
|
662
673
|
routes = Prepares.routes
|
663
|
-
routes.size.
|
674
|
+
expect(routes.size).to eq(0)
|
664
675
|
end
|
665
676
|
|
666
677
|
it "should do nothing for redirect" do
|
@@ -672,7 +683,7 @@ module RailsBestPractices
|
|
672
683
|
EOF
|
673
684
|
runner.prepare('config/routes.rb', content)
|
674
685
|
routes = Prepares.routes
|
675
|
-
routes.size.
|
686
|
+
expect(routes.size).to eq(0)
|
676
687
|
end
|
677
688
|
|
678
689
|
it "should parse customize route in nested resources" do
|
@@ -686,7 +697,20 @@ module RailsBestPractices
|
|
686
697
|
EOF
|
687
698
|
runner.prepare('config/routes.rb', content)
|
688
699
|
routes = Prepares.routes
|
689
|
-
routes.last.to_s.
|
700
|
+
expect(routes.last.to_s).to eq("PostsController#stop")
|
701
|
+
end
|
702
|
+
|
703
|
+
it "should parse custom route for resource with explicit to and different action name" do
|
704
|
+
content =<<-EOF
|
705
|
+
RailsBestPracticesCom::Application.routes.draw do
|
706
|
+
resources :posts do
|
707
|
+
get :halt, to: 'posts#stop'
|
708
|
+
end
|
709
|
+
end
|
710
|
+
EOF
|
711
|
+
runner.prepare('config/routes.rb', content)
|
712
|
+
routes = Prepares.routes
|
713
|
+
expect(routes.last.to_s).to eq("PostsController#stop")
|
690
714
|
end
|
691
715
|
|
692
716
|
it "should not take former resources for direct get/post" do
|
@@ -698,7 +722,7 @@ module RailsBestPractices
|
|
698
722
|
EOF
|
699
723
|
runner.prepare('config/routes.rb', content)
|
700
724
|
routes = Prepares.routes
|
701
|
-
routes.last.to_s.
|
725
|
+
expect(routes.last.to_s).to eq("SprintsController#stop")
|
702
726
|
end
|
703
727
|
|
704
728
|
it "should not parse wrong route" do
|
@@ -709,7 +733,7 @@ module RailsBestPractices
|
|
709
733
|
EOF
|
710
734
|
runner.prepare('config/routes.rb', content)
|
711
735
|
routes = Prepares.routes
|
712
|
-
routes.size.
|
736
|
+
expect(routes.size).to eq(0)
|
713
737
|
end
|
714
738
|
end
|
715
739
|
end
|
@@ -20,12 +20,12 @@ module RailsBestPractices
|
|
20
20
|
EOF
|
21
21
|
runner.prepare("db/schema.rb", content)
|
22
22
|
model_attributes = Prepares.model_attributes
|
23
|
-
model_attributes.get_attribute_type("Post", "title").
|
24
|
-
model_attributes.get_attribute_type("Post", "body").
|
25
|
-
model_attributes.get_attribute_type("Post", "created_at").
|
26
|
-
model_attributes.get_attribute_type("Post", "user_id").
|
27
|
-
model_attributes.get_attribute_type("Post", "comments_count").
|
28
|
-
model_attributes.get_attribute_type("Post", "published").
|
23
|
+
expect(model_attributes.get_attribute_type("Post", "title")).to eq("string")
|
24
|
+
expect(model_attributes.get_attribute_type("Post", "body")).to eq("text")
|
25
|
+
expect(model_attributes.get_attribute_type("Post", "created_at")).to eq("datetime")
|
26
|
+
expect(model_attributes.get_attribute_type("Post", "user_id")).to eq("integer")
|
27
|
+
expect(model_attributes.get_attribute_type("Post", "comments_count")).to eq("integer")
|
28
|
+
expect(model_attributes.get_attribute_type("Post", "published")).to eq("boolean")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -17,8 +17,8 @@ module RailsBestPractices
|
|
17
17
|
end
|
18
18
|
EOF
|
19
19
|
runner.review('app/controllers/users_controller.rb', content)
|
20
|
-
runner.
|
21
|
-
runner.errors[0].to_s.
|
20
|
+
expect(runner.errors.size).to eq(1)
|
21
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/users_controller.rb:2 - add model virtual attribute (for @user)")
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should add model virtual attribute with local assignment" do
|
@@ -33,8 +33,8 @@ module RailsBestPractices
|
|
33
33
|
end
|
34
34
|
EOF
|
35
35
|
runner.review('app/controllers/users_controller.rb', content)
|
36
|
-
runner.
|
37
|
-
runner.errors[0].to_s.
|
36
|
+
expect(runner.errors.size).to eq(1)
|
37
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/users_controller.rb:2 - add model virtual attribute (for user)")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should not add model virtual attribute with differen param" do
|
@@ -49,7 +49,7 @@ module RailsBestPractices
|
|
49
49
|
end
|
50
50
|
EOF
|
51
51
|
runner.review('app/controllers/users_controller.rb', content)
|
52
|
-
runner.
|
52
|
+
expect(runner.errors.size).to eq(0)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not add model virtual attribute with read" do
|
@@ -65,7 +65,7 @@ module RailsBestPractices
|
|
65
65
|
end
|
66
66
|
EOF
|
67
67
|
runner.review('app/controllers/users_controller.rb', content)
|
68
|
-
runner.
|
68
|
+
expect(runner.errors.size).to eq(0)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should add model virtual attribute with two dimension params" do
|
@@ -80,8 +80,8 @@ module RailsBestPractices
|
|
80
80
|
end
|
81
81
|
EOF
|
82
82
|
runner.review('app/controllers/users_controller.rb', content)
|
83
|
-
runner.
|
84
|
-
runner.errors[0].to_s.
|
83
|
+
expect(runner.errors.size).to eq(1)
|
84
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/users_controller.rb:2 - add model virtual attribute (for @user)")
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should no add model virtual attribute with two dimension params" do
|
@@ -96,7 +96,23 @@ module RailsBestPractices
|
|
96
96
|
end
|
97
97
|
EOF
|
98
98
|
runner.review('app/controllers/users_controller.rb', content)
|
99
|
-
runner.
|
99
|
+
expect(runner.errors.size).to eq(0)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should not check ignored files" do
|
103
|
+
runner = Core::Runner.new(reviews: AddModelVirtualAttributeReview.new(ignored_files: /user/))
|
104
|
+
content = <<-EOF
|
105
|
+
class UsersController < ApplicationController
|
106
|
+
def create
|
107
|
+
@user = User.new(params[:user])
|
108
|
+
@user.first_name = params[:full_name].split(' ', 2).first
|
109
|
+
@user.last_name = params[:full_name].split(' ', 2).last
|
110
|
+
@user.save
|
111
|
+
end
|
112
|
+
end
|
113
|
+
EOF
|
114
|
+
runner.review('app/controllers/users_controller.rb', content)
|
115
|
+
expect(runner.errors.size).to eq(0)
|
100
116
|
end
|
101
117
|
end
|
102
118
|
end
|