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
@@ -21,9 +21,9 @@ module RailsBestPractices
|
|
21
21
|
EOF
|
22
22
|
runner.review('db/schema.rb', content)
|
23
23
|
runner.after_review
|
24
|
-
runner.
|
25
|
-
runner.errors[0].to_s.
|
26
|
-
runner.errors[1].to_s.
|
24
|
+
expect(runner.errors.size).to eq(2)
|
25
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (comments => [post_id])")
|
26
|
+
expect(runner.errors[1].to_s).to eq("db/schema.rb:2 - always add db index (comments => [user_id])")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should always add db index with polymorphic foreign key" do
|
@@ -38,8 +38,8 @@ module RailsBestPractices
|
|
38
38
|
EOF
|
39
39
|
runner.review('db/schema.rb', content)
|
40
40
|
runner.after_review
|
41
|
-
runner.
|
42
|
-
runner.errors[0].to_s.
|
41
|
+
expect(runner.errors.size).to eq(1)
|
42
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (versions => [versioned_id, versioned_type])")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should always add db index with polymorphic foreign key and _type is defined before _id" do
|
@@ -54,8 +54,8 @@ module RailsBestPractices
|
|
54
54
|
EOF
|
55
55
|
runner.review('db/schema.rb', content)
|
56
56
|
runner.after_review
|
57
|
-
runner.
|
58
|
-
runner.errors[0].to_s.
|
57
|
+
expect(runner.errors.size).to eq(1)
|
58
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (versions => [versioned_id, versioned_type])")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should always add db index with single index, but without polymorphic foreign key" do
|
@@ -74,8 +74,8 @@ module RailsBestPractices
|
|
74
74
|
EOF
|
75
75
|
runner.review('db/schema.rb', content)
|
76
76
|
runner.after_review
|
77
|
-
runner.
|
78
|
-
runner.errors[0].to_s.
|
77
|
+
expect(runner.errors.size).to eq(1)
|
78
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (taggings => [taggable_id, taggable_type])")
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should always add db index with polymorphic foreign key, but without single index" do
|
@@ -94,8 +94,8 @@ module RailsBestPractices
|
|
94
94
|
EOF
|
95
95
|
runner.review('db/schema.rb', content)
|
96
96
|
runner.after_review
|
97
|
-
runner.
|
98
|
-
runner.errors[0].to_s.
|
97
|
+
expect(runner.errors.size).to eq(1)
|
98
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (taggings => [tag_id])")
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should always add db index only _id without non related _type column" do
|
@@ -113,8 +113,8 @@ module RailsBestPractices
|
|
113
113
|
EOF
|
114
114
|
runner.review('db/schema.rb', content)
|
115
115
|
runner.after_review
|
116
|
-
runner.
|
117
|
-
runner.errors[0].to_s.
|
116
|
+
expect(runner.errors.size).to eq(1)
|
117
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (websites => [user_id])")
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should not always add db index with column has no id" do
|
@@ -128,7 +128,7 @@ module RailsBestPractices
|
|
128
128
|
EOF
|
129
129
|
runner.review('db/schema.rb', content)
|
130
130
|
runner.after_review
|
131
|
-
runner.
|
131
|
+
expect(runner.errors.size).to eq(0)
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should not always add db index with add_index" do
|
@@ -150,7 +150,7 @@ module RailsBestPractices
|
|
150
150
|
EOF
|
151
151
|
runner.review('db/schema.rb', content)
|
152
152
|
runner.after_review
|
153
|
-
runner.
|
153
|
+
expect(runner.errors.size).to eq(0)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should not always add db index with t.index" do
|
@@ -168,7 +168,7 @@ module RailsBestPractices
|
|
168
168
|
EOF
|
169
169
|
runner.review('db/schema.rb', content)
|
170
170
|
runner.after_review
|
171
|
-
runner.
|
171
|
+
expect(runner.errors.size).to eq(0)
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should not always add db index with only _type column" do
|
@@ -181,7 +181,7 @@ module RailsBestPractices
|
|
181
181
|
EOF
|
182
182
|
runner.review('db/schema.rb', content)
|
183
183
|
runner.after_review
|
184
|
-
runner.
|
184
|
+
expect(runner.errors.size).to eq(0)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should not always add db index with multi-column index" do
|
@@ -198,7 +198,7 @@ module RailsBestPractices
|
|
198
198
|
EOF
|
199
199
|
runner.review('db/schema.rb', content)
|
200
200
|
runner.after_review
|
201
|
-
runner.
|
201
|
+
expect(runner.errors.size).to eq(0)
|
202
202
|
end
|
203
203
|
|
204
204
|
it "should not always add db index if there is an index contains more columns" do
|
@@ -215,7 +215,7 @@ module RailsBestPractices
|
|
215
215
|
EOF
|
216
216
|
runner.review('db/schema.rb', content)
|
217
217
|
runner.after_review
|
218
|
-
runner.
|
218
|
+
expect(runner.errors.size).to eq(0)
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should not always add db index if two indexes for polymorphic association" do
|
@@ -233,7 +233,7 @@ module RailsBestPractices
|
|
233
233
|
EOF
|
234
234
|
runner.review('db/schema.rb', content)
|
235
235
|
runner.after_review
|
236
|
-
runner.
|
236
|
+
expect(runner.errors.size).to eq(0)
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should not always add db index if table does not exist" do
|
@@ -246,7 +246,7 @@ module RailsBestPractices
|
|
246
246
|
EOF
|
247
247
|
runner.review('db/schema.rb', content)
|
248
248
|
runner.after_review
|
249
|
-
runner.
|
249
|
+
expect(runner.errors.size).to eq(0)
|
250
250
|
end
|
251
251
|
|
252
252
|
it "should always add db index if association_name is different to foreign_key" do
|
@@ -272,8 +272,28 @@ module RailsBestPractices
|
|
272
272
|
EOF
|
273
273
|
runner.review('db/schema.rb', content)
|
274
274
|
runner.after_review
|
275
|
-
runner.
|
276
|
-
runner.errors[0].to_s.
|
275
|
+
expect(runner.errors.size).to eq(1)
|
276
|
+
expect(runner.errors[0].to_s).to eq("db/schema.rb:2 - always add db index (comments => [commentor_id])")
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should not check ignored files" do
|
280
|
+
runner = Core::Runner.new(reviews: AlwaysAddDbIndexReview.new(ignored_files: /db\/schema/))
|
281
|
+
content = <<-EOF
|
282
|
+
ActiveRecord::Schema.define(version: 20100603080629) do
|
283
|
+
create_table "comments", force: true do |t|
|
284
|
+
t.string "content"
|
285
|
+
t.integer "post_id"
|
286
|
+
t.integer "user_id"
|
287
|
+
end
|
288
|
+
create_table "posts", force: true do |t|
|
289
|
+
end
|
290
|
+
create_table "users", force: true do |t|
|
291
|
+
end
|
292
|
+
end
|
293
|
+
EOF
|
294
|
+
runner.review('db/schema.rb', content)
|
295
|
+
runner.after_review
|
296
|
+
expect(runner.errors.size).to eq(0)
|
277
297
|
end
|
278
298
|
end
|
279
299
|
end
|
@@ -16,8 +16,8 @@ module RailsBestPractices
|
|
16
16
|
end
|
17
17
|
EOF
|
18
18
|
runner.review('app/helpers/posts_helper.rb', content)
|
19
|
-
runner.
|
20
|
-
runner.errors[0].to_s.
|
19
|
+
expect(runner.errors.size).to eq(1)
|
20
|
+
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:5 - check 'save' return value or use 'save!'")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should allow save return value assigned to var" do
|
@@ -30,7 +30,7 @@ module RailsBestPractices
|
|
30
30
|
end
|
31
31
|
EOF
|
32
32
|
runner.review('app/helpers/posts_helper.rb', content)
|
33
|
-
runner.
|
33
|
+
expect(runner.errors.size).to eq(0)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should allow save return value used in if" do
|
@@ -47,7 +47,7 @@ module RailsBestPractices
|
|
47
47
|
end
|
48
48
|
EOF
|
49
49
|
runner.review('app/helpers/posts_helper.rb', content)
|
50
|
-
runner.
|
50
|
+
expect(runner.errors.size).to eq(0)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should allow save return value used in elsif" do
|
@@ -66,7 +66,7 @@ module RailsBestPractices
|
|
66
66
|
end
|
67
67
|
EOF
|
68
68
|
runner.review('app/helpers/posts_helper.rb', content)
|
69
|
-
runner.
|
69
|
+
expect(runner.errors.size).to eq(0)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should allow save return value used in unless" do
|
@@ -78,7 +78,7 @@ module RailsBestPractices
|
|
78
78
|
end
|
79
79
|
EOF
|
80
80
|
runner.review('app/helpers/posts_helper.rb', content)
|
81
|
-
runner.
|
81
|
+
expect(runner.errors.size).to eq(0)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should allow save return value used in if_mod" do
|
@@ -91,7 +91,7 @@ module RailsBestPractices
|
|
91
91
|
end
|
92
92
|
EOF
|
93
93
|
runner.review('app/helpers/posts_helper.rb', content)
|
94
|
-
expect(runner).to
|
94
|
+
expect(runner.errors.size).to eq(0)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should allow save return value used in unless_mod" do
|
@@ -104,7 +104,7 @@ module RailsBestPractices
|
|
104
104
|
end
|
105
105
|
EOF
|
106
106
|
runner.review('app/helpers/posts_helper.rb', content)
|
107
|
-
expect(runner).to
|
107
|
+
expect(runner.errors.size).to eq(0)
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should allow save return value used in unless with &&" do
|
@@ -116,7 +116,7 @@ module RailsBestPractices
|
|
116
116
|
end
|
117
117
|
EOF
|
118
118
|
runner.review('app/helpers/posts_helper.rb', content)
|
119
|
-
runner.
|
119
|
+
expect(runner.errors.size).to eq(0)
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should allow save!" do
|
@@ -129,7 +129,7 @@ module RailsBestPractices
|
|
129
129
|
end
|
130
130
|
EOF
|
131
131
|
runner.review('app/helpers/posts_helper.rb', content)
|
132
|
-
runner.
|
132
|
+
expect(runner.errors.size).to eq(0)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should warn you if you fail to check update_attributes return value" do
|
@@ -139,8 +139,8 @@ module RailsBestPractices
|
|
139
139
|
end
|
140
140
|
EOF
|
141
141
|
runner.review('app/helpers/posts_helper.rb', content)
|
142
|
-
runner.
|
143
|
-
runner.errors[0].to_s.
|
142
|
+
expect(runner.errors.size).to eq(1)
|
143
|
+
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:2 - check 'update_attributes' return value or use 'update_attributes!'")
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should allow update_attributes if return value is checked" do
|
@@ -150,7 +150,7 @@ module RailsBestPractices
|
|
150
150
|
end
|
151
151
|
EOF
|
152
152
|
runner.review('app/helpers/posts_helper.rb', content)
|
153
|
-
runner.
|
153
|
+
expect(runner.errors.size).to eq(0)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "is not clever enough to allow update_attributes if value is returned from method" do
|
@@ -173,8 +173,8 @@ module RailsBestPractices
|
|
173
173
|
end
|
174
174
|
EOF
|
175
175
|
runner.review('app/controllers/posts_controller.rb', content)
|
176
|
-
runner.
|
177
|
-
runner.errors[0].to_s.
|
176
|
+
expect(runner.errors.size).to eq(1)
|
177
|
+
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:12 - check 'update_attributes' return value or use 'update_attributes!'")
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should warn you if you use create which is always unsafe" do
|
@@ -192,8 +192,8 @@ module RailsBestPractices
|
|
192
192
|
end
|
193
193
|
EOF
|
194
194
|
runner.review('app/helpers/posts_helper.rb', content)
|
195
|
-
runner.
|
196
|
-
runner.errors[0].to_s.
|
195
|
+
expect(runner.errors.size).to eq(1)
|
196
|
+
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:2 - use 'create!' instead of 'create' as the latter may not always save")
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should warn you if you use create with a block which is always unsafe" do
|
@@ -220,8 +220,8 @@ module RailsBestPractices
|
|
220
220
|
end
|
221
221
|
EOF
|
222
222
|
runner.review('app/helpers/blog/posts_helper.rb', content)
|
223
|
-
runner.
|
224
|
-
runner.errors[0].to_s.
|
223
|
+
expect(runner.errors.size).to eq(1)
|
224
|
+
expect(runner.errors[0].to_s).to eq("app/helpers/blog/posts_helper.rb:4 - use 'create!' instead of 'create' as the latter may not always save")
|
225
225
|
end
|
226
226
|
|
227
227
|
it "allows create called on non-model classes" do
|
@@ -235,9 +235,23 @@ module RailsBestPractices
|
|
235
235
|
end
|
236
236
|
EOF
|
237
237
|
runner.review('app/helpers/posts_helper.rb', content)
|
238
|
-
runner.errors.map(&:to_s).
|
238
|
+
expect(runner.errors.map(&:to_s)).to eq([])
|
239
239
|
end
|
240
240
|
end
|
241
|
+
|
242
|
+
it "should not check ignored files" do
|
243
|
+
runner = Core::Runner.new(reviews: CheckSaveReturnValueReview.new(ignored_files: /helpers/))
|
244
|
+
content =<<-EOF
|
245
|
+
def my_method
|
246
|
+
post = Posts.new do |p|
|
247
|
+
p.title = "foo"
|
248
|
+
end
|
249
|
+
post.save
|
250
|
+
end
|
251
|
+
EOF
|
252
|
+
runner.review('app/helpers/posts_helper.rb', content)
|
253
|
+
expect(runner.errors.size).to eq(0)
|
254
|
+
end
|
241
255
|
end
|
242
256
|
end
|
243
257
|
end
|
@@ -12,8 +12,8 @@ module RailsBestPractices
|
|
12
12
|
end
|
13
13
|
EOF
|
14
14
|
runner.review('app/models/user.rb', content)
|
15
|
-
runner.
|
16
|
-
runner.errors[0].to_s.
|
15
|
+
expect(runner.errors.size).to eq(1)
|
16
|
+
expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - default_scope is evil")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should detect default_scope with old syntax" do
|
@@ -23,8 +23,8 @@ module RailsBestPractices
|
|
23
23
|
end
|
24
24
|
EOF
|
25
25
|
runner.review('app/models/user.rb', content)
|
26
|
-
runner.
|
27
|
-
runner.errors[0].to_s.
|
26
|
+
expect(runner.errors.size).to eq(1)
|
27
|
+
expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - default_scope is evil")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not detect default_scope" do
|
@@ -34,7 +34,18 @@ module RailsBestPractices
|
|
34
34
|
end
|
35
35
|
EOF
|
36
36
|
runner.review('app/models/user.rb', content)
|
37
|
-
runner.
|
37
|
+
expect(runner.errors.size).to eq(0)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not check ignored files" do
|
41
|
+
runner = Core::Runner.new(reviews: DefaultScopeIsEvilReview.new(ignored_files: /user/))
|
42
|
+
content = <<-EOF
|
43
|
+
class User < ActiveRecord::Base
|
44
|
+
default_scope -> { order('created_at desc') }
|
45
|
+
end
|
46
|
+
EOF
|
47
|
+
runner.review('app/models/user.rb', content)
|
48
|
+
expect(runner.errors.size).to eq(0)
|
38
49
|
end
|
39
50
|
end
|
40
51
|
end
|
@@ -23,8 +23,8 @@ module RailsBestPractices
|
|
23
23
|
after 'deploy:update_code', 'bundler:bundle_new_release'
|
24
24
|
EOF
|
25
25
|
runner.review('config/deploy.rb', content)
|
26
|
-
runner.
|
27
|
-
runner.errors[0].to_s.
|
26
|
+
expect(runner.errors.size).to eq(1)
|
27
|
+
expect(runner.errors[0].to_s).to eq("config/deploy.rb:1 - dry bundler in capistrano")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not dry bundler in capistrano" do
|
@@ -32,7 +32,29 @@ module RailsBestPractices
|
|
32
32
|
require 'bundler/capistrano'
|
33
33
|
EOF
|
34
34
|
runner.review('config/deploy.rb', content)
|
35
|
-
runner.
|
35
|
+
expect(runner.errors.size).to eq(0)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not check ignored files" do
|
39
|
+
runner = Core::Runner.new(reviews: DryBundlerInCapistranoReview.new(ignored_files: /deploy\.rb/))
|
40
|
+
content = <<-EOF
|
41
|
+
namespace :bundler do
|
42
|
+
task :create_symlink, roles: :app do
|
43
|
+
shared_dir = File.join(shared_path, 'bundle')
|
44
|
+
release_dir = File.join(current_release, '.bundle')
|
45
|
+
run("mkdir -p \#{shared_dir} && ln -s \#{shared_dir} \#{release_dir}")
|
46
|
+
end
|
47
|
+
|
48
|
+
task :bundle_new_release, roles: :app do
|
49
|
+
bundler.create_symlink
|
50
|
+
run "cd \#{release_path} && bundle install --without development test"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
after 'deploy:update_code', 'bundler:bundle_new_release'
|
55
|
+
EOF
|
56
|
+
runner.review('config/deploy.rb', content)
|
57
|
+
expect(runner.errors.size).to eq(0)
|
36
58
|
end
|
37
59
|
end
|
38
60
|
end
|
@@ -12,8 +12,8 @@ module RailsBestPractices
|
|
12
12
|
end
|
13
13
|
EOF
|
14
14
|
runner.review('app/models/user.rb', content)
|
15
|
-
runner.
|
16
|
-
runner.errors[0].to_s.
|
15
|
+
expect(runner.errors.size).to eq(1)
|
16
|
+
expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - change Hash Syntax to 1.9")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should not find 1.8 Hash with string" do
|
@@ -23,7 +23,7 @@ module RailsBestPractices
|
|
23
23
|
end
|
24
24
|
EOF
|
25
25
|
runner.review('app/models/user.rb', content)
|
26
|
-
runner.
|
26
|
+
expect(runner.errors.size).to eq(0)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should not alert on 1.9 Syntax" do
|
@@ -33,7 +33,7 @@ module RailsBestPractices
|
|
33
33
|
end
|
34
34
|
EOF
|
35
35
|
runner.review('app/models/user.rb', content)
|
36
|
-
runner.
|
36
|
+
expect(runner.errors.size).to eq(0)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should ignore haml_out" do
|
@@ -43,7 +43,7 @@ module RailsBestPractices
|
|
43
43
|
#div{ class: "foo3" }
|
44
44
|
EOF
|
45
45
|
runner.review('app/views/files/show.html.haml', content)
|
46
|
-
runner.
|
46
|
+
expect(runner.errors.size).to eq(0)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should not consider hash with array key" do
|
@@ -51,7 +51,7 @@ module RailsBestPractices
|
|
51
51
|
transition [:unverified, :verified] => :deleted
|
52
52
|
EOF
|
53
53
|
runner.review('app/models/post.rb', content)
|
54
|
-
runner.
|
54
|
+
expect(runner.errors.size).to eq(0)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should not consider hash with charaters not valid for symbol" do
|
@@ -59,7 +59,18 @@ module RailsBestPractices
|
|
59
59
|
receiver.stub(:` => 'Error')
|
60
60
|
EOF
|
61
61
|
runner.review('app/models/post.rb', content)
|
62
|
-
runner.
|
62
|
+
expect(runner.errors.size).to eq(0)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not check ignored files" do
|
66
|
+
runner = Core::Runner.new(reviews: HashSyntaxReview.new(ignored_files: /user/))
|
67
|
+
content =<<-EOF
|
68
|
+
class User < ActiveRecord::Base
|
69
|
+
CONST = { :foo => :bar }
|
70
|
+
end
|
71
|
+
EOF
|
72
|
+
runner.review('app/models/user.rb', content)
|
73
|
+
expect(runner.errors.size).to eq(0)
|
63
74
|
end
|
64
75
|
end
|
65
76
|
end
|
@@ -25,8 +25,8 @@ module RailsBestPractices
|
|
25
25
|
end
|
26
26
|
EOF
|
27
27
|
runner.review('db/migrate/20090818130258_create_roles.rb', content)
|
28
|
-
runner.
|
29
|
-
runner.errors[0].to_s.
|
28
|
+
expect(runner.errors.size).to eq(1)
|
29
|
+
expect(runner.errors[0].to_s).to eq("db/migrate/20090818130258_create_roles.rb:8 - isolate seed data")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -51,8 +51,8 @@ module RailsBestPractices
|
|
51
51
|
end
|
52
52
|
EOF
|
53
53
|
runner.review('db/migrate/20090818130258_create_roles.rb', content)
|
54
|
-
runner.
|
55
|
-
runner.errors[0].to_s.
|
54
|
+
expect(runner.errors.size).to eq(1)
|
55
|
+
expect(runner.errors[0].to_s).to eq("db/migrate/20090818130258_create_roles.rb:9 - isolate seed data")
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should isolate seed data for instance variable" do
|
@@ -75,8 +75,8 @@ module RailsBestPractices
|
|
75
75
|
end
|
76
76
|
EOF
|
77
77
|
runner.review('db/migrate/20090818130258_create_roles.rb', content)
|
78
|
-
runner.
|
79
|
-
runner.errors[0].to_s.
|
78
|
+
expect(runner.errors.size).to eq(1)
|
79
|
+
expect(runner.errors[0].to_s).to eq("db/migrate/20090818130258_create_roles.rb:9 - isolate seed data")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -95,7 +95,30 @@ module RailsBestPractices
|
|
95
95
|
end
|
96
96
|
EOF
|
97
97
|
runner.review('db/migrate/20090818130258_create_roles.rb', content)
|
98
|
-
runner.
|
98
|
+
expect(runner.errors.size).to eq(0)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should not check ignored files" do
|
102
|
+
runner = Core::Runner.new(reviews: IsolateSeedDataReview.new(ignored_files: /create_roles/))
|
103
|
+
content = <<-EOF
|
104
|
+
class CreateRoles < ActiveRecord::Migration
|
105
|
+
def self.up
|
106
|
+
create_table "roles", force: true do |t|
|
107
|
+
t.string :name
|
108
|
+
end
|
109
|
+
|
110
|
+
["admin", "author", "editor", "account"].each do |name|
|
111
|
+
Role.create!(name: name)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.down
|
116
|
+
drop_table "roles"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
EOF
|
120
|
+
runner.review('db/migrate/20090818130258_create_roles.rb', content)
|
121
|
+
expect(runner.errors.size).to eq(0)
|
99
122
|
end
|
100
123
|
end
|
101
124
|
end
|
@@ -17,8 +17,8 @@ module RailsBestPractices
|
|
17
17
|
end
|
18
18
|
EOF
|
19
19
|
runner.review('app/models/post.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/models/post.rb:5 - keep finders on their own model")
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should keep finders on thier own model with all method" do
|
@@ -33,8 +33,8 @@ module RailsBestPractices
|
|
33
33
|
end
|
34
34
|
EOF
|
35
35
|
runner.review('app/models/post.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/models/post.rb:5 - keep finders on their own model")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should not keep finders on thier own model with self finder" do
|
@@ -49,7 +49,7 @@ module RailsBestPractices
|
|
49
49
|
end
|
50
50
|
EOF
|
51
51
|
runner.review('app/models/post.rb', content)
|
52
|
-
runner.
|
52
|
+
expect(runner.errors.size).to eq(0)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not keep finders on thier own model with own finder" do
|
@@ -64,7 +64,7 @@ module RailsBestPractices
|
|
64
64
|
end
|
65
65
|
EOF
|
66
66
|
runner.review('app/models/post.rb', content)
|
67
|
-
runner.
|
67
|
+
expect(runner.errors.size).to eq(0)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should not keep finders on their own model without finder" do
|
@@ -78,7 +78,7 @@ module RailsBestPractices
|
|
78
78
|
end
|
79
79
|
EOF
|
80
80
|
runner.review('app/models/post.rb', content)
|
81
|
-
runner.
|
81
|
+
expect(runner.errors.size).to eq(0)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should not keep finders on their own model with ruby Array#find" do
|
@@ -92,7 +92,23 @@ module RailsBestPractices
|
|
92
92
|
end
|
93
93
|
EOF
|
94
94
|
runner.review('app/models/post.rb', content)
|
95
|
-
runner.
|
95
|
+
expect(runner.errors.size).to eq(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not check ignored files" do
|
99
|
+
runner = Core::Runner.new(reviews: KeepFindersOnTheirOwnModelReview.new(ignored_files: /app\/models\/post\.rb/))
|
100
|
+
content = <<-EOF
|
101
|
+
class Post < ActiveRecord::Base
|
102
|
+
has_many :comments
|
103
|
+
|
104
|
+
def find_valid_comments
|
105
|
+
self.comment.find(:all, conditions: { is_spam: false },
|
106
|
+
limit: 10)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
EOF
|
110
|
+
runner.review('app/models/post.rb', content)
|
111
|
+
expect(runner.errors.size).to eq(0)
|
96
112
|
end
|
97
113
|
end
|
98
114
|
end
|