rails_best_practices 1.19.2 → 1.20.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +2 -3
- data/CHANGELOG.md +7 -7
- data/Gemfile +3 -5
- data/Gemfile.lock +125 -0
- data/Guardfile +2 -0
- data/README.md +6 -6
- data/Rakefile +2 -17
- data/assets/result.html.erb +2 -0
- data/lib/rails_best_practices.rb +3 -2
- data/lib/rails_best_practices/analyzer.rb +61 -49
- data/lib/rails_best_practices/cli.rb +22 -0
- data/lib/rails_best_practices/command.rb +1 -131
- data/lib/rails_best_practices/core/check.rb +64 -56
- data/lib/rails_best_practices/core/checks_loader.rb +24 -23
- data/lib/rails_best_practices/core/configs.rb +1 -2
- data/lib/rails_best_practices/core/controllers.rb +1 -2
- data/lib/rails_best_practices/core/error.rb +1 -1
- data/lib/rails_best_practices/core/helpers.rb +1 -2
- data/lib/rails_best_practices/core/mailers.rb +1 -2
- data/lib/rails_best_practices/core/methods.rb +27 -21
- data/lib/rails_best_practices/core/model_associations.rb +10 -5
- data/lib/rails_best_practices/core/models.rb +1 -2
- data/lib/rails_best_practices/core/modules.rb +1 -1
- data/lib/rails_best_practices/core/routes.rb +2 -2
- data/lib/rails_best_practices/core/runner.rb +67 -73
- data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
- data/lib/rails_best_practices/option_parser.rb +156 -0
- data/lib/rails_best_practices/prepares.rb +1 -1
- data/lib/rails_best_practices/prepares/controller_prepare.rb +24 -17
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -2
- data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/model_prepare.rb +63 -23
- data/lib/rails_best_practices/prepares/route_prepare.rb +28 -21
- data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +38 -34
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +94 -89
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +15 -5
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +20 -8
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +16 -16
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +12 -12
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +10 -11
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +25 -24
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +4 -4
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +9 -10
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +10 -11
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +24 -22
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +8 -8
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +35 -32
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +26 -19
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +12 -10
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +38 -18
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +11 -11
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +77 -74
- data/lib/rails_best_practices/reviews/review.rb +2 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -3
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +12 -12
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +18 -15
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +15 -15
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +24 -22
- data/lib/rails_best_practices/reviews/use_observer_review.rb +28 -28
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +68 -66
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -8
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +16 -14
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +38 -43
- data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
- data/spec/rails_best_practices/analyzer_spec.rb +73 -42
- data/spec/rails_best_practices/core/check_spec.rb +5 -5
- data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
- data/spec/rails_best_practices/core/configs_spec.rb +1 -1
- data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
- data/spec/rails_best_practices/core/error_spec.rb +21 -18
- data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
- data/spec/rails_best_practices/core/gems_spec.rb +4 -4
- data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
- data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
- data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
- data/spec/rails_best_practices/core/methods_spec.rb +6 -6
- data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
- data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
- data/spec/rails_best_practices/core/models_spec.rb +1 -1
- data/spec/rails_best_practices/core/modules_spec.rb +5 -5
- data/spec/rails_best_practices/core/routes_spec.rb +5 -5
- data/spec/rails_best_practices/core/runner_spec.rb +9 -7
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +32 -31
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +17 -17
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +141 -76
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +13 -13
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +29 -22
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +32 -22
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -17
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +64 -31
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +21 -14
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +57 -53
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +20 -14
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +35 -31
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +10 -8
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +61 -59
- metadata +16 -18
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe MoveCodeIntoModelReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'moves code into model' do
|
11
11
|
content = <<-EOF
|
12
12
|
<% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
|
13
13
|
<%= link_to 'Edit this post', edit_post_url(@post) %>
|
@@ -15,48 +15,58 @@ module RailsBestPractices
|
|
15
15
|
EOF
|
16
16
|
runner.review('app/views/posts/show.html.erb', content)
|
17
17
|
expect(runner.errors.size).to eq(1)
|
18
|
-
expect(runner.errors[0].to_s).to eq(
|
18
|
+
expect(runner.errors[0].to_s).to eq(
|
19
|
+
'app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)'
|
20
|
+
)
|
19
21
|
end
|
20
22
|
|
21
|
-
it '
|
22
|
-
content =
|
23
|
-
- if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
|
24
|
-
|
23
|
+
it 'moves code into model with haml' do
|
24
|
+
content = <<~EOF
|
25
|
+
- if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
|
26
|
+
= link_to 'Edit this post', edit_post_url(@post)
|
25
27
|
EOF
|
26
28
|
runner.review('app/views/posts/show.html.haml', content)
|
27
29
|
expect(runner.errors.size).to eq(1)
|
28
|
-
expect(runner.errors[0].to_s).to eq(
|
30
|
+
expect(runner.errors[0].to_s).to eq(
|
31
|
+
'app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)'
|
32
|
+
)
|
29
33
|
end
|
30
34
|
|
31
|
-
it '
|
32
|
-
content =
|
33
|
-
- if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
|
34
|
-
|
35
|
+
it 'moves code into model with slim' do
|
36
|
+
content = <<~EOF
|
37
|
+
- if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
|
38
|
+
= link_to 'Edit this post', edit_post_url(@post)
|
35
39
|
EOF
|
36
40
|
runner.review('app/views/posts/show.html.slim', content)
|
37
41
|
expect(runner.errors.size).to eq(1)
|
38
|
-
expect(runner.errors[0].to_s).to eq(
|
42
|
+
expect(runner.errors[0].to_s).to eq(
|
43
|
+
'app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)'
|
44
|
+
)
|
39
45
|
end
|
40
46
|
|
41
|
-
it '
|
47
|
+
it 'moves code into model with if in one line' do
|
42
48
|
content = <<-EOF
|
43
49
|
<%= link_to 'Edit this post', edit_post_url(@post) if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
|
44
50
|
EOF
|
45
51
|
runner.review('app/views/posts/show.html.erb', content)
|
46
52
|
expect(runner.errors.size).to eq(1)
|
47
|
-
expect(runner.errors[0].to_s).to eq(
|
53
|
+
expect(runner.errors[0].to_s).to eq(
|
54
|
+
'app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)'
|
55
|
+
)
|
48
56
|
end
|
49
57
|
|
50
|
-
it "
|
58
|
+
it "moves code into model with '? :'" do
|
51
59
|
content = <<-EOF
|
52
60
|
<%= current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) ? link_to('Edit this post', edit_post_url(@post)) : '' %>
|
53
61
|
EOF
|
54
62
|
runner.review('app/views/posts/show.html.erb', content)
|
55
63
|
expect(runner.errors.size).to eq(1)
|
56
|
-
expect(runner.errors[0].to_s).to eq(
|
64
|
+
expect(runner.errors[0].to_s).to eq(
|
65
|
+
'app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)'
|
66
|
+
)
|
57
67
|
end
|
58
68
|
|
59
|
-
it '
|
69
|
+
it 'moves code into model only review for current if conditional statement' do
|
60
70
|
content = <<-EOF
|
61
71
|
<% if @post.title %>
|
62
72
|
<% if @post.user %>
|
@@ -69,7 +79,7 @@ module RailsBestPractices
|
|
69
79
|
expect(runner.errors.size).to eq(0)
|
70
80
|
end
|
71
81
|
|
72
|
-
it '
|
82
|
+
it 'does not move code into model' do
|
73
83
|
content = <<-EOF
|
74
84
|
<% if @post.editable_by?(current_user) %>
|
75
85
|
<%= link_to 'Edit this post', edit_post_url(@post) %>
|
@@ -79,7 +89,7 @@ module RailsBestPractices
|
|
79
89
|
expect(runner.errors.size).to eq(0)
|
80
90
|
end
|
81
91
|
|
82
|
-
it '
|
92
|
+
it 'does not move code into model for multiple calls on same variable node' do
|
83
93
|
content = <<-EOF
|
84
94
|
<% if !job.company.blank? && job.company.title? %>
|
85
95
|
<% end %>
|
@@ -88,8 +98,8 @@ module RailsBestPractices
|
|
88
98
|
expect(runner.errors.size).to eq(0)
|
89
99
|
end
|
90
100
|
|
91
|
-
it '
|
92
|
-
runner = Core::Runner.new(reviews:
|
101
|
+
it 'does not check ignored files' do
|
102
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/views/post}))
|
93
103
|
content = <<-EOF
|
94
104
|
<% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
|
95
105
|
<%= link_to 'Edit this post', edit_post_url(@post) %>
|
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe MoveFinderToNamedScopeReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'moves finder to named_scope' do
|
11
11
|
content = <<-EOF
|
12
12
|
class PostsController < ActionController::Base
|
13
13
|
def index
|
@@ -27,7 +27,7 @@ module RailsBestPractices
|
|
27
27
|
expect(runner.errors[1].to_s).to eq('app/controllers/posts_controller.rb:7 - move finder to named_scope')
|
28
28
|
end
|
29
29
|
|
30
|
-
it '
|
30
|
+
it 'does not move simple finder' do
|
31
31
|
content = <<-EOF
|
32
32
|
class PostsController < ActionController::Base
|
33
33
|
def index
|
@@ -44,7 +44,7 @@ module RailsBestPractices
|
|
44
44
|
expect(runner.errors.size).to eq(0)
|
45
45
|
end
|
46
46
|
|
47
|
-
it '
|
47
|
+
it 'does not move namd_scope' do
|
48
48
|
content = <<-EOF
|
49
49
|
class PostsController < ActionController::Base
|
50
50
|
def index
|
@@ -57,7 +57,7 @@ module RailsBestPractices
|
|
57
57
|
expect(runner.errors.size).to eq(0)
|
58
58
|
end
|
59
59
|
|
60
|
-
it '
|
60
|
+
it 'does not review model file' do
|
61
61
|
content = <<-EOF
|
62
62
|
class Post < ActiveRecord::Base
|
63
63
|
def published
|
@@ -75,8 +75,8 @@ module RailsBestPractices
|
|
75
75
|
expect(runner.errors.size).to eq(0)
|
76
76
|
end
|
77
77
|
|
78
|
-
it '
|
79
|
-
runner = Core::Runner.new(reviews:
|
78
|
+
it 'does not check ignored files' do
|
79
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/controllers/posts}))
|
80
80
|
content = <<-EOF
|
81
81
|
class PostsController < ActionController::Base
|
82
82
|
def index
|
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe MoveModelLogicIntoModelReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'moves model logic into model' do
|
11
11
|
content = <<-EOF
|
12
12
|
class PostsController < ApplicationController
|
13
13
|
def publish
|
@@ -26,10 +26,12 @@ module RailsBestPractices
|
|
26
26
|
EOF
|
27
27
|
runner.review('app/controllers/posts_controller.rb', content)
|
28
28
|
expect(runner.errors.size).to eq(1)
|
29
|
-
expect(runner.errors[0].to_s).to eq(
|
29
|
+
expect(runner.errors[0].to_s).to eq(
|
30
|
+
'app/controllers/posts_controller.rb:2 - move model logic into model (@post use_count > 4)'
|
31
|
+
)
|
30
32
|
end
|
31
33
|
|
32
|
-
it '
|
34
|
+
it 'does not move model logic into model with simple model calling' do
|
33
35
|
content = <<-EOF
|
34
36
|
class PostsController < ApplicationController
|
35
37
|
def publish
|
@@ -45,7 +47,7 @@ module RailsBestPractices
|
|
45
47
|
expect(runner.errors.size).to eq(0)
|
46
48
|
end
|
47
49
|
|
48
|
-
it '
|
50
|
+
it 'does not move model logic into model with self calling' do
|
49
51
|
content = <<-EOF
|
50
52
|
class PostsController < ApplicationController
|
51
53
|
def publish
|
@@ -61,8 +63,8 @@ module RailsBestPractices
|
|
61
63
|
expect(runner.errors.size).to eq(0)
|
62
64
|
end
|
63
65
|
|
64
|
-
it '
|
65
|
-
runner = Core::Runner.new(reviews:
|
66
|
+
it 'does not check ignored files' do
|
67
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/controllers/posts}))
|
66
68
|
content = <<-EOF
|
67
69
|
class PostsController < ApplicationController
|
68
70
|
def publish
|
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe NeedlessDeepNestingReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'needlesses deep nesting' do
|
11
11
|
content = <<-EOF
|
12
12
|
resources :posts do
|
13
13
|
resources :comments do
|
@@ -20,7 +20,7 @@ module RailsBestPractices
|
|
20
20
|
expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - needless deep nesting (nested_count > 2)')
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'does not needless deep nesting for shallow' do
|
24
24
|
content = <<-EOF
|
25
25
|
resources :posts, shallow: true do
|
26
26
|
resources :comments do
|
@@ -32,7 +32,7 @@ module RailsBestPractices
|
|
32
32
|
expect(runner.errors.size).to eq(0)
|
33
33
|
end
|
34
34
|
|
35
|
-
it '
|
35
|
+
it 'does not needless deep nesting for shallow 4 levels' do
|
36
36
|
content = <<-EOF
|
37
37
|
resources :applications, shallow: true, only: [:index, :show, :create] do
|
38
38
|
resources :events, only: [:index, :show, :create, :subscribe, :push] do
|
@@ -46,7 +46,7 @@ module RailsBestPractices
|
|
46
46
|
expect(runner.errors.size).to eq(0)
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'needlesses deep nesting with resource' do
|
50
50
|
content = <<-EOF
|
51
51
|
resources :posts do
|
52
52
|
resources :comments do
|
@@ -59,7 +59,7 @@ module RailsBestPractices
|
|
59
59
|
expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - needless deep nesting (nested_count > 2)')
|
60
60
|
end
|
61
61
|
|
62
|
-
it '
|
62
|
+
it 'needlesses deep nesting with block node' do
|
63
63
|
content = <<-EOF
|
64
64
|
resources :posts do
|
65
65
|
resources :comments do
|
@@ -73,7 +73,7 @@ module RailsBestPractices
|
|
73
73
|
expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - needless deep nesting (nested_count > 2)')
|
74
74
|
end
|
75
75
|
|
76
|
-
it '
|
76
|
+
it 'noes needless deep nesting' do
|
77
77
|
content = <<-EOF
|
78
78
|
resources :posts do
|
79
79
|
resources :comments
|
@@ -88,8 +88,8 @@ module RailsBestPractices
|
|
88
88
|
expect(runner.errors.size).to eq(0)
|
89
89
|
end
|
90
90
|
|
91
|
-
it '
|
92
|
-
runner = Core::Runner.new(reviews:
|
91
|
+
it 'does not check ignored files' do
|
92
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{config/routes}))
|
93
93
|
content = <<-EOF
|
94
94
|
map.resources :posts do |post|
|
95
95
|
post.resources :comments do |comment|
|
@@ -5,10 +5,10 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe NotRescueExceptionReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
10
|
describe 'not_rescue_exception' do
|
11
|
-
it '
|
11
|
+
it 'does not rescue exception in method rescue with named var' do
|
12
12
|
content = <<-EOF
|
13
13
|
def my_method
|
14
14
|
do_something
|
@@ -21,7 +21,7 @@ module RailsBestPractices
|
|
21
21
|
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:3 - Don't rescue Exception")
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
24
|
+
it 'does not rescue exception in method rescue without named var' do
|
25
25
|
content = <<-EOF
|
26
26
|
def my_method
|
27
27
|
do_something
|
@@ -34,7 +34,7 @@ module RailsBestPractices
|
|
34
34
|
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:3 - Don't rescue Exception")
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
37
|
+
it 'does not rescue exception in block rescue with named var' do
|
38
38
|
content = <<-EOF
|
39
39
|
def my_method
|
40
40
|
begin
|
@@ -49,7 +49,7 @@ module RailsBestPractices
|
|
49
49
|
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:4 - Don't rescue Exception")
|
50
50
|
end
|
51
51
|
|
52
|
-
it '
|
52
|
+
it 'does not rescue exception in block rescue without named var' do
|
53
53
|
content = <<-EOF
|
54
54
|
def my_method
|
55
55
|
begin
|
@@ -64,7 +64,7 @@ module RailsBestPractices
|
|
64
64
|
expect(runner.errors[0].to_s).to eq("app/helpers/posts_helper.rb:4 - Don't rescue Exception")
|
65
65
|
end
|
66
66
|
|
67
|
-
it '
|
67
|
+
it 'allows rescue implicit StandardError in block rescue without named var' do
|
68
68
|
content = <<-EOF
|
69
69
|
def my_method
|
70
70
|
begin
|
@@ -78,7 +78,7 @@ module RailsBestPractices
|
|
78
78
|
expect(runner.errors.size).to eq(0)
|
79
79
|
end
|
80
80
|
|
81
|
-
it '
|
81
|
+
it 'allows rescue explicit StandardError in block rescue without named var' do
|
82
82
|
content = <<-EOF
|
83
83
|
def my_method
|
84
84
|
begin
|
@@ -92,8 +92,8 @@ module RailsBestPractices
|
|
92
92
|
expect(runner.errors.size).to eq(0)
|
93
93
|
end
|
94
94
|
|
95
|
-
it '
|
96
|
-
runner = Core::Runner.new(reviews:
|
95
|
+
it 'does not check ignored files' do
|
96
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_helper/))
|
97
97
|
content = <<-EOF
|
98
98
|
def my_method
|
99
99
|
do_something
|
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe NotUseDefaultRouteReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'does not use default route' do
|
11
11
|
content = <<-EOF
|
12
12
|
RailsBestpracticesCom::Application.routes.draw do |map|
|
13
13
|
resources :posts
|
@@ -20,7 +20,7 @@ module RailsBestPractices
|
|
20
20
|
expect(runner.errors[0].to_s).to eq('config/routes.rb:4 - not use default route')
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'noes not use default route' do
|
24
24
|
content = <<-EOF
|
25
25
|
RailsBestpracticesCom::Application.routes.draw do |map|
|
26
26
|
resources :posts
|
@@ -30,8 +30,8 @@ module RailsBestPractices
|
|
30
30
|
expect(runner.errors.size).to eq(0)
|
31
31
|
end
|
32
32
|
|
33
|
-
it '
|
34
|
-
runner = Core::Runner.new(reviews:
|
33
|
+
it 'does not check ignored files' do
|
34
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{config/routes\.rb}))
|
35
35
|
content = <<-EOF
|
36
36
|
RailsBestpracticesCom::Application.routes.draw do |map|
|
37
37
|
resources :posts
|
@@ -5,10 +5,10 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe NotUseTimeAgoInWordsReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
10
|
describe 'time_ago_in_words' do
|
11
|
-
it '
|
11
|
+
it 'does not use in views' do
|
12
12
|
content = <<-EOF
|
13
13
|
<%= time_ago_in_words(post.created_at) %>
|
14
14
|
EOF
|
@@ -17,7 +17,7 @@ module RailsBestPractices
|
|
17
17
|
expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - not use time_ago_in_words')
|
18
18
|
end
|
19
19
|
|
20
|
-
it '
|
20
|
+
it 'does not use in helpers' do
|
21
21
|
content = <<-EOF
|
22
22
|
def timeago
|
23
23
|
content_tag(:p, time_ago_in_words(post.created_at))
|
@@ -30,7 +30,7 @@ module RailsBestPractices
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe 'distance_of_time_in_words_to_now' do
|
33
|
-
it '
|
33
|
+
it 'does not use in views' do
|
34
34
|
content = <<-EOF
|
35
35
|
<%= distance_of_time_in_words_to_now(post.created_at) %>
|
36
36
|
EOF
|
@@ -39,7 +39,7 @@ module RailsBestPractices
|
|
39
39
|
expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - not use time_ago_in_words')
|
40
40
|
end
|
41
41
|
|
42
|
-
it '
|
42
|
+
it 'does not use in helpers' do
|
43
43
|
content = <<-EOF
|
44
44
|
def timeago
|
45
45
|
content_tag(:p, distance_of_time_in_words_to_now(post.created_at))
|
@@ -51,8 +51,8 @@ module RailsBestPractices
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
it '
|
55
|
-
runner = Core::Runner.new(reviews:
|
54
|
+
it 'does not check ignored files' do
|
55
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_helper/))
|
56
56
|
content = <<-EOF
|
57
57
|
def timeago
|
58
58
|
content_tag(:p, time_ago_in_words(post.created_at))
|
@@ -5,9 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module RailsBestPractices
|
6
6
|
module Reviews
|
7
7
|
describe OveruseRouteCustomizationsReview do
|
8
|
-
let(:runner) { Core::Runner.new(reviews:
|
8
|
+
let(:runner) { Core::Runner.new(reviews: described_class.new) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'overuses route customizations' do
|
11
11
|
content = <<-EOF
|
12
12
|
RailsBestpracticesCom::Application.routes.draw do
|
13
13
|
resources :posts do
|
@@ -28,7 +28,7 @@ module RailsBestPractices
|
|
28
28
|
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - overuse route customizations (customize_count > 3)')
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'overuses route customizations another way' do
|
32
32
|
content = <<-EOF
|
33
33
|
RailsBestpracticesCom::Application.routes.draw do
|
34
34
|
resources :posts do
|
@@ -44,7 +44,7 @@ module RailsBestPractices
|
|
44
44
|
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - overuse route customizations (customize_count > 3)')
|
45
45
|
end
|
46
46
|
|
47
|
-
it '
|
47
|
+
it 'does not overuse route customizations without customization' do
|
48
48
|
content = <<-EOF
|
49
49
|
RailsBestpracticesCom::Application.routes.draw do
|
50
50
|
resources :posts
|
@@ -54,7 +54,7 @@ module RailsBestPractices
|
|
54
54
|
expect(runner.errors.size).to eq(0)
|
55
55
|
end
|
56
56
|
|
57
|
-
it '
|
57
|
+
it 'does not overuse route customizations when customize route is only one' do
|
58
58
|
content = <<-EOF
|
59
59
|
RailsBestpracticesCom::Application.routes.draw do
|
60
60
|
resources :posts do
|
@@ -68,8 +68,8 @@ module RailsBestPractices
|
|
68
68
|
expect(runner.errors.size).to eq(0)
|
69
69
|
end
|
70
70
|
|
71
|
-
it '
|
72
|
-
runner = Core::Runner.new(reviews:
|
71
|
+
it 'does not check ignored files' do
|
72
|
+
runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{config/routes\.rb}))
|
73
73
|
content = <<-EOF
|
74
74
|
ActionController::Routing::Routes.draw do |map|
|
75
75
|
map.resources :posts, member: { comments: :get,
|