rails_best_practices 1.15.4 → 1.15.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/Gemfile +1 -0
- data/README.md +4 -4
- data/assets/result.html.erb +27 -2
- data/lib/rails_best_practices/analyzer.rb +33 -1
- data/lib/rails_best_practices/command.rb +2 -2
- data/lib/rails_best_practices/prepares/route_prepare.rb +1 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +2 -2
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -2
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_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 +2 -2
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +2 -2
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +2 -2
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -2
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -2
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -2
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -2
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +2 -2
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -2
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -3
- data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -3
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +2 -2
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -2
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +3 -3
- 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 +2 -3
- data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -3
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -2
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -1
- data/spec/rails_best_practices/analyzer_spec.rb +10 -0
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +4 -3
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +10 -10
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 226e897e70ff9eef8f71618f89f0477e251b98b6
|
4
|
+
data.tar.gz: d306ab46262bb3b6cc11efa62c3d46b5ef12a056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a22ae71b9e6b399c29987eb78a0ca19046b2823a2853e82b9e6b6772403daa1e6192b9f68330fefb658800c12547ac49cb0874d3fa615b14bd78a33e25d0f8e
|
7
|
+
data.tar.gz: 80cb58e6262aa89f8781c8cfd8cd37b92131c247d2a8d2c114453a3f370b3969e507f458b946a08bf3a6bac7bf029c9b343642a53c15997197a01e1f0a90b967
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[](http://coderwall.com/flyerhzm)
|
8
8
|
[](https://pledgie.com/campaigns/12057)
|
9
9
|
|
10
|
-
rails_best_practices is a code metric tool to check the quality of rails
|
10
|
+
rails_best_practices is a code metric tool to check the quality of rails code.
|
11
11
|
|
12
12
|
it supports following ORM/ODMs:
|
13
13
|
|
@@ -40,14 +40,14 @@ or html output
|
|
40
40
|
|
41
41
|
rails_best_practices -f html .
|
42
42
|
|
43
|
-
By default rails_best_practices will do parse codes in vendor, spec, test and features directories.
|
43
|
+
By default rails_best_practices will do parse codes in vendor, spec, test and features directories.
|
44
44
|
|
45
45
|
### Excluding folders
|
46
46
|
|
47
47
|
To exclude folder simply call it with -e or --exclude
|
48
48
|
|
49
49
|
rails_best_practices -e "db/migrate" .
|
50
|
-
|
50
|
+
|
51
51
|
To exclude multiple folders, separate them with comma
|
52
52
|
|
53
53
|
rails_best_practices -e "db/migrate,vendor" .
|
@@ -57,7 +57,7 @@ To exclude multiple folders, separate them with comma
|
|
57
57
|
To see full list of commandline options call:
|
58
58
|
|
59
59
|
$ rails_best_practices -h
|
60
|
-
|
60
|
+
|
61
61
|
Usage: rails_best_practices [options]
|
62
62
|
-d, --debug Debug mode
|
63
63
|
-f, --format FORMAT output format
|
data/assets/result.html.erb
CHANGED
@@ -47,6 +47,9 @@
|
|
47
47
|
display: none;
|
48
48
|
float: left;
|
49
49
|
}
|
50
|
+
.result tbody tr{
|
51
|
+
display: none;
|
52
|
+
}
|
50
53
|
</style>
|
51
54
|
<%
|
52
55
|
def columnize(arr, col_count)
|
@@ -140,23 +143,45 @@
|
|
140
143
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
141
144
|
<script type="text/javascript">
|
142
145
|
$(function() {
|
143
|
-
|
144
|
-
|
146
|
+
|
147
|
+
keys = location.hash.slice(2).split("|");
|
148
|
+
keys = keys.filter(function(item){
|
149
|
+
return item != "";
|
150
|
+
});
|
151
|
+
keys.forEach(function(item){
|
152
|
+
$('.'+item).show();
|
153
|
+
$('input.error-type#'+item+'[type=checkbox]').prop('checked', true);
|
154
|
+
});
|
155
|
+
|
156
|
+
$('input.error-type[type=checkbox]').click(function() {
|
145
157
|
if ($(this).attr('checked')) {
|
146
158
|
$(this).prop('checked', true);
|
147
159
|
$('.'+$(this).val()).show();
|
160
|
+
|
161
|
+
new_hash = location.hash.replace("|"+$(this).val().toString(), "");
|
162
|
+
location.hash = new_hash+"|"+$(this).val();
|
148
163
|
} else {
|
149
164
|
$(this).prop('checked', false);
|
150
165
|
$('.'+$(this).val()).hide();
|
166
|
+
|
167
|
+
new_hash = location.hash.replace("|"+$(this).val().toString(), "");
|
168
|
+
location.hash = new_hash
|
151
169
|
}
|
152
170
|
});
|
171
|
+
|
153
172
|
$('#show-all').click(function() {
|
173
|
+
$('input.error-type[type=checkbox]').each(function(index, item){
|
174
|
+
new_hash = location.hash.replace("|"+$(item).val().toString(), "");
|
175
|
+
location.hash = new_hash+"|"+$(item).val();
|
176
|
+
});
|
154
177
|
$('input.error-type[type=checkbox]').prop('checked', true);
|
155
178
|
$('table.result tbody tr').show();
|
156
179
|
});
|
180
|
+
|
157
181
|
$('#show-none').click(function() {
|
158
182
|
$('input.error-type[type=checkbox]').prop('checked', false);
|
159
183
|
$('table.result tbody tr').hide();
|
184
|
+
location.hash = "";
|
160
185
|
});
|
161
186
|
});
|
162
187
|
</script>
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'ap'
|
3
2
|
require 'colored'
|
4
3
|
require 'fileutils'
|
5
4
|
require 'json'
|
@@ -70,6 +69,9 @@ module RailsBestPractices
|
|
70
69
|
when "yaml"
|
71
70
|
@options["output-file"] ||= "rails_best_practices_output.yaml"
|
72
71
|
output_yaml_errors
|
72
|
+
when "xml"
|
73
|
+
@options["output-file"] ||= "rails_best_practices_output.xml"
|
74
|
+
output_xml_errors
|
73
75
|
else
|
74
76
|
output_terminal_errors
|
75
77
|
end
|
@@ -246,6 +248,36 @@ module RailsBestPractices
|
|
246
248
|
end
|
247
249
|
end
|
248
250
|
|
251
|
+
def output_xml_errors
|
252
|
+
require 'rexml/document'
|
253
|
+
|
254
|
+
document = REXML::Document.new.tap do |d|
|
255
|
+
d << REXML::XMLDecl.new
|
256
|
+
end
|
257
|
+
|
258
|
+
checkstyle = REXML::Element.new('checkstyle', document)
|
259
|
+
|
260
|
+
errors.group_by(&:filename).each do |file, group|
|
261
|
+
REXML::Element.new('file', checkstyle).tap do |f|
|
262
|
+
f.attributes['name'] = file
|
263
|
+
group.each do |error|
|
264
|
+
REXML::Element.new('error', f).tap do |e|
|
265
|
+
e.attributes['line'] = error.line_number
|
266
|
+
e.attributes['column'] = 0
|
267
|
+
e.attributes['severity'] = 'error'
|
268
|
+
e.attributes['message'] = error.message
|
269
|
+
e.attributes['source'] = 'com.puppycrawl.tools.checkstyle.' + error.type
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
formatter = REXML::Formatters::Default.new
|
276
|
+
File.open(@options["output-file"], 'w+') do |result|
|
277
|
+
formatter.write(document, result)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
249
281
|
# output errors with yaml format.
|
250
282
|
def output_yaml_errors
|
251
283
|
File.open(@options["output-file"], "w+") do |file|
|
@@ -4,7 +4,7 @@ require "optparse"
|
|
4
4
|
# Usage: rails_best_practices [options] path
|
5
5
|
# -d, --debug debug mode
|
6
6
|
# --silent silent mode
|
7
|
-
# -f, --format FORMAT output format (text, html, yml, json)
|
7
|
+
# -f, --format FORMAT output format (text, html, yml, json, xml)
|
8
8
|
# --output-file FILE output html file for the analyzing result
|
9
9
|
# --without-color only output plain text without color
|
10
10
|
# --with-textmate open file by textmate in html format
|
@@ -35,7 +35,7 @@ OptionParser.new do |opts|
|
|
35
35
|
options["debug"] = true
|
36
36
|
end
|
37
37
|
|
38
|
-
opts.on("-f", "--format FORMAT", "output format (text, html, yml, json)") do |format|
|
38
|
+
opts.on("-f", "--format FORMAT", "output format (text, html, yml, json, xml)") do |format|
|
39
39
|
options["format"] = format
|
40
40
|
end
|
41
41
|
|
@@ -22,7 +22,7 @@ module RailsBestPractices
|
|
22
22
|
add_resources_routes(node)
|
23
23
|
when "resource"
|
24
24
|
add_resource_routes(node)
|
25
|
-
when "get", "post", "put", "delete"
|
25
|
+
when "get", "post", "put", "patch", "delete"
|
26
26
|
first_argument = node.arguments.all.first
|
27
27
|
second_argument = node.arguments.all[1]
|
28
28
|
if @controller_names.last
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to add a model virual attribute to simplify model creation.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/21/add-model-virtual-attribute/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class AddModelVirtualAttributeReview < Review
|
17
17
|
interesting_nodes :def
|
18
18
|
interesting_files CONTROLLER_FILES
|
19
|
-
url "http://rails-bestpractices.com/posts/
|
19
|
+
url "http://rails-bestpractices.com/posts/2010/07/21/add-model-virtual-attribute/"
|
20
20
|
|
21
21
|
# check method define nodes to see if there are some attribute assignments that can use model virtual attribute instead in review process.
|
22
22
|
#
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review db/schema.rb file to make sure every reference key has a database index.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/always-add-db-index/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -24,7 +24,7 @@ module RailsBestPractices
|
|
24
24
|
class AlwaysAddDbIndexReview < Review
|
25
25
|
interesting_nodes :command, :command_call
|
26
26
|
interesting_files SCHEMA_FILE
|
27
|
-
url "http://rails-bestpractices.com/posts/
|
27
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/always-add-db-index/"
|
28
28
|
|
29
29
|
def initialize(options={})
|
30
30
|
super(options)
|
@@ -4,7 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review all code to make sure we either check the return value of "save"
|
5
5
|
# or use "save!"
|
6
6
|
#
|
7
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
7
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2012/11/02/check-the-return-value-of-save-otherwise-use-save/
|
8
8
|
#
|
9
9
|
# Implementation:
|
10
10
|
#
|
@@ -15,7 +15,7 @@ module RailsBestPractices
|
|
15
15
|
include Classable
|
16
16
|
interesting_nodes :call, :command_call, :method_add_arg, :if, :ifop, :elsif, :unless, :if_mod, :unless_mod, :assign, :binary
|
17
17
|
interesting_files ALL_FILES
|
18
|
-
url "http://rails-bestpractices.com/posts/
|
18
|
+
url "http://rails-bestpractices.com/posts/2012/11/02/check-the-return-value-of-save-otherwise-use-save/"
|
19
19
|
|
20
20
|
add_callback :start_if, :start_ifop, :start_elsif, :start_unless, :start_if_mod, :start_unless_mod do |node|
|
21
21
|
@used_return_value_of = node.conditional_statement.all_conditions
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review model files to make sure not use default_scope
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2013/06/15/default_scope-is-evil/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class DefaultScopeIsEvilReview < Review
|
13
13
|
interesting_nodes :command
|
14
14
|
interesting_files MODEL_FILES
|
15
|
-
url "http://rails-bestpractices.com/posts/
|
15
|
+
url "http://rails-bestpractices.com/posts/2013/06/15/default_scope-is-evil/"
|
16
16
|
|
17
17
|
# check all command nodes' message
|
18
18
|
add_callback :start_command do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review config/deploy.rb file to make sure using the bundler's capistrano recipe.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/09/02/dry-bundler-in-capistrano/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -15,7 +15,7 @@ module RailsBestPractices
|
|
15
15
|
class DryBundlerInCapistranoReview < Review
|
16
16
|
interesting_nodes :command
|
17
17
|
interesting_files DEPLOY_FILES
|
18
|
-
url "http://rails-bestpractices.com/posts/
|
18
|
+
url "http://rails-bestpractices.com/posts/2010/09/02/dry-bundler-in-capistrano/"
|
19
19
|
|
20
20
|
# check call node to see if it is with message "namespace" and argument "bundler".
|
21
21
|
add_callback :start_command do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure not to insert data in migration, move them to seed file.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/isolating-seed-data/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -21,7 +21,7 @@ module RailsBestPractices
|
|
21
21
|
class IsolateSeedDataReview < Review
|
22
22
|
interesting_nodes :call, :assign
|
23
23
|
interesting_files MIGRATION_FILES
|
24
|
-
url "http://rails-bestpractices.com/posts/
|
24
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/isolating-seed-data/"
|
25
25
|
|
26
26
|
def initialize(options={})
|
27
27
|
super(options)
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review model files to make sure finders are on their own model.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/23/keep-finders-on-their-own-model/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -17,7 +17,7 @@ module RailsBestPractices
|
|
17
17
|
class KeepFindersOnTheirOwnModelReview < Review
|
18
18
|
interesting_nodes :method_add_arg
|
19
19
|
interesting_files MODEL_FILES
|
20
|
-
url "http://rails-bestpractices.com/posts/
|
20
|
+
url "http://rails-bestpractices.com/posts/2010/07/23/keep-finders-on-their-own-model/"
|
21
21
|
|
22
22
|
FINDERS = %w(find all first last)
|
23
23
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review to make sure not to avoid the law of demeter.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/the-law-of-demeter/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class LawOfDemeterReview < Review
|
17
17
|
interesting_nodes :call
|
18
18
|
interesting_files ALL_FILES
|
19
|
-
url "http://rails-bestpractices.com/posts/
|
19
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/the-law-of-demeter/"
|
20
20
|
|
21
21
|
ASSOCIATION_METHODS = %w(belongs_to has_one)
|
22
22
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a view file to make sure there is no finder, finder should be moved to controller.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/24
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/move-code-into-controller/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class MoveCodeIntoControllerReview < Review
|
13
13
|
interesting_nodes :method_add_arg, :assign
|
14
14
|
interesting_files VIEW_FILES
|
15
|
-
url "http://rails-bestpractices.com/posts/24
|
15
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/move-code-into-controller/"
|
16
16
|
|
17
17
|
FINDERS = %w(find all first last)
|
18
18
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a view file to make sure there is no complex options_for_select message call.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/move-code-into-helper/
|
7
7
|
#
|
8
8
|
# TODO: we need a better soluation, any suggestion?
|
9
9
|
#
|
@@ -19,7 +19,7 @@ module RailsBestPractices
|
|
19
19
|
class MoveCodeIntoHelperReview < Review
|
20
20
|
interesting_nodes :method_add_arg
|
21
21
|
interesting_files VIEW_FILES
|
22
|
-
url "http://rails-bestpractices.com/posts/
|
22
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/move-code-into-helper/"
|
23
23
|
|
24
24
|
def initialize(options = {})
|
25
25
|
super(options)
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a view file to make sure there is no complex logic call for model.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/move-code-into-model/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class MoveCodeIntoModelReview < Review
|
14
14
|
interesting_nodes :if, :unless, :elsif, :ifop, :if_mod, :unless_mod
|
15
15
|
interesting_files VIEW_FILES
|
16
|
-
url "http://rails-bestpractices.com/posts/
|
16
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/move-code-into-model/"
|
17
17
|
|
18
18
|
def initialize(options={})
|
19
19
|
super(options)
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a controller file to make sure there are no complex finder.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/14/move-finder-to-named_scope/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -15,7 +15,7 @@ module RailsBestPractices
|
|
15
15
|
class MoveFinderToNamedScopeReview < Review
|
16
16
|
interesting_nodes :method_add_arg
|
17
17
|
interesting_files CONTROLLER_FILES
|
18
|
-
url "http://rails-bestpractices.com/posts/
|
18
|
+
url "http://rails-bestpractices.com/posts/2010/07/14/move-finder-to-named_scope/"
|
19
19
|
|
20
20
|
FINDERS = %w(find all first last)
|
21
21
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a controller file to make sure that complex model logic should not exist in controller, should be moved into a model.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/21/move-model-logic-into-the-model/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -15,7 +15,7 @@ module RailsBestPractices
|
|
15
15
|
class MoveModelLogicIntoModelReview < Review
|
16
16
|
interesting_nodes :def
|
17
17
|
interesting_files CONTROLLER_FILES
|
18
|
-
url "http://rails-bestpractices.com/posts/
|
18
|
+
url "http://rails-bestpractices.com/posts/2010/07/21/move-model-logic-into-the-model/"
|
19
19
|
|
20
20
|
def initialize(options = {})
|
21
21
|
super(options)
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review config/routes.rb file to make sure not to use too deep nesting routes.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/22/needless-deep-nesting/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -24,7 +24,7 @@ module RailsBestPractices
|
|
24
24
|
class NeedlessDeepNestingReview < Review
|
25
25
|
interesting_nodes :method_add_block
|
26
26
|
interesting_files ROUTE_FILES
|
27
|
-
url "http://rails-bestpractices.com/posts/
|
27
|
+
url "http://rails-bestpractices.com/posts/2010/07/22/needless-deep-nesting/"
|
28
28
|
|
29
29
|
def initialize(options = {})
|
30
30
|
super(options)
|
@@ -4,7 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review all code to make sure we don't rescue Exception
|
5
5
|
# This is a common mistake by Java or C# devs in ruby.
|
6
6
|
#
|
7
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
7
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2012/11/01/don-t-rescue-exception-rescue-standarderror/
|
8
8
|
#
|
9
9
|
# Implementation:
|
10
10
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class NotRescueExceptionReview < Review
|
14
14
|
interesting_nodes :rescue
|
15
15
|
interesting_files ALL_FILES
|
16
|
-
url "http://rails-bestpractices.com/posts/
|
16
|
+
url "http://rails-bestpractices.com/posts/2012/11/01/don-t-rescue-exception-rescue-standarderror/"
|
17
17
|
|
18
18
|
# check rescue node to see if its type is Exception
|
19
19
|
add_callback :start_rescue do |rescue_node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review config/routes file to make sure not use default route that rails generated.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/22/not-use-default-route-if-you-use-restful-design/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -19,7 +19,7 @@ module RailsBestPractices
|
|
19
19
|
class NotUseDefaultRouteReview < Review
|
20
20
|
interesting_nodes :command_call, :command
|
21
21
|
interesting_files ROUTE_FILES
|
22
|
-
url "http://rails-bestpractices.com/posts/
|
22
|
+
url "http://rails-bestpractices.com/posts/2010/07/22/not-use-default-route-if-you-use-restful-design/"
|
23
23
|
|
24
24
|
# check all command call nodes, compare with rails2 default route
|
25
25
|
add_callback :start_command_call do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review view and helper files to make sure not use time_ago_in_words or distance_of_time_in_words_to_now.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2012/02/10/not-use-time_ago_in_words/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class NotUseTimeAgoInWordsReview < Review
|
13
13
|
interesting_nodes :fcall
|
14
14
|
interesting_files VIEW_FILES, HELPER_FILES
|
15
|
-
url "http://rails-bestpractices.com/posts/
|
15
|
+
url "http://rails-bestpractices.com/posts/2012/02/10/not-use-time_ago_in_words/"
|
16
16
|
|
17
17
|
# check fcall node to see if its message is time_ago_in_words or distance_of_time_in_words_to_now
|
18
18
|
add_callback :start_fcall do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review config/routes.rb file to make sure there are no overuse route customizations.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/22/overuse-route-customizations/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -28,7 +28,7 @@ module RailsBestPractices
|
|
28
28
|
class OveruseRouteCustomizationsReview < Review
|
29
29
|
interesting_nodes :command_call, :method_add_block
|
30
30
|
interesting_files ROUTE_FILES
|
31
|
-
url "http://rails-bestpractices.com/posts/
|
31
|
+
url "http://rails-bestpractices.com/posts/2010/07/22/overuse-route-customizations/"
|
32
32
|
|
33
33
|
VERBS = %w(get post update delete)
|
34
34
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review model files to make sure to use attr_accessible, attr_protected or strong_parameters to protect mass assignment.
|
5
5
|
#
|
6
|
-
# See the best practices details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practices details here http://rails-bestpractices.com/posts/2012/03/06/protect-mass-assignment/
|
7
7
|
#
|
8
8
|
# Implmentation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class ProtectMassAssignmentReview < Review
|
14
14
|
interesting_files MODEL_FILES
|
15
15
|
interesting_nodes :class, :command, :var_ref, :vcall, :fcall
|
16
|
-
url "http://rails-bestpractices.com/posts/
|
16
|
+
url "http://rails-bestpractices.com/posts/2012/03/06/protect-mass-assignment/"
|
17
17
|
|
18
18
|
# we treat it as mass assignment by default.
|
19
19
|
add_callback :start_class do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a helper file to make sure it is not an empty moduel.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2011/04/09/remove-empty-helpers/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class RemoveEmptyHelpersReview < Review
|
13
13
|
interesting_nodes :module
|
14
14
|
interesting_files HELPER_FILES
|
15
|
-
url "http://rails-bestpractices.com/posts/
|
15
|
+
url "http://rails-bestpractices.com/posts/2011/04/09/remove-empty-helpers/"
|
16
16
|
|
17
17
|
# check the body of module node, if it is nil, then it should be removed.
|
18
18
|
add_callback :start_module do |module_node|
|
data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb
CHANGED
@@ -4,8 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review a controller file to make sure that complex model creation should not exist in
|
5
5
|
# controller, should be replaced with factory method.
|
6
6
|
#
|
7
|
-
# See the best practice details here
|
8
|
-
# http://rails-bestpractices.com/posts/6-replace-complex-creation-with-factory-method.
|
7
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/21/replace-complex-creation-with-factory-method/
|
9
8
|
#
|
10
9
|
# Implementation:
|
11
10
|
#
|
@@ -18,7 +17,7 @@ module RailsBestPractices
|
|
18
17
|
class ReplaceComplexCreationWithFactoryMethodReview < Review
|
19
18
|
interesting_nodes :def
|
20
19
|
interesting_files CONTROLLER_FILES
|
21
|
-
url "http://rails-bestpractices.com/posts/
|
20
|
+
url "http://rails-bestpractices.com/posts/2010/07/21/replace-complex-creation-with-factory-method/"
|
22
21
|
|
23
22
|
def initialize(options = {})
|
24
23
|
super(options)
|
data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb
CHANGED
@@ -3,8 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a partail view file to make sure there is no instance variable.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
7
|
-
# http://rails-bestpractices.com/posts/27-replace-instance-variable-with-local-variable.
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/replace-instance-variable-with-local-variable/
|
8
7
|
#
|
9
8
|
# Implementation:
|
10
9
|
#
|
@@ -14,7 +13,7 @@ module RailsBestPractices
|
|
14
13
|
class ReplaceInstanceVariableWithLocalVariableReview < Review
|
15
14
|
interesting_nodes :var_ref, :vcall
|
16
15
|
interesting_files PARTIAL_VIEW_FILES
|
17
|
-
url "http://rails-bestpractices.com/posts/
|
16
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/replace-instance-variable-with-local-variable/"
|
18
17
|
|
19
18
|
# check ivar node in partial view file,
|
20
19
|
# it is an instance variable, and should be replaced with local variable.
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a route file to make sure all auto-generated routes have corresponding actions in controller.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2011/08/19/restrict-auto-generated-routes/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -15,7 +15,7 @@ module RailsBestPractices
|
|
15
15
|
class RestrictAutoGeneratedRoutesReview < Review
|
16
16
|
interesting_nodes :command, :command_call, :method_add_block
|
17
17
|
interesting_files ROUTE_FILES
|
18
|
-
url "http://rails-bestpractices.com/posts/
|
18
|
+
url "http://rails-bestpractices.com/posts/2011/08/19/restrict-auto-generated-routes/"
|
19
19
|
|
20
20
|
RESOURCE_METHODS = ["show", "new", "create", "edit", "update", "destroy"]
|
21
21
|
RESOURCES_METHODS = RESOURCE_METHODS + ["index"]
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a controller file to make sure using simplified syntax for render.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/12/12/simplify-render-in-controllers/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -14,7 +14,7 @@ module RailsBestPractices
|
|
14
14
|
class SimplifyRenderInControllersReview < Review
|
15
15
|
interesting_nodes :command
|
16
16
|
interesting_files CONTROLLER_FILES
|
17
|
-
url "http://rails-bestpractices.com/posts/
|
17
|
+
url "http://rails-bestpractices.com/posts/2010/12/12/simplify-render-in-controllers/"
|
18
18
|
|
19
19
|
# check command node in the controller file,
|
20
20
|
# if its message is render and the arguments contain a key action, template or file,
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a view file to make sure using simplified syntax for render.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/12/04/simplify-render-in-views/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class SimplifyRenderInViewsReview < Review
|
14
14
|
interesting_nodes :command
|
15
15
|
interesting_files VIEW_FILES
|
16
|
-
url "http://rails-bestpractices.com/posts/
|
16
|
+
url "http://rails-bestpractices.com/posts/2010/12/04/simplify-render-in-views/"
|
17
17
|
|
18
18
|
VALID_KEYS = %w(object collection locals)
|
19
19
|
|
@@ -4,7 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review a controller file to make sure to use before_filter to remove duplicated first code
|
5
5
|
# line_number in different action.
|
6
6
|
#
|
7
|
-
# See the best practice detailed here http://rails-bestpractices.com/posts/
|
7
|
+
# See the best practice detailed here http://rails-bestpractices.com/posts/2010/07/24/use-before_filter/
|
8
8
|
#
|
9
9
|
# Implementation:
|
10
10
|
#
|
@@ -14,7 +14,7 @@ module RailsBestPractices
|
|
14
14
|
class UseBeforeFilterReview < Review
|
15
15
|
interesting_nodes :class
|
16
16
|
interesting_files CONTROLLER_FILES
|
17
|
-
url "http://rails-bestpractices.com/posts/
|
17
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/use-before_filter/"
|
18
18
|
|
19
19
|
def initialize(options = {})
|
20
20
|
super()
|
@@ -49,7 +49,7 @@ module RailsBestPractices
|
|
49
49
|
def remember_first_sentence(node)
|
50
50
|
first_sentence = node.body.statements.first
|
51
51
|
return unless first_sentence
|
52
|
-
first_sentence = first_sentence.
|
52
|
+
first_sentence = first_sentence.remove_line_and_column
|
53
53
|
unless first_sentence == s(:nil)
|
54
54
|
@first_sentences[first_sentence] ||= []
|
55
55
|
@first_sentences[first_sentence] << node
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# review a controller file to make sure to use model association instead of foreign key id assignment.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/19/use-model-association/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseModelAssociationReview < Review
|
17
17
|
interesting_nodes :def
|
18
18
|
interesting_files CONTROLLER_FILES
|
19
|
-
url "http://rails-bestpractices.com/posts/
|
19
|
+
url "http://rails-bestpractices.com/posts/2010/07/19/use-model-association/"
|
20
20
|
|
21
21
|
# check method define nodes to see if there are some attribute assignments that can use model association instead.
|
22
22
|
#
|
data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb
CHANGED
@@ -3,8 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to use multipart/alternative as content_type of email.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
7
|
-
# http://rails-bestpractices.com/posts/41-use-multipart-alternative-as-content_type-of-email.
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/08/05/use-multipart-alternative-as-content_type-of-email/
|
8
7
|
#
|
9
8
|
# Implementation:
|
10
9
|
#
|
@@ -14,7 +13,7 @@ module RailsBestPractices
|
|
14
13
|
class UseMultipartAlternativeAsContentTypeOfEmailReview < Review
|
15
14
|
interesting_nodes :class, :def
|
16
15
|
interesting_files MAILER_FILES
|
17
|
-
url "http://rails-bestpractices.com/posts/
|
16
|
+
url "http://rails-bestpractices.com/posts/2010/08/05/use-multipart-alternative-as-content_type-of-email/"
|
18
17
|
|
19
18
|
# check class node to remember the ActionMailer class name.
|
20
19
|
add_callback :start_class do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to use observer (sorry we only check the mailer deliver now).
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/24/use-observer/
|
7
7
|
#
|
8
8
|
# TODO: we need a better solution, any suggestion?
|
9
9
|
#
|
@@ -20,7 +20,7 @@ module RailsBestPractices
|
|
20
20
|
class UseObserverReview < Review
|
21
21
|
interesting_nodes :def, :command
|
22
22
|
interesting_files MODEL_FILES
|
23
|
-
url "http://rails-bestpractices.com/posts/
|
23
|
+
url "http://rails-bestpractices.com/posts/2010/07/24/use-observer/"
|
24
24
|
|
25
25
|
def initialize(options = {})
|
26
26
|
super
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to use query attribute instead of nil?, blank? and present?.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/10/03/use-query-attribute/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseQueryAttributeReview < Review
|
17
17
|
interesting_nodes :if, :unless, :elsif, :ifop, :if_mod, :unless_mod
|
18
18
|
interesting_files ALL_FILES
|
19
|
-
url "http://rails-bestpractices.com/posts/
|
19
|
+
url "http://rails-bestpractices.com/posts/2010/10/03/use-query-attribute/"
|
20
20
|
|
21
21
|
QUERY_METHODS = %w(nil? blank? present?)
|
22
22
|
|
@@ -4,8 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review a migration file to make sure to use say or say_with_time for customized data changes
|
5
5
|
# to produce a more readable output.
|
6
6
|
#
|
7
|
-
# See the best practice detials here
|
8
|
-
# http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log.
|
7
|
+
# See the best practice detials here http://rails-bestpractices.com/posts/2010/08/19/use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log/
|
9
8
|
#
|
10
9
|
# Implementation:
|
11
10
|
#
|
@@ -17,7 +16,7 @@ module RailsBestPractices
|
|
17
16
|
class UseSayWithTimeInMigrationsReview < Review
|
18
17
|
interesting_nodes :defs
|
19
18
|
interesting_files MIGRATION_FILES
|
20
|
-
url "http://rails-bestpractices.com/posts/
|
19
|
+
url "http://rails-bestpractices.com/posts/2010/08/19/use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log/"
|
21
20
|
|
22
21
|
WITH_SAY_METHODS = %w(say say_with_time)
|
23
22
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a controller to make sure to use scope access instead of manually checking current_user and redirect.
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2010/07/20/use-scope-access/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseScopeAccessReview < Review
|
17
17
|
interesting_nodes :if, :unless, :elsif, :ifop, :if_mod, :unless_mod
|
18
18
|
interesting_files CONTROLLER_FILES
|
19
|
-
url "http://rails-bestpractices.com/posts/
|
19
|
+
url "http://rails-bestpractices.com/posts/2010/07/20/use-scope-access/"
|
20
20
|
|
21
21
|
# check if node.
|
22
22
|
#
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Prepare Gemfile and review Capfile file to make sure using turbo-sprocket-rails3
|
5
5
|
#
|
6
|
-
# See the best practice details here http://rails-bestpractices.com/posts/
|
6
|
+
# See the best practice details here http://rails-bestpractices.com/posts/2012/11/23/speed-up-assets-precompile-with-turbo-sprockets-rails3/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class UseTurboSprocketsRails3Review < Review
|
13
13
|
interesting_nodes :command
|
14
14
|
interesting_files CAPFILE
|
15
|
-
url "http://rails-bestpractices.com/posts/
|
15
|
+
url "http://rails-bestpractices.com/posts/2012/11/23/speed-up-assets-precompile-with-turbo-sprockets-rails3/"
|
16
16
|
|
17
17
|
# check command node to see if load 'deploy/assets'
|
18
18
|
add_callback :start_command do |node|
|
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_rubygems_version = ">= 1.3.6"
|
17
17
|
|
18
18
|
s.add_dependency("activesupport")
|
19
|
-
s.add_dependency("awesome_print")
|
20
19
|
s.add_dependency("code_analyzer", ">= 0.4.3")
|
21
20
|
s.add_dependency("colored")
|
22
21
|
s.add_dependency("erubis")
|
@@ -30,6 +29,7 @@ Gem::Specification.new do |s|
|
|
30
29
|
s.add_development_dependency("haml")
|
31
30
|
s.add_development_dependency("slim")
|
32
31
|
s.add_development_dependency("bundler")
|
32
|
+
s.add_development_dependency("awesome_print")
|
33
33
|
|
34
34
|
s.files = `git ls-files`.split("\n")
|
35
35
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -47,6 +47,7 @@ module RailsBestPractices
|
|
47
47
|
subject.stub(:output_terminal_errors)
|
48
48
|
subject.stub(:output_html_errors)
|
49
49
|
subject.stub(:output_yaml_errors)
|
50
|
+
subject.stub(:output_xml_errors)
|
50
51
|
|
51
52
|
subject.output
|
52
53
|
end
|
@@ -74,6 +75,15 @@ module RailsBestPractices
|
|
74
75
|
expect(subject).to have_received(:output_html_errors)
|
75
76
|
end
|
76
77
|
end
|
78
|
+
|
79
|
+
context "when format is xml" do
|
80
|
+
let(:format) { "xml" }
|
81
|
+
|
82
|
+
it "runs xml output" do
|
83
|
+
expect(subject).to have_received(:output_xml_errors)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
77
87
|
end
|
78
88
|
|
79
89
|
describe "output_terminal_errors" do
|
@@ -469,7 +469,7 @@ module RailsBestPractices
|
|
469
469
|
expect(routes.size).to eq(0)
|
470
470
|
end
|
471
471
|
|
472
|
-
it "should add resource routes with get/post/put/delete routes" do
|
472
|
+
it "should add resource routes with get/post/put/patch/delete routes" do
|
473
473
|
content =<<-EOF
|
474
474
|
RailsBestPracticesCom::Application.routes.draw do
|
475
475
|
resources :posts, only: [:show] do
|
@@ -481,14 +481,15 @@ module RailsBestPractices
|
|
481
481
|
post :create, on: :member
|
482
482
|
member do
|
483
483
|
put :update
|
484
|
+
patch :update
|
484
485
|
end
|
485
486
|
end
|
486
487
|
end
|
487
488
|
EOF
|
488
489
|
runner.prepare('config/routes.rb', content)
|
489
490
|
routes = Prepares.routes
|
490
|
-
expect(routes.size).to eq(
|
491
|
-
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#list", "PostsController#search", "PostsController#available", "PostsController#create", "PostsController#update"])
|
491
|
+
expect(routes.size).to eq(7)
|
492
|
+
expect(routes.map(&:to_s)).to eq(["PostsController#show", "PostsController#list", "PostsController#search", "PostsController#available", "PostsController#create", "PostsController#update", "PostsController#update"])
|
492
493
|
end
|
493
494
|
|
494
495
|
it "should add custom resources routes with {}" do
|
@@ -6,7 +6,7 @@ module RailsBestPractices
|
|
6
6
|
let(:runner) { Core::Runner.new(reviews: UseScopeAccessReview.new) }
|
7
7
|
|
8
8
|
context "if" do
|
9
|
-
it "
|
9
|
+
it "should use scope access" do
|
10
10
|
content = <<-EOF
|
11
11
|
class PostsController < ApplicationController
|
12
12
|
def edit
|
@@ -24,7 +24,7 @@ module RailsBestPractices
|
|
24
24
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "should use scope access with if in one line" do
|
28
28
|
content = <<-EOF
|
29
29
|
class PostsController < ApplicationController
|
30
30
|
def edit
|
@@ -39,7 +39,7 @@ module RailsBestPractices
|
|
39
39
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "should use scope access with '? :'" do
|
43
43
|
content = <<-EOF
|
44
44
|
class PostsController < ApplicationController
|
45
45
|
def edit
|
@@ -54,7 +54,7 @@ module RailsBestPractices
|
|
54
54
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
55
55
|
end
|
56
56
|
|
57
|
-
it "
|
57
|
+
it "should use scope access by comparing with id" do
|
58
58
|
content = <<-EOF
|
59
59
|
class PostsController < ApplicationController
|
60
60
|
def edit
|
@@ -72,7 +72,7 @@ module RailsBestPractices
|
|
72
72
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
73
73
|
end
|
74
74
|
|
75
|
-
it "
|
75
|
+
it "should use scope access with current_user ==" do
|
76
76
|
content = <<-EOF
|
77
77
|
class PostsController < ApplicationController
|
78
78
|
def edit
|
@@ -90,7 +90,7 @@ module RailsBestPractices
|
|
90
90
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
91
91
|
end
|
92
92
|
|
93
|
-
it "
|
93
|
+
it "should use scope access by current_user.id ==" do
|
94
94
|
content = <<-EOF
|
95
95
|
class PostsController < ApplicationController
|
96
96
|
def edit
|
@@ -110,7 +110,7 @@ module RailsBestPractices
|
|
110
110
|
end
|
111
111
|
|
112
112
|
context "unless" do
|
113
|
-
it "
|
113
|
+
it "should use scope access" do
|
114
114
|
content = <<-EOF
|
115
115
|
class PostsController < ApplicationController
|
116
116
|
def edit
|
@@ -128,7 +128,7 @@ module RailsBestPractices
|
|
128
128
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
129
129
|
end
|
130
130
|
|
131
|
-
it "
|
131
|
+
it "should use scope access by comparing with id" do
|
132
132
|
content = <<-EOF
|
133
133
|
class PostsController < ApplicationController
|
134
134
|
def edit
|
@@ -146,7 +146,7 @@ module RailsBestPractices
|
|
146
146
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
147
147
|
end
|
148
148
|
|
149
|
-
it "
|
149
|
+
it "should use scope access with current_user ==" do
|
150
150
|
content = <<-EOF
|
151
151
|
class PostsController < ApplicationController
|
152
152
|
def edit
|
@@ -164,7 +164,7 @@ module RailsBestPractices
|
|
164
164
|
expect(runner.errors[0].to_s).to eq("app/controllers/posts_controller.rb:5 - use scope access")
|
165
165
|
end
|
166
166
|
|
167
|
-
it "
|
167
|
+
it "should use scope access by current_user.id ==" do
|
168
168
|
content = <<-EOF
|
169
169
|
class PostsController < ApplicationController
|
170
170
|
def edit
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.15.
|
4
|
+
version: 1.15.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: awesome_print
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: code_analyzer
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,6 +192,20 @@ dependencies:
|
|
206
192
|
- - ">="
|
207
193
|
- !ruby/object:Gem::Version
|
208
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: awesome_print
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
209
|
description: a code metric tool for rails codes, written in Ruby.
|
210
210
|
email:
|
211
211
|
- flyerhzm@gmail.com
|
@@ -413,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
413
413
|
version: 1.3.6
|
414
414
|
requirements: []
|
415
415
|
rubyforge_project:
|
416
|
-
rubygems_version: 2.
|
416
|
+
rubygems_version: 2.4.5
|
417
417
|
signing_key:
|
418
418
|
specification_version: 4
|
419
419
|
summary: a code metric tool for rails codes.
|