rails_best_practices 1.19.0 → 1.19.1
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/CHANGELOG.md +5 -0
- data/Guardfile +2 -2
- data/Rakefile +8 -8
- data/bin/rails_best_practices +1 -1
- data/lib/rails_best_practices/analyzer.rb +45 -45
- data/lib/rails_best_practices/command.rb +40 -40
- data/lib/rails_best_practices/core/check.rb +15 -15
- data/lib/rails_best_practices/core/klasses.rb +1 -1
- data/lib/rails_best_practices/core/methods.rb +7 -7
- data/lib/rails_best_practices/core/model_associations.rb +3 -3
- 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 +3 -3
- data/lib/rails_best_practices/core_ext/erubis.rb +4 -4
- data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -2
- data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -2
- data/lib/rails_best_practices/prepares/config_prepare.rb +1 -1
- data/lib/rails_best_practices/prepares/controller_prepare.rb +8 -8
- data/lib/rails_best_practices/prepares/helper_prepare.rb +1 -1
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +4 -4
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -1
- data/lib/rails_best_practices/prepares/model_prepare.rb +19 -19
- data/lib/rails_best_practices/prepares/route_prepare.rb +34 -34
- data/lib/rails_best_practices/prepares/schema_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 +7 -7
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +1 -1
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +3 -3
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +3 -3
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +1 -1
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +6 -6
- 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 +4 -4
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -3
- 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 +1 -1
- 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 +1 -1
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +4 -4
- 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 +4 -4
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +3 -3
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -2
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +9 -9
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +3 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -11
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +1 -1
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +8 -7
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
- data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -2
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +22 -22
- data/lib/rails_best_practices/reviews/review.rb +2 -2
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +3 -3
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +4 -4
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -2
- 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 -2
- data/lib/rails_best_practices/reviews/use_observer_review.rb +3 -3
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +1 -1
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +3 -3
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +5 -5
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -4
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +24 -24
- data/spec/rails_best_practices/analyzer_spec.rb +43 -43
- data/spec/rails_best_practices/core/check_spec.rb +2 -2
- data/spec/rails_best_practices/core/checks_loader_spec.rb +4 -4
- data/spec/rails_best_practices/core/error_spec.rb +16 -16
- data/spec/rails_best_practices/core/except_methods_spec.rb +15 -15
- data/spec/rails_best_practices/core/gems_spec.rb +9 -9
- data/spec/rails_best_practices/core/klasses_spec.rb +17 -17
- data/spec/rails_best_practices/core/methods_spec.rb +28 -28
- data/spec/rails_best_practices/core/model_associations_spec.rb +10 -10
- data/spec/rails_best_practices/core/model_attributes_spec.rb +10 -10
- data/spec/rails_best_practices/core/modules_spec.rb +10 -10
- data/spec/rails_best_practices/core/routes_spec.rb +10 -10
- data/spec/rails_best_practices/core/runner_spec.rb +4 -4
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +7 -7
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +7 -7
- 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 +3 -3
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +26 -26
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +6 -6
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +5 -5
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +108 -108
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +77 -77
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +8 -8
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +10 -10
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +27 -27
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +11 -11
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +17 -17
- 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 +4 -4
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +8 -8
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +10 -10
- 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 +16 -16
- 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 +4 -4
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +13 -13
- 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 +5 -5
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +10 -10
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +8 -8
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +4 -4
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +11 -11
- 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 +16 -16
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -33
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +106 -106
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +8 -8
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +29 -29
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +15 -15
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +15 -15
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +7 -7
- 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 +29 -29
- 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 +5 -5
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +28 -28
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +23 -23
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +6 -6
- data/spec/spec_helper.rb +1 -1
- metadata +7 -7
data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb
CHANGED
@@ -5,7 +5,7 @@ module RailsBestPractices
|
|
5
5
|
describe ReplaceComplexCreationWithFactoryMethodReview do
|
6
6
|
let(:runner) { Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should replace complex creation with factory method' do
|
9
9
|
content = <<-EOF
|
10
10
|
class InvoiceController < ApplicationController
|
11
11
|
def create
|
@@ -26,10 +26,10 @@ module RailsBestPractices
|
|
26
26
|
EOF
|
27
27
|
runner.review('app/controllers/invoices_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('app/controllers/invoices_controller.rb:2 - replace complex creation with factory method (@invoice attribute_assignment_count > 2)')
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'should not replace complex creation with factory method with simple creation' do
|
33
33
|
content = <<-EOF
|
34
34
|
class InvoiceController < ApplicationController
|
35
35
|
def create
|
@@ -44,7 +44,7 @@ module RailsBestPractices
|
|
44
44
|
expect(runner.errors.size).to eq(0)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'should not replace complex creation with factory method when attrasgn_count is 5' do
|
48
48
|
content = <<-EOF
|
49
49
|
class InvoiceController < ApplicationController
|
50
50
|
def create
|
@@ -68,7 +68,7 @@ module RailsBestPractices
|
|
68
68
|
expect(runner.errors.size).to eq(0)
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
71
|
+
it 'should not check ignored files' do
|
72
72
|
runner = Core::Runner.new(reviews: ReplaceComplexCreationWithFactoryMethodReview.new(ignored_files: /invoices_controller/))
|
73
73
|
content = <<-EOF
|
74
74
|
class InvoiceController < ApplicationController
|
data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
CHANGED
@@ -5,34 +5,34 @@ module RailsBestPractices
|
|
5
5
|
describe ReplaceInstanceVariableWithLocalVariableReview do
|
6
6
|
let(:runner) { Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should replace instance variable with local varialbe' do
|
9
9
|
content = <<-EOF
|
10
10
|
<%= @post.title %>
|
11
11
|
EOF
|
12
12
|
runner.review('app/views/posts/_post.html.erb', content)
|
13
13
|
expect(runner.errors.size).to eq(1)
|
14
|
-
expect(runner.errors[0].to_s).to eq(
|
14
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/_post.html.erb:1 - replace instance variable with local variable')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should replace instance variable with local varialbe in haml file' do
|
18
18
|
content = <<-EOF
|
19
19
|
= @post.title
|
20
20
|
EOF
|
21
21
|
runner.review('app/views/posts/_post.html.haml', content)
|
22
22
|
expect(runner.errors.size).to eq(1)
|
23
|
-
expect(runner.errors[0].to_s).to eq(
|
23
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/_post.html.haml:1 - replace instance variable with local variable')
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should replace instance variable with local varialbe in slim file' do
|
27
27
|
content = <<-EOF
|
28
28
|
= @post.title
|
29
29
|
EOF
|
30
30
|
runner.review('app/views/posts/_post.html.slim', content)
|
31
31
|
expect(runner.errors.size).to eq(1)
|
32
|
-
expect(runner.errors[0].to_s).to eq(
|
32
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/_post.html.slim:1 - replace instance variable with local variable')
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'should not replace instance variable with local varialbe' do
|
36
36
|
content = <<-EOF
|
37
37
|
<%= post.title %>
|
38
38
|
EOF
|
@@ -40,7 +40,7 @@ module RailsBestPractices
|
|
40
40
|
expect(runner.errors.size).to eq(0)
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'should not check ignored files' do
|
44
44
|
runner = Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new(ignored_files: /views\/posts/))
|
45
45
|
content = <<-EOF
|
46
46
|
<%= @post.title %>
|
@@ -5,7 +5,7 @@ module RailsBestPractices
|
|
5
5
|
describe RestrictAutoGeneratedRoutesReview do
|
6
6
|
let(:runner) { Core::Runner.new(prepares: Prepares::ControllerPrepare.new, reviews: RestrictAutoGeneratedRoutesReview.new) }
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe 'resources' do
|
9
9
|
before :each do
|
10
10
|
content =<<-EOF
|
11
11
|
class PostsController < ApplicationController
|
@@ -20,7 +20,7 @@ module RailsBestPractices
|
|
20
20
|
runner.prepare('app/controllers/posts_controller.rb', content)
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'should restrict auto-generated routes' do
|
24
24
|
content =<<-EOF
|
25
25
|
RailsBestPracticesCom::Application.routes.draw do
|
26
26
|
resources :posts
|
@@ -28,10 +28,10 @@ module RailsBestPractices
|
|
28
28
|
EOF
|
29
29
|
runner.review('config/routes.rb', content)
|
30
30
|
expect(runner.errors.size).to eq(1)
|
31
|
-
expect(runner.errors[0].to_s).to eq(
|
31
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])')
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'should not restrict auto-generated routes with only' do
|
35
35
|
content =<<-EOF
|
36
36
|
RailsBestPracticesCom::Application.routes.draw do
|
37
37
|
resources :posts, only: %w(show new create edit update destroy)
|
@@ -41,7 +41,7 @@ module RailsBestPractices
|
|
41
41
|
expect(runner.errors.size).to eq(0)
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'should not restrict auto-generated routes with except' do
|
45
45
|
content =<<-EOF
|
46
46
|
RailsBestPracticesCom::Application.routes.draw do
|
47
47
|
resources :posts, except: :index
|
@@ -51,8 +51,8 @@ module RailsBestPractices
|
|
51
51
|
expect(runner.errors.size).to eq(0)
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
55
|
-
it
|
54
|
+
describe 'specify a controller' do
|
55
|
+
it 'should restrict auto-generated routes' do
|
56
56
|
content =<<-EOF
|
57
57
|
RailsBestPracticesCom::Application.routes.draw do
|
58
58
|
resources :articles, controller: "posts"
|
@@ -60,11 +60,11 @@ module RailsBestPractices
|
|
60
60
|
EOF
|
61
61
|
runner.review('config/routes.rb', content)
|
62
62
|
expect(runner.errors.size).to eq(1)
|
63
|
-
expect(runner.errors[0].to_s).to eq(
|
63
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes articles (except: [:index])')
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe
|
67
|
+
describe 'namespace' do
|
68
68
|
before do
|
69
69
|
content =<<-EOF
|
70
70
|
class Admin::CommentsController < ApplicationController
|
@@ -79,7 +79,7 @@ module RailsBestPractices
|
|
79
79
|
runner.prepare('app/controllers/admin/comments_controller.rb', content)
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
82
|
+
it 'should restrict auto-generated routes' do
|
83
83
|
content =<<-EOF
|
84
84
|
RailsBestPracticesCom::Application.routes.draw do
|
85
85
|
namespace :admin do
|
@@ -89,10 +89,10 @@ module RailsBestPractices
|
|
89
89
|
EOF
|
90
90
|
runner.review('config/routes.rb', content)
|
91
91
|
expect(runner.errors.size).to eq(1)
|
92
|
-
expect(runner.errors[0].to_s).to eq(
|
92
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])')
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
95
|
+
it 'should restrict auto-generated routes with scope :module' do
|
96
96
|
content =<<-EOF
|
97
97
|
RailsBestPracticesCom::Application.routes.draw do
|
98
98
|
scope module: :admin do
|
@@ -102,10 +102,10 @@ module RailsBestPractices
|
|
102
102
|
EOF
|
103
103
|
runner.review('config/routes.rb', content)
|
104
104
|
expect(runner.errors.size).to eq(1)
|
105
|
-
expect(runner.errors[0].to_s).to eq(
|
105
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:3 - restrict auto-generated routes admin/comments (except: [:index])')
|
106
106
|
end
|
107
107
|
|
108
|
-
it
|
108
|
+
it 'should restrict auto-generated routes with resources :module' do
|
109
109
|
content =<<-EOF
|
110
110
|
RailsBestPracticesCom::Application.routes.draw do
|
111
111
|
resources :comments, module: :admin
|
@@ -113,11 +113,11 @@ module RailsBestPractices
|
|
113
113
|
EOF
|
114
114
|
runner.review('config/routes.rb', content)
|
115
115
|
expect(runner.errors.size).to eq(1)
|
116
|
-
expect(runner.errors[0].to_s).to eq(
|
116
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes admin/comments (except: [:index])')
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
describe
|
120
|
+
describe 'nested routes' do
|
121
121
|
before :each do
|
122
122
|
content =<<-EOF
|
123
123
|
class CommentsController < ApplicationController
|
@@ -133,7 +133,7 @@ module RailsBestPractices
|
|
133
133
|
runner.prepare('app/controllers/comments_controller.rb', content)
|
134
134
|
end
|
135
135
|
|
136
|
-
it
|
136
|
+
it 'should restrict auto-generated routes' do
|
137
137
|
content =<<-EOF
|
138
138
|
RailsBestPracticesCom::Application.routes.draw do
|
139
139
|
resources :posts do
|
@@ -143,10 +143,10 @@ module RailsBestPractices
|
|
143
143
|
EOF
|
144
144
|
runner.review('config/routes.rb', content)
|
145
145
|
expect(runner.errors.size).to eq(1)
|
146
|
-
expect(runner.errors[0].to_s).to eq(
|
146
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])')
|
147
147
|
end
|
148
148
|
|
149
|
-
it
|
149
|
+
it 'should not restrict auto-generated routes with only' do
|
150
150
|
content =<<-EOF
|
151
151
|
RailsBestPracticesCom::Application.routes.draw do
|
152
152
|
resources :posts, only: %w(show new create edit update destroy) do
|
@@ -158,7 +158,7 @@ module RailsBestPractices
|
|
158
158
|
expect(runner.errors.size).to eq(0)
|
159
159
|
end
|
160
160
|
|
161
|
-
it
|
161
|
+
it 'should not restrict auto-generated routes with except' do
|
162
162
|
content =<<-EOF
|
163
163
|
RailsBestPracticesCom::Application.routes.draw do
|
164
164
|
resources :posts, except: :index do
|
@@ -172,7 +172,7 @@ module RailsBestPractices
|
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
-
describe
|
175
|
+
describe 'resource' do
|
176
176
|
before :each do
|
177
177
|
content =<<-EOF
|
178
178
|
class AccountsController < ApplicationController
|
@@ -186,7 +186,7 @@ module RailsBestPractices
|
|
186
186
|
runner.prepare('app/controllers/accounts_controller.rb', content)
|
187
187
|
end
|
188
188
|
|
189
|
-
it
|
189
|
+
it 'should restrict auto-generated routes' do
|
190
190
|
content =<<-EOF
|
191
191
|
ActionController::Routing::Routes.draw do |map|
|
192
192
|
map.resource :account
|
@@ -194,10 +194,10 @@ module RailsBestPractices
|
|
194
194
|
EOF
|
195
195
|
runner.review('config/routes.rb', content)
|
196
196
|
expect(runner.errors.size).to eq(1)
|
197
|
-
expect(runner.errors[0].to_s).to eq(
|
197
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes account (except: [:destroy])')
|
198
198
|
end
|
199
199
|
|
200
|
-
it
|
200
|
+
it 'should not restrict auto-generated routes with only' do
|
201
201
|
content =<<-EOF
|
202
202
|
ActionController::Routing::Routes.draw do |map|
|
203
203
|
map.resource :account, only: %w(show new create edit update)
|
@@ -207,7 +207,7 @@ module RailsBestPractices
|
|
207
207
|
expect(runner.errors.size).to eq(0)
|
208
208
|
end
|
209
209
|
|
210
|
-
it
|
210
|
+
it 'should not restrict auto-generated routes with except' do
|
211
211
|
content =<<-EOF
|
212
212
|
ActionController::Routing::Routes.draw do |map|
|
213
213
|
map.resource :account, except: :destroy
|
@@ -217,7 +217,7 @@ module RailsBestPractices
|
|
217
217
|
expect(runner.errors.size).to eq(0)
|
218
218
|
end
|
219
219
|
|
220
|
-
it
|
220
|
+
it 'should not check ignored files' do
|
221
221
|
runner = Core::Runner.new(prepares: Prepares::ControllerPrepare.new,
|
222
222
|
reviews: RestrictAutoGeneratedRoutesReview.new(ignored_files: /config\/routes\.rb/))
|
223
223
|
|
@@ -254,7 +254,7 @@ module RailsBestPractices
|
|
254
254
|
runner.prepare('app/controllers/posts_controller.rb', content)
|
255
255
|
end
|
256
256
|
|
257
|
-
it
|
257
|
+
it 'should restrict auto-generated routes' do
|
258
258
|
content =<<-EOF
|
259
259
|
RailsBestPracticesCom::Application.routes.draw do
|
260
260
|
resources :posts
|
@@ -262,10 +262,10 @@ module RailsBestPractices
|
|
262
262
|
EOF
|
263
263
|
runner.review('config/routes.rb', content)
|
264
264
|
expect(runner.errors.size).to eq(1)
|
265
|
-
expect(runner.errors[0].to_s).to eq(
|
265
|
+
expect(runner.errors[0].to_s).to eq('config/routes.rb:2 - restrict auto-generated routes posts (except: [:index])')
|
266
266
|
end
|
267
267
|
|
268
|
-
it
|
268
|
+
it 'should not restrict auto-generated routes with only' do
|
269
269
|
content =<<-EOF
|
270
270
|
RailsBestPracticesCom::Application.routes.draw do
|
271
271
|
resources :posts, only: %w(show create update destroy)
|
@@ -5,15 +5,15 @@ module RailsBestPractices
|
|
5
5
|
describe SimplifyRenderInControllersReview do
|
6
6
|
let(:runner) { Core::Runner.new(reviews: SimplifyRenderInControllersReview.new) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should simplify render action view' do
|
9
9
|
content =<<-EOF
|
10
10
|
def edit
|
11
11
|
render action: :edit
|
12
12
|
end
|
13
13
|
EOF
|
14
|
-
runner.review(
|
14
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
15
15
|
expect(runner.errors.size).to eq(1)
|
16
|
-
expect(runner.errors[0].to_s).to eq(
|
16
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - simplify render in controllers')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should simplify render actions's template" do
|
@@ -22,27 +22,27 @@ module RailsBestPractices
|
|
22
22
|
render template: 'books/edit'
|
23
23
|
end
|
24
24
|
EOF
|
25
|
-
runner.review(
|
25
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
26
26
|
expect(runner.errors.size).to eq(1)
|
27
|
-
expect(runner.errors[0].to_s).to eq(
|
27
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - simplify render in controllers')
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'should simplify render an arbitrary file' do
|
31
31
|
content =<<-EOF
|
32
32
|
def edit
|
33
33
|
render file: '/path/to/rails/app/views/books/edit'
|
34
34
|
end
|
35
35
|
EOF
|
36
|
-
runner.review(
|
36
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
37
37
|
expect(runner.errors.size).to eq(1)
|
38
|
-
expect(runner.errors[0].to_s).to eq(
|
38
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:2 - simplify render in controllers')
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'should not simplify render action view' do
|
42
42
|
content =<<-EOF
|
43
43
|
render :edit
|
44
44
|
EOF
|
45
|
-
runner.review(
|
45
|
+
runner.review('app/controllers/posts_controller', content)
|
46
46
|
expect(runner.errors.size).to eq(0)
|
47
47
|
end
|
48
48
|
|
@@ -52,28 +52,28 @@ module RailsBestPractices
|
|
52
52
|
render 'books/edit'
|
53
53
|
end
|
54
54
|
EOF
|
55
|
-
runner.review(
|
55
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
56
56
|
expect(runner.errors.size).to eq(0)
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'should not simplify render an arbitrary file' do
|
60
60
|
content =<<-EOF
|
61
61
|
def edit
|
62
62
|
render '/path/to/rails/app/views/books/edit'
|
63
63
|
end
|
64
64
|
EOF
|
65
|
-
runner.review(
|
65
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
66
66
|
expect(runner.errors.size).to eq(0)
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
69
|
+
it 'should not check ignored files' do
|
70
70
|
runner = Core::Runner.new(reviews: SimplifyRenderInControllersReview.new(ignored_files: /posts_controller/))
|
71
71
|
content =<<-EOF
|
72
72
|
def edit
|
73
73
|
render action: :edit
|
74
74
|
end
|
75
75
|
EOF
|
76
|
-
runner.review(
|
76
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
77
77
|
expect(runner.errors.size).to eq(0)
|
78
78
|
end
|
79
79
|
end
|
@@ -5,43 +5,43 @@ module RailsBestPractices
|
|
5
5
|
describe SimplifyRenderInViewsReview do
|
6
6
|
let(:runner) { Core::Runner.new(reviews: SimplifyRenderInViewsReview.new) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should simplify render simple partial' do
|
9
9
|
content =<<-EOF
|
10
10
|
<%= render partial: 'sidebar' %>
|
11
11
|
EOF
|
12
12
|
runner.review('app/views/posts/index.html.erb', content)
|
13
13
|
expect(runner.errors.size).to eq(1)
|
14
|
-
expect(runner.errors[0].to_s).to eq(
|
14
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'should simplify render partial with object' do
|
18
18
|
content =<<-EOF
|
19
19
|
<%= render partial: 'post', object: @post %>
|
20
20
|
EOF
|
21
21
|
runner.review('app/views/posts/index.html.erb', content)
|
22
22
|
expect(runner.errors.size).to eq(1)
|
23
|
-
expect(runner.errors[0].to_s).to eq(
|
23
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should simplify render partial with collection' do
|
27
27
|
content =<<-EOF
|
28
28
|
<%= render partial: 'posts', collection: @posts %>
|
29
29
|
EOF
|
30
30
|
runner.review('app/views/posts/index.html.erb', content)
|
31
31
|
expect(runner.errors.size).to eq(1)
|
32
|
-
expect(runner.errors[0].to_s).to eq(
|
32
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'should simplify render partial with local variables' do
|
36
36
|
content =<<-EOF
|
37
37
|
<%= render partial: 'comment', locals: { parent: post } %>
|
38
38
|
EOF
|
39
39
|
runner.review('app/views/posts/index.html.erb', content)
|
40
40
|
expect(runner.errors.size).to eq(1)
|
41
|
-
expect(runner.errors[0].to_s).to eq(
|
41
|
+
expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - simplify render in views')
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'should not simplify render simple partial' do
|
45
45
|
content =<<-EOF
|
46
46
|
<%= render 'sidebar' %>
|
47
47
|
<%= render 'shared/sidebar' %>
|
@@ -50,7 +50,7 @@ module RailsBestPractices
|
|
50
50
|
expect(runner.errors.size).to eq(0)
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'should not simplify render partial with object' do
|
54
54
|
content =<<-EOF
|
55
55
|
<%= render @post %>
|
56
56
|
EOF
|
@@ -58,7 +58,7 @@ module RailsBestPractices
|
|
58
58
|
expect(runner.errors.size).to eq(0)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'should not simplify render partial with collection' do
|
62
62
|
content =<<-EOF
|
63
63
|
<%= render @posts %>
|
64
64
|
EOF
|
@@ -66,7 +66,7 @@ module RailsBestPractices
|
|
66
66
|
expect(runner.errors.size).to eq(0)
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
69
|
+
it 'should not simplify render partial with local variables' do
|
70
70
|
content =<<-EOF
|
71
71
|
<%= render 'comment', parent: post %>
|
72
72
|
EOF
|
@@ -74,7 +74,7 @@ module RailsBestPractices
|
|
74
74
|
expect(runner.errors.size).to eq(0)
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
77
|
+
it 'should not simplify render partial with complex partial' do
|
78
78
|
content =<<-EOF
|
79
79
|
<%= render partial: 'shared/post', object: @post %>
|
80
80
|
EOF
|
@@ -82,7 +82,7 @@ module RailsBestPractices
|
|
82
82
|
expect(runner.errors.size).to eq(0)
|
83
83
|
end
|
84
84
|
|
85
|
-
it
|
85
|
+
it 'should not simplify render partial with layout option' do
|
86
86
|
content =<<-EOF
|
87
87
|
<%= render partial: 'post', layout: 'post' %>
|
88
88
|
EOF
|
@@ -90,7 +90,7 @@ module RailsBestPractices
|
|
90
90
|
expect(runner.errors.size).to eq(0)
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
93
|
+
it 'should not check ignored files' do
|
94
94
|
runner = Core::Runner.new(reviews: SimplifyRenderInViewsReview.new(ignored_files: /views\/posts\/index/))
|
95
95
|
content =<<-EOF
|
96
96
|
<%= render partial: 'sidebar' %>
|