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
@@ -6,17 +6,17 @@ module RailsBestPractices
|
|
6
6
|
let(:runner) { Core::Runner.new(prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
|
7
7
|
reviews: ProtectMassAssignmentReview.new) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'should protect mass assignment' do
|
10
10
|
content =<<-EOF
|
11
11
|
class User < ActiveRecord::Base
|
12
12
|
end
|
13
13
|
EOF
|
14
14
|
runner.review('app/models/user.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/models/user.rb:1 - protect mass assignment')
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'should not protect mass assignment if attr_accessible is used with arguments and user set config.active_record.whitelist_attributes' do
|
20
20
|
content =<<-EOF
|
21
21
|
module RailsBestPracticesCom
|
22
22
|
class Application < Rails::Application
|
@@ -34,7 +34,7 @@ module RailsBestPractices
|
|
34
34
|
expect(runner.errors.size).to eq(0)
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'should not protect mass assignment if attr_accessible is used without arguments and user set config.active_record.whitelist_attributes' do
|
38
38
|
content =<<-EOF
|
39
39
|
module RailsBestPracticesCom
|
40
40
|
class Application < Rails::Application
|
@@ -52,7 +52,7 @@ module RailsBestPractices
|
|
52
52
|
expect(runner.errors.size).to eq(0)
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'should not protect mass assignment with attr_protected if user set config.active_record.whitelist_attributes' do
|
56
56
|
content =<<-EOF
|
57
57
|
module RailsBestPracticesCom
|
58
58
|
class Application < Rails::Application
|
@@ -70,7 +70,7 @@ module RailsBestPractices
|
|
70
70
|
expect(runner.errors.size).to eq(0)
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'should not protect mass assignment if using devise' do
|
74
74
|
content =<<-EOF
|
75
75
|
class User < ActiveRecord::Base
|
76
76
|
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
|
@@ -80,7 +80,7 @@ module RailsBestPractices
|
|
80
80
|
expect(runner.errors.size).to eq(0)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it 'should not protect mass assignment if using authlogic with configuration' do
|
84
84
|
content =<<-EOF
|
85
85
|
class User < ActiveRecord::Base
|
86
86
|
acts_as_authentic do |c|
|
@@ -92,7 +92,7 @@ module RailsBestPractices
|
|
92
92
|
expect(runner.errors.size).to eq(0)
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
95
|
+
it 'should not protect mass assignment if using authlogic without configuration' do
|
96
96
|
content =<<-EOF
|
97
97
|
class User < ActiveRecord::Base
|
98
98
|
acts_as_authentic
|
@@ -102,7 +102,7 @@ module RailsBestPractices
|
|
102
102
|
expect(runner.errors.size).to eq(0)
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'should not protect mass assignment if checking non ActiveRecord::Base inherited model' do
|
106
106
|
content =<<-EOF
|
107
107
|
class User < Person
|
108
108
|
end
|
@@ -111,8 +111,8 @@ module RailsBestPractices
|
|
111
111
|
expect(runner.errors.size).to eq(0)
|
112
112
|
end
|
113
113
|
|
114
|
-
context
|
115
|
-
it
|
114
|
+
context 'strong_parameters' do
|
115
|
+
it 'should not protect mass assignment for strong_parameters' do
|
116
116
|
content =<<-EOF
|
117
117
|
class User < ActiveRecord::Base
|
118
118
|
include ActiveModel::ForbiddenAttributesProtection
|
@@ -122,7 +122,7 @@ module RailsBestPractices
|
|
122
122
|
expect(runner.errors.size).to eq(0)
|
123
123
|
end
|
124
124
|
|
125
|
-
it
|
125
|
+
it 'should not protect mass assignment for strong_parameters' do
|
126
126
|
content =<<-EOF
|
127
127
|
class AR
|
128
128
|
ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
|
@@ -138,8 +138,8 @@ module RailsBestPractices
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
context
|
142
|
-
it
|
141
|
+
context 'activerecord 4' do
|
142
|
+
it 'should not protect mass assignment for activerecord 4' do
|
143
143
|
content =<<-EOF
|
144
144
|
GEM
|
145
145
|
remote: https://rubygems.org
|
@@ -155,7 +155,7 @@ module RailsBestPractices
|
|
155
155
|
expect(runner.errors.size).to eq(0)
|
156
156
|
end
|
157
157
|
|
158
|
-
it
|
158
|
+
it 'should protect mass assignment for activerecord 3' do
|
159
159
|
content =<<-EOF
|
160
160
|
GEM
|
161
161
|
remote: https://rubygems.org
|
@@ -172,7 +172,7 @@ module RailsBestPractices
|
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
-
it
|
175
|
+
it 'should not check ignored files' do
|
176
176
|
runner = Core::Runner.new(prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
|
177
177
|
reviews: ProtectMassAssignmentReview.new(ignored_files: /app\/models\/user\.rb/))
|
178
178
|
content =<<-EOF
|
@@ -5,17 +5,17 @@ module RailsBestPractices
|
|
5
5
|
describe RemoveEmptyHelpersReview do
|
6
6
|
let(:runner) { Core::Runner.new(reviews: RemoveEmptyHelpersReview.new) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'should remove empty helpers' do
|
9
9
|
content =<<-EOF
|
10
10
|
module PostsHelper
|
11
11
|
end
|
12
12
|
EOF
|
13
13
|
runner.review('app/helpers/posts_helper.rb', content)
|
14
14
|
expect(runner.errors.size).to eq(1)
|
15
|
-
expect(runner.errors[0].to_s).to eq(
|
15
|
+
expect(runner.errors[0].to_s).to eq('app/helpers/posts_helper.rb:1 - remove empty helpers')
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'should not remove empty helpers' do
|
19
19
|
content =<<-EOF
|
20
20
|
module PostsHelper
|
21
21
|
def post_link(post)
|
@@ -27,7 +27,7 @@ module RailsBestPractices
|
|
27
27
|
expect(runner.errors.size).to eq(0)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'should not remove empty application_helper' do
|
31
31
|
content =<<-EOF
|
32
32
|
module ApplicationHelper
|
33
33
|
end
|
@@ -36,7 +36,7 @@ module RailsBestPractices
|
|
36
36
|
expect(runner.errors.size).to eq(0)
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'should not check ignored files' do
|
40
40
|
runner = Core::Runner.new(reviews: RemoveEmptyHelpersReview.new(ignored_files: /posts_helper/))
|
41
41
|
content =<<-EOF
|
42
42
|
module PostsHelper
|
@@ -5,11 +5,11 @@ module RailsBestPractices
|
|
5
5
|
describe RemoveUnusedMethodsInControllersReview do
|
6
6
|
let(:runner) { Core::Runner.new(
|
7
7
|
prepares: [Prepares::ControllerPrepare.new, Prepares::RoutePrepare.new],
|
8
|
-
reviews: RemoveUnusedMethodsInControllersReview.new({'except_methods' => [
|
8
|
+
reviews: RemoveUnusedMethodsInControllersReview.new({'except_methods' => ['ExceptableController#*']})
|
9
9
|
) }
|
10
10
|
|
11
|
-
context
|
12
|
-
it
|
11
|
+
context 'private/protected' do
|
12
|
+
it 'should remove unused methods' do
|
13
13
|
content =<<-EOF
|
14
14
|
RailsBestPracticesCom::Application.routes.draw do
|
15
15
|
resources :posts do
|
@@ -36,11 +36,11 @@ module RailsBestPractices
|
|
36
36
|
runner.review('app/controllers/posts_controller.rb', content)
|
37
37
|
runner.after_review
|
38
38
|
expect(runner.errors.size).to eq(2)
|
39
|
-
expect(runner.errors[0].to_s).to eq(
|
40
|
-
expect(runner.errors[1].to_s).to eq(
|
39
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:6 - remove unused methods (PostsController#load_post)')
|
40
|
+
expect(runner.errors[1].to_s).to eq('app/controllers/posts_controller.rb:8 - remove unused methods (PostsController#load_user)')
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'should not remove unused methods for before_filter' do
|
44
44
|
content =<<-EOF
|
45
45
|
RailsBestPracticesCom::Application.routes.draw do
|
46
46
|
resources :posts
|
@@ -62,7 +62,7 @@ module RailsBestPractices
|
|
62
62
|
expect(runner.errors.size).to eq(0)
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it 'should not remove unused methods for around_filter' do
|
66
66
|
content =<<-EOF
|
67
67
|
RailsBestPracticesCom::Application.routes.draw do
|
68
68
|
resources :posts
|
@@ -87,7 +87,7 @@ module RailsBestPractices
|
|
87
87
|
expect(runner.errors.size).to eq(0)
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it 'should not remove unused methods for layout' do
|
91
91
|
content =<<-EOF
|
92
92
|
RailsBestPracticesCom::Application.routes.draw do
|
93
93
|
resources :posts
|
@@ -109,7 +109,7 @@ module RailsBestPractices
|
|
109
109
|
expect(runner.errors.size).to eq(0)
|
110
110
|
end
|
111
111
|
|
112
|
-
it
|
112
|
+
it 'should not remove inherited_resources methods' do
|
113
113
|
content =<<-EOF
|
114
114
|
RailsBestPracticesCom::Application.routes.draw do
|
115
115
|
resources :posts
|
@@ -132,8 +132,8 @@ module RailsBestPractices
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
context
|
136
|
-
it
|
135
|
+
context 'public' do
|
136
|
+
it 'should remove unused methods' do
|
137
137
|
content =<<-EOF
|
138
138
|
RailsBestPracticesCom::Application.routes.draw do
|
139
139
|
resources :posts
|
@@ -150,10 +150,10 @@ module RailsBestPractices
|
|
150
150
|
runner.review('app/controllers/posts_controller.rb', content)
|
151
151
|
runner.after_review
|
152
152
|
expect(runner.errors.size).to eq(1)
|
153
|
-
expect(runner.errors[0].to_s).to eq(
|
153
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:3 - remove unused methods (PostsController#list)')
|
154
154
|
end
|
155
155
|
|
156
|
-
it
|
156
|
+
it 'should not remove inline routes' do
|
157
157
|
content =<<-EOF
|
158
158
|
RailsBestPracticesCom::Application.routes.draw do
|
159
159
|
resources :posts, only: :none do
|
@@ -174,7 +174,7 @@ module RailsBestPractices
|
|
174
174
|
expect(runner.errors.size).to eq(0)
|
175
175
|
end
|
176
176
|
|
177
|
-
it
|
177
|
+
it 'should not remove unused methods if all actions are used in route' do
|
178
178
|
content =<<-EOF
|
179
179
|
ActionController::Routing::Routes.draw do |map|
|
180
180
|
map.connect 'internal/:action/*whatever', controller: "internal"
|
@@ -194,7 +194,7 @@ module RailsBestPractices
|
|
194
194
|
expect(runner.errors.size).to eq(0)
|
195
195
|
end
|
196
196
|
|
197
|
-
it
|
197
|
+
it 'should not remove unused methods if they are except_methods' do
|
198
198
|
content =<<-EOF
|
199
199
|
class ExceptableController < ApplicationController
|
200
200
|
def list; end
|
@@ -207,8 +207,8 @@ module RailsBestPractices
|
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
-
context
|
211
|
-
it
|
210
|
+
context 'assignment' do
|
211
|
+
it 'should not remove unused methods if call in base class' do
|
212
212
|
content =<<-EOF
|
213
213
|
RailsBestPracticesCom::Application.routes.draw do
|
214
214
|
resources :user, only: :show do; end
|
@@ -236,8 +236,8 @@ module RailsBestPractices
|
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
|
-
context
|
240
|
-
it
|
239
|
+
context 'helper_method' do
|
240
|
+
it 'should remove unused methods if helper method is not called' do
|
241
241
|
content = <<-EOF
|
242
242
|
class PostsController < ApplicationController
|
243
243
|
helper_method :helper_post
|
@@ -249,10 +249,10 @@ module RailsBestPractices
|
|
249
249
|
runner.review('app/controllers/posts_controller.rb', content)
|
250
250
|
runner.after_review
|
251
251
|
expect(runner.errors.size).to eq(1)
|
252
|
-
expect(runner.errors[0].to_s).to eq(
|
252
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:4 - remove unused methods (PostsController#helper_post)')
|
253
253
|
end
|
254
254
|
|
255
|
-
it
|
255
|
+
it 'should not remove unused methods if call helper method in views' do
|
256
256
|
content = <<-EOF
|
257
257
|
class PostsController < ApplicationController
|
258
258
|
helper_method :helper_post
|
@@ -270,7 +270,7 @@ module RailsBestPractices
|
|
270
270
|
expect(runner.errors.size).to eq(0)
|
271
271
|
end
|
272
272
|
|
273
|
-
it
|
273
|
+
it 'should not remove unused methods if call helper method in helpers' do
|
274
274
|
content = <<-EOF
|
275
275
|
class PostsController < ApplicationController
|
276
276
|
helper_method :helper_post
|
@@ -293,8 +293,8 @@ module RailsBestPractices
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
-
context
|
297
|
-
it
|
296
|
+
context 'delegate to: :controller' do
|
297
|
+
it 'should remove unused methods if delegate method is not called' do
|
298
298
|
content = <<-EOF
|
299
299
|
class PostsController < ApplicationController
|
300
300
|
protected
|
@@ -311,10 +311,10 @@ module RailsBestPractices
|
|
311
311
|
runner.review('app/helpers/posts_helper.rb', content)
|
312
312
|
runner.after_review
|
313
313
|
expect(runner.errors.size).to eq(1)
|
314
|
-
expect(runner.errors[0].to_s).to eq(
|
314
|
+
expect(runner.errors[0].to_s).to eq('app/controllers/posts_controller.rb:3 - remove unused methods (PostsController#helper_post)')
|
315
315
|
end
|
316
316
|
|
317
|
-
it
|
317
|
+
it 'should remove unused methods if delegate method is called' do
|
318
318
|
content = <<-EOF
|
319
319
|
class PostsController < ApplicationController
|
320
320
|
protected
|
@@ -338,8 +338,8 @@ module RailsBestPractices
|
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
341
|
-
context
|
342
|
-
it
|
341
|
+
context 'cells' do
|
342
|
+
it 'should remove unused methods' do
|
343
343
|
content =<<-EOF
|
344
344
|
class PostsCell < Cell::Rails
|
345
345
|
def list; end
|
@@ -349,10 +349,10 @@ module RailsBestPractices
|
|
349
349
|
runner.review('app/cells/posts_cell.rb', content)
|
350
350
|
runner.after_review
|
351
351
|
expect(runner.errors.size).to eq(1)
|
352
|
-
expect(runner.errors[0].to_s).to eq(
|
352
|
+
expect(runner.errors[0].to_s).to eq('app/cells/posts_cell.rb:2 - remove unused methods (PostsCell#list)')
|
353
353
|
end
|
354
354
|
|
355
|
-
it
|
355
|
+
it 'should not remove unused methods if render_cell' do
|
356
356
|
content =<<-EOF
|
357
357
|
class PostsCell < Cell::Rails
|
358
358
|
def list; end
|
@@ -370,7 +370,7 @@ module RailsBestPractices
|
|
370
370
|
expect(runner.errors.size).to eq(0)
|
371
371
|
end
|
372
372
|
|
373
|
-
it
|
373
|
+
it 'should not remove unused methods if render with state' do
|
374
374
|
content =<<-EOF
|
375
375
|
class PostsCell < Cell::Rails
|
376
376
|
def list
|
@@ -393,7 +393,7 @@ module RailsBestPractices
|
|
393
393
|
end
|
394
394
|
end
|
395
395
|
|
396
|
-
it
|
396
|
+
it 'should not remove unused methods' do
|
397
397
|
route_content =<<-EOF
|
398
398
|
RailsBestPracticesCom::Application.routes.draw do
|
399
399
|
namespace :admin do
|
@@ -430,7 +430,7 @@ module RailsBestPractices
|
|
430
430
|
expect(runner.errors.size).to eq(0)
|
431
431
|
end
|
432
432
|
|
433
|
-
it
|
433
|
+
it 'should not check ignored files' do
|
434
434
|
runner = Core::Runner.new(prepares: [Prepares::ControllerPrepare.new, Prepares::RoutePrepare.new],
|
435
435
|
reviews: RemoveUnusedMethodsInControllersReview.new(ignored_files: /posts_controller/, except_methods: []))
|
436
436
|
content =<<-EOF
|
@@ -8,7 +8,7 @@ module RailsBestPractices
|
|
8
8
|
reviews: RemoveUnusedMethodsInHelpersReview.new(except_methods: [])
|
9
9
|
) }
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'should remove unused methods' do
|
12
12
|
content =<<-EOF
|
13
13
|
module PostsHelper
|
14
14
|
def unused; end
|
@@ -18,10 +18,10 @@ module RailsBestPractices
|
|
18
18
|
runner.review('app/helpers/posts_helper.rb', content)
|
19
19
|
runner.after_review
|
20
20
|
expect(runner.errors.size).to eq(1)
|
21
|
-
expect(runner.errors[0].to_s).to eq(
|
21
|
+
expect(runner.errors[0].to_s).to eq('app/helpers/posts_helper.rb:2 - remove unused methods (PostsHelper#unused)')
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'should not remove unused methods if called on views' do
|
25
25
|
content =<<-EOF
|
26
26
|
module PostsHelper
|
27
27
|
def used?(post); end
|
@@ -38,7 +38,7 @@ module RailsBestPractices
|
|
38
38
|
expect(runner.errors.size).to eq(0)
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'should not remove unused methods if called on helpers' do
|
42
42
|
content =<<-EOF
|
43
43
|
module PostsHelper
|
44
44
|
def used?(post)
|
@@ -59,7 +59,7 @@ module RailsBestPractices
|
|
59
59
|
expect(runner.errors.size).to eq(0)
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'should not remove unused methods if called on controllers' do
|
63
63
|
helper_content =<<-EOF
|
64
64
|
module PostsHelper
|
65
65
|
def used?(post); end
|
@@ -84,7 +84,7 @@ module RailsBestPractices
|
|
84
84
|
expect(runner.errors.size).to eq(0)
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
87
|
+
it 'should not remove unused methods if called in descendant controllers' do
|
88
88
|
application_helper_content =<<-EOF
|
89
89
|
module ApplicationHelper
|
90
90
|
def admin?; end
|
@@ -114,7 +114,7 @@ module RailsBestPractices
|
|
114
114
|
expect(runner.errors.size).to eq(0)
|
115
115
|
end
|
116
116
|
|
117
|
-
it
|
117
|
+
it 'should not check ignored files' do
|
118
118
|
runner = Core::Runner.new(prepares: [Prepares::ControllerPrepare.new, Prepares::HelperPrepare.new],
|
119
119
|
reviews: RemoveUnusedMethodsInHelpersReview.new(ignored_files: /posts_helper/, except_methods: []))
|
120
120
|
|
@@ -5,11 +5,11 @@ module RailsBestPractices
|
|
5
5
|
describe RemoveUnusedMethodsInModelsReview do
|
6
6
|
let(:runner) { Core::Runner.new(
|
7
7
|
prepares: Prepares::ModelPrepare.new,
|
8
|
-
reviews: RemoveUnusedMethodsInModelsReview.new({'except_methods' => [
|
8
|
+
reviews: RemoveUnusedMethodsInModelsReview.new({'except_methods' => ['*#set_cache']})
|
9
9
|
) }
|
10
10
|
|
11
|
-
context
|
12
|
-
it
|
11
|
+
context 'private' do
|
12
|
+
it 'should remove unused methods' do
|
13
13
|
content =<<-EOF
|
14
14
|
class Post < ActiveRecord::Base
|
15
15
|
def find; end
|
@@ -29,10 +29,10 @@ module RailsBestPractices
|
|
29
29
|
runner.review('app/controllers/posts_controller.rb', content)
|
30
30
|
runner.after_review
|
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/models/post.rb:4 - remove unused methods (Post#find_by_sql)')
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'should not remove unused methods with except_methods' do
|
36
36
|
content =<<-EOF
|
37
37
|
class Post < ActiveRecord::Base
|
38
38
|
def set_cache; end
|
@@ -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 remove unused methods with var_ref' do
|
48
48
|
content =<<-EOF
|
49
49
|
class Post < ActiveRecord::Base
|
50
50
|
def find
|
@@ -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 remove unused methods with callback' do
|
72
72
|
content =<<-EOF
|
73
73
|
class Post < ActiveRecord::Base
|
74
74
|
after_save :expire_cache
|
@@ -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 remove unused method with command' do
|
86
86
|
content =<<-EOF
|
87
87
|
class Post < ActiveRecord::Base
|
88
88
|
def fetch
|
@@ -106,7 +106,7 @@ module RailsBestPractices
|
|
106
106
|
expect(runner.errors.size).to eq(0)
|
107
107
|
end
|
108
108
|
|
109
|
-
it
|
109
|
+
it 'should not remove unused method with call' do
|
110
110
|
content =<<-EOF
|
111
111
|
class Post < ActiveRecord::Base
|
112
112
|
def conditions
|
@@ -130,7 +130,7 @@ module RailsBestPractices
|
|
130
130
|
expect(runner.errors.size).to eq(0)
|
131
131
|
end
|
132
132
|
|
133
|
-
it
|
133
|
+
it 'should not remove unused method with message' do
|
134
134
|
content =<<-EOF
|
135
135
|
class Post < ActiveRecord::Base
|
136
136
|
def save
|
@@ -156,7 +156,7 @@ module RailsBestPractices
|
|
156
156
|
expect(runner.errors.size).to eq(0)
|
157
157
|
end
|
158
158
|
|
159
|
-
it
|
159
|
+
it 'should not remove unused method with validation condition' do
|
160
160
|
content =<<-EOF
|
161
161
|
class Post < ActiveRecord::Base
|
162
162
|
validates_uniqueness_of :login, if: :email_blank?
|
@@ -170,7 +170,7 @@ module RailsBestPractices
|
|
170
170
|
expect(runner.errors.size).to eq(0)
|
171
171
|
end
|
172
172
|
|
173
|
-
it
|
173
|
+
it 'should not remove unused method with aasm' do
|
174
174
|
content =<<-EOF
|
175
175
|
class Post < ActiveRecord::Base
|
176
176
|
aasm_state :accepted, enter: [:update_datetime]
|
@@ -184,7 +184,7 @@ module RailsBestPractices
|
|
184
184
|
expect(runner.errors.size).to eq(0)
|
185
185
|
end
|
186
186
|
|
187
|
-
it
|
187
|
+
it 'should not remove unused method with initialize' do
|
188
188
|
content =<<-EOF
|
189
189
|
class Post < ActiveRecord::Base
|
190
190
|
private
|
@@ -198,8 +198,8 @@ module RailsBestPractices
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
context
|
202
|
-
it
|
201
|
+
context 'public' do
|
202
|
+
it 'should remove unused methods' do
|
203
203
|
content =<<-EOF
|
204
204
|
class Post < ActiveRecord::Base
|
205
205
|
def fetch; end
|
@@ -208,10 +208,10 @@ module RailsBestPractices
|
|
208
208
|
runner.prepare('app/models/post.rb', content)
|
209
209
|
runner.after_review
|
210
210
|
expect(runner.errors.size).to eq(1)
|
211
|
-
expect(runner.errors[0].to_s).to eq(
|
211
|
+
expect(runner.errors[0].to_s).to eq('app/models/post.rb:2 - remove unused methods (Post#fetch)')
|
212
212
|
end
|
213
213
|
|
214
|
-
it
|
214
|
+
it 'should not remove unused methods' do
|
215
215
|
content =<<-EOF
|
216
216
|
class Post < ActiveRecord::Base
|
217
217
|
def fetch; end
|
@@ -230,7 +230,7 @@ module RailsBestPractices
|
|
230
230
|
expect(runner.errors.size).to eq(0)
|
231
231
|
end
|
232
232
|
|
233
|
-
it
|
233
|
+
it 'should not remove unused methods for attribute assignment' do
|
234
234
|
content =<<-EOF
|
235
235
|
class Post < ActiveRecord::Base
|
236
236
|
def user=(user); end
|
@@ -242,7 +242,7 @@ module RailsBestPractices
|
|
242
242
|
expect(runner.errors.size).to eq(0)
|
243
243
|
end
|
244
244
|
|
245
|
-
it
|
245
|
+
it 'should not remove unused methods for try' do
|
246
246
|
content =<<-EOF
|
247
247
|
class Post < ActiveRecord::Base
|
248
248
|
def find(user_id); end
|
@@ -262,7 +262,7 @@ module RailsBestPractices
|
|
262
262
|
expect(runner.errors.size).to eq(0)
|
263
263
|
end
|
264
264
|
|
265
|
-
it
|
265
|
+
it 'should not remove unused methods for send' do
|
266
266
|
content =<<-EOF
|
267
267
|
class Post < ActiveRecord::Base
|
268
268
|
def find(user_id); end
|
@@ -282,7 +282,7 @@ module RailsBestPractices
|
|
282
282
|
expect(runner.errors.size).to eq(0)
|
283
283
|
end
|
284
284
|
|
285
|
-
it
|
285
|
+
it 'should remove unused methods for send string_embexpre' do
|
286
286
|
content =<<-EOF
|
287
287
|
class Post < ActiveRecord::Base
|
288
288
|
def find_first; end
|
@@ -303,7 +303,7 @@ module RailsBestPractices
|
|
303
303
|
expect(runner.errors.size).to eq(1)
|
304
304
|
end
|
305
305
|
|
306
|
-
it
|
306
|
+
it 'should remove unused methods for send variable' do
|
307
307
|
content =<<-EOF
|
308
308
|
class Post < ActiveRecord::Base
|
309
309
|
def first; end
|
@@ -325,16 +325,16 @@ module RailsBestPractices
|
|
325
325
|
end
|
326
326
|
end
|
327
327
|
|
328
|
-
context
|
329
|
-
it
|
328
|
+
context 'protected' do
|
329
|
+
it 'should not remove unused methods' do
|
330
330
|
content =<<-EOF
|
331
331
|
class Post < ActiveRecord::Base
|
332
332
|
protected
|
333
333
|
def test; end
|
334
334
|
end
|
335
335
|
EOF
|
336
|
-
runner.prepare(
|
337
|
-
runner.review(
|
336
|
+
runner.prepare('app/models/post.rb', content)
|
337
|
+
runner.review('app/models/post.rb', content)
|
338
338
|
content =<<-EOF
|
339
339
|
class PostsController < ApplicationController
|
340
340
|
def test
|
@@ -345,10 +345,10 @@ module RailsBestPractices
|
|
345
345
|
runner.review('app/controllers/posts_controller.rb', content)
|
346
346
|
runner.after_review
|
347
347
|
expect(runner.errors.size).to eq(1)
|
348
|
-
expect(runner.errors[0].to_s).to eq(
|
348
|
+
expect(runner.errors[0].to_s).to eq('app/models/post.rb:3 - remove unused methods (Post#test)')
|
349
349
|
end
|
350
350
|
|
351
|
-
it
|
351
|
+
it 'should not remove unused methods' do
|
352
352
|
post_content =<<-EOF
|
353
353
|
class Post < ActiveRecord::Base
|
354
354
|
protected
|
@@ -362,10 +362,10 @@ module RailsBestPractices
|
|
362
362
|
end
|
363
363
|
end
|
364
364
|
EOF
|
365
|
-
runner.prepare(
|
366
|
-
runner.prepare(
|
367
|
-
runner.review(
|
368
|
-
runner.review(
|
365
|
+
runner.prepare('app/models/post.rb', post_content)
|
366
|
+
runner.prepare('app/models/blog_post.rb', blog_post_content)
|
367
|
+
runner.review('app/models/post.rb', post_content)
|
368
|
+
runner.review('app/models/blog_post.rb', blog_post_content)
|
369
369
|
content =<<-EOF
|
370
370
|
class BlogPostsController < ApplicationController
|
371
371
|
def play
|
@@ -379,15 +379,15 @@ module RailsBestPractices
|
|
379
379
|
end
|
380
380
|
end
|
381
381
|
|
382
|
-
context
|
383
|
-
it
|
382
|
+
context 'named_scope' do
|
383
|
+
it 'should not remove unused named_scope' do
|
384
384
|
content =<<-EOF
|
385
385
|
class Post < ActiveRecord::Base
|
386
386
|
named_scope :active, conditions: {active: true}
|
387
387
|
end
|
388
388
|
EOF
|
389
|
-
runner.prepare(
|
390
|
-
runner.review(
|
389
|
+
runner.prepare('app/models/post.rb', content)
|
390
|
+
runner.review('app/models/post.rb', content)
|
391
391
|
content =<<-EOF
|
392
392
|
class PostsController < ApplicationController
|
393
393
|
def index
|
@@ -395,34 +395,34 @@ module RailsBestPractices
|
|
395
395
|
end
|
396
396
|
end
|
397
397
|
EOF
|
398
|
-
runner.review(
|
398
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
399
399
|
runner.after_review
|
400
400
|
expect(runner.errors.size).to eq(0)
|
401
401
|
end
|
402
402
|
|
403
|
-
it
|
403
|
+
it 'should remove unused named_scope' do
|
404
404
|
content =<<-EOF
|
405
405
|
class Post < ActiveRecord::Base
|
406
406
|
named_scope :active, conditions: {active: true}
|
407
407
|
end
|
408
408
|
EOF
|
409
|
-
runner.prepare(
|
410
|
-
runner.review(
|
409
|
+
runner.prepare('app/models/post.rb', content)
|
410
|
+
runner.review('app/models/post.rb', content)
|
411
411
|
runner.after_review
|
412
412
|
expect(runner.errors.size).to eq(1)
|
413
|
-
expect(runner.errors[0].to_s).to eq(
|
413
|
+
expect(runner.errors[0].to_s).to eq('app/models/post.rb:2 - remove unused methods (Post#active)')
|
414
414
|
end
|
415
415
|
end
|
416
416
|
|
417
|
-
context
|
418
|
-
it
|
417
|
+
context 'scope' do
|
418
|
+
it 'should not remove unused scope' do
|
419
419
|
content =<<-EOF
|
420
420
|
class Post < ActiveRecord::Base
|
421
421
|
scope :active, where(active: true)
|
422
422
|
end
|
423
423
|
EOF
|
424
|
-
runner.prepare(
|
425
|
-
runner.review(
|
424
|
+
runner.prepare('app/models/post.rb', content)
|
425
|
+
runner.review('app/models/post.rb', content)
|
426
426
|
content =<<-EOF
|
427
427
|
class PostsController < ApplicationController
|
428
428
|
def index
|
@@ -430,35 +430,35 @@ module RailsBestPractices
|
|
430
430
|
end
|
431
431
|
end
|
432
432
|
EOF
|
433
|
-
runner.review(
|
433
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
434
434
|
runner.after_review
|
435
435
|
expect(runner.errors.size).to eq(0)
|
436
436
|
end
|
437
437
|
|
438
|
-
it
|
438
|
+
it 'should remove unused named_scope' do
|
439
439
|
content =<<-EOF
|
440
440
|
class Post < ActiveRecord::Base
|
441
441
|
scope :active, where(active: true)
|
442
442
|
end
|
443
443
|
EOF
|
444
|
-
runner.prepare(
|
445
|
-
runner.review(
|
444
|
+
runner.prepare('app/models/post.rb', content)
|
445
|
+
runner.review('app/models/post.rb', content)
|
446
446
|
runner.after_review
|
447
447
|
expect(runner.errors.size).to eq(1)
|
448
|
-
expect(runner.errors[0].to_s).to eq(
|
448
|
+
expect(runner.errors[0].to_s).to eq('app/models/post.rb:2 - remove unused methods (Post#active)')
|
449
449
|
end
|
450
450
|
end
|
451
451
|
|
452
|
-
context
|
453
|
-
it
|
452
|
+
context 'alias' do
|
453
|
+
it 'should not remove unused method with alias' do
|
454
454
|
content =<<-EOF
|
455
455
|
class Post < ActiveRecord::Base
|
456
456
|
def old; end
|
457
457
|
alias new old
|
458
458
|
end
|
459
459
|
EOF
|
460
|
-
runner.prepare(
|
461
|
-
runner.review(
|
460
|
+
runner.prepare('app/models/post.rb', content)
|
461
|
+
runner.review('app/models/post.rb', content)
|
462
462
|
content =<<-EOF
|
463
463
|
class PostsController < ApplicationController
|
464
464
|
def show
|
@@ -466,20 +466,20 @@ module RailsBestPractices
|
|
466
466
|
end
|
467
467
|
end
|
468
468
|
EOF
|
469
|
-
runner.review(
|
469
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
470
470
|
runner.after_review
|
471
471
|
expect(runner.errors.size).to eq(0)
|
472
472
|
end
|
473
473
|
|
474
|
-
it
|
474
|
+
it 'should not remove unused method with symbol alias' do
|
475
475
|
content =<<-EOF
|
476
476
|
class Post < ActiveRecord::Base
|
477
477
|
def old; end
|
478
478
|
alias :new :old
|
479
479
|
end
|
480
480
|
EOF
|
481
|
-
runner.prepare(
|
482
|
-
runner.review(
|
481
|
+
runner.prepare('app/models/post.rb', content)
|
482
|
+
runner.review('app/models/post.rb', content)
|
483
483
|
content =<<-EOF
|
484
484
|
class PostsController < ApplicationController
|
485
485
|
def show
|
@@ -487,20 +487,20 @@ module RailsBestPractices
|
|
487
487
|
end
|
488
488
|
end
|
489
489
|
EOF
|
490
|
-
runner.review(
|
490
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
491
491
|
runner.after_review
|
492
492
|
expect(runner.errors.size).to eq(0)
|
493
493
|
end
|
494
494
|
|
495
|
-
it
|
495
|
+
it 'should not remove unused method with alias_method' do
|
496
496
|
content =<<-EOF
|
497
497
|
class Post < ActiveRecord::Base
|
498
498
|
def old; end
|
499
499
|
alias_method :new, :old
|
500
500
|
end
|
501
501
|
EOF
|
502
|
-
runner.prepare(
|
503
|
-
runner.review(
|
502
|
+
runner.prepare('app/models/post.rb', content)
|
503
|
+
runner.review('app/models/post.rb', content)
|
504
504
|
content =<<-EOF
|
505
505
|
class PostsController < ApplicationController
|
506
506
|
def show
|
@@ -508,20 +508,20 @@ module RailsBestPractices
|
|
508
508
|
end
|
509
509
|
end
|
510
510
|
EOF
|
511
|
-
runner.review(
|
511
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
512
512
|
runner.after_review
|
513
513
|
expect(runner.errors.size).to eq(0)
|
514
514
|
end
|
515
515
|
|
516
|
-
it
|
516
|
+
it 'should not remove unused method with alias_method_chain' do
|
517
517
|
content =<<-EOF
|
518
518
|
class Post < ActiveRecord::Base
|
519
519
|
def method_with_feature; end
|
520
520
|
alias_method_chain :method, :feature
|
521
521
|
end
|
522
522
|
EOF
|
523
|
-
runner.prepare(
|
524
|
-
runner.review(
|
523
|
+
runner.prepare('app/models/post.rb', content)
|
524
|
+
runner.review('app/models/post.rb', content)
|
525
525
|
content =<<-EOF
|
526
526
|
class PostsController < ApplicationController
|
527
527
|
def show
|
@@ -529,14 +529,14 @@ module RailsBestPractices
|
|
529
529
|
end
|
530
530
|
end
|
531
531
|
EOF
|
532
|
-
runner.review(
|
532
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
533
533
|
runner.after_review
|
534
534
|
expect(runner.errors.size).to eq(0)
|
535
535
|
end
|
536
536
|
end
|
537
537
|
|
538
|
-
context
|
539
|
-
it
|
538
|
+
context 'methods hash' do
|
539
|
+
it 'should not remove unused method with methods hash' do
|
540
540
|
content =<<-EOF
|
541
541
|
class Post < ActiveRecord::Base
|
542
542
|
def to_xml(options = {})
|
@@ -546,15 +546,15 @@ module RailsBestPractices
|
|
546
546
|
def is_discussion_conversation; end
|
547
547
|
end
|
548
548
|
EOF
|
549
|
-
runner.prepare(
|
550
|
-
runner.review(
|
549
|
+
runner.prepare('app/models/post.rb', content)
|
550
|
+
runner.review('app/models/post.rb', content)
|
551
551
|
runner.after_review
|
552
552
|
expect(runner.errors.size).to eq(0)
|
553
553
|
end
|
554
554
|
end
|
555
555
|
|
556
|
-
context
|
557
|
-
it
|
556
|
+
context 'callbacks' do
|
557
|
+
it 'should not remove unused method' do
|
558
558
|
content =<<-EOF
|
559
559
|
class Post < ActiveRecord::Base
|
560
560
|
before_save :init_columns
|
@@ -565,15 +565,15 @@ module RailsBestPractices
|
|
565
565
|
def remove_dependencies; end
|
566
566
|
end
|
567
567
|
EOF
|
568
|
-
runner.prepare(
|
569
|
-
runner.review(
|
568
|
+
runner.prepare('app/models/post.rb', content)
|
569
|
+
runner.review('app/models/post.rb', content)
|
570
570
|
runner.after_review
|
571
571
|
expect(runner.errors.size).to eq(0)
|
572
572
|
end
|
573
573
|
end
|
574
574
|
|
575
|
-
context
|
576
|
-
it
|
575
|
+
context 'validates' do
|
576
|
+
it 'should not remove unused method' do
|
577
577
|
content =<<-EOF
|
578
578
|
class Post < ActiveRecord::Base
|
579
579
|
validate :valid_birth_date
|
@@ -582,13 +582,13 @@ module RailsBestPractices
|
|
582
582
|
def valid_birth_date; end
|
583
583
|
end
|
584
584
|
EOF
|
585
|
-
runner.prepare(
|
586
|
-
runner.review(
|
585
|
+
runner.prepare('app/models/post.rb', content)
|
586
|
+
runner.review('app/models/post.rb', content)
|
587
587
|
runner.after_review
|
588
588
|
expect(runner.errors.size).to eq(0)
|
589
589
|
end
|
590
590
|
|
591
|
-
it
|
591
|
+
it 'should not remove unused method for validate_on_create and validate_on_update' do
|
592
592
|
content =<<-EOF
|
593
593
|
class Post < ActiveRecord::Base
|
594
594
|
validate_on_create :valid_email
|
@@ -599,13 +599,13 @@ module RailsBestPractices
|
|
599
599
|
def valid_birth_date; end
|
600
600
|
end
|
601
601
|
EOF
|
602
|
-
runner.prepare(
|
603
|
-
runner.review(
|
602
|
+
runner.prepare('app/models/post.rb', content)
|
603
|
+
runner.review('app/models/post.rb', content)
|
604
604
|
runner.after_review
|
605
605
|
expect(runner.errors.size).to eq(0)
|
606
606
|
end
|
607
607
|
|
608
|
-
it
|
608
|
+
it 'should not remove unused methods for to_param' do
|
609
609
|
content =<<-EOF
|
610
610
|
class Post < ActiveRecord::Base
|
611
611
|
def to_param
|
@@ -613,83 +613,83 @@ module RailsBestPractices
|
|
613
613
|
end
|
614
614
|
end
|
615
615
|
EOF
|
616
|
-
runner.prepare(
|
617
|
-
runner.review(
|
616
|
+
runner.prepare('app/models/post.rb', content)
|
617
|
+
runner.review('app/models/post.rb', content)
|
618
618
|
runner.after_review
|
619
619
|
expect(runner.errors.size).to eq(0)
|
620
620
|
end
|
621
621
|
end
|
622
622
|
|
623
|
-
context
|
624
|
-
it
|
623
|
+
context 'helper method' do
|
624
|
+
it 'should not remove unused method for coommand_call collection_select' do
|
625
625
|
content =<<-EOF
|
626
626
|
class Category < ActiveRecord::Base
|
627
627
|
def indented_name; end
|
628
628
|
end
|
629
629
|
EOF
|
630
|
-
runner.prepare(
|
631
|
-
runner.review(
|
630
|
+
runner.prepare('app/models/category.rb', content)
|
631
|
+
runner.review('app/models/category.rb', content)
|
632
632
|
content =<<-EOF
|
633
633
|
<%= f.collection_select :parent_id, Category.all_hierarchic(except: @category), :id, :indented_name, {include_blank: true} %>
|
634
634
|
EOF
|
635
|
-
runner.review(
|
635
|
+
runner.review('app/views/categories/_form.html.erb', content)
|
636
636
|
runner.after_review
|
637
637
|
expect(runner.errors.size).to eq(0)
|
638
638
|
end
|
639
639
|
|
640
|
-
it
|
640
|
+
it 'should not remove unused method for command collection_select' do
|
641
641
|
content =<<-EOF
|
642
642
|
class Category < ActiveRecord::Base
|
643
643
|
def indented_name; end
|
644
644
|
end
|
645
645
|
EOF
|
646
|
-
runner.prepare(
|
647
|
-
runner.review(
|
646
|
+
runner.prepare('app/models/category.rb', content)
|
647
|
+
runner.review('app/models/category.rb', content)
|
648
648
|
content =<<-EOF
|
649
649
|
<%= collection_select :category, :parent_id, Category.all_hierarchic(except: @category), :id, :indented_name, {include_blank: true} %>
|
650
650
|
EOF
|
651
|
-
runner.review(
|
651
|
+
runner.review('app/views/categories/_form.html.erb', content)
|
652
652
|
runner.after_review
|
653
653
|
expect(runner.errors.size).to eq(0)
|
654
654
|
end
|
655
655
|
|
656
|
-
it
|
656
|
+
it 'should not remove unused method for options_from_collection_for_select' do
|
657
657
|
content =<<-EOF
|
658
658
|
class Category < ActiveRecord::Base
|
659
659
|
def indented_name; end
|
660
660
|
end
|
661
661
|
EOF
|
662
|
-
runner.prepare(
|
663
|
-
runner.review(
|
662
|
+
runner.prepare('app/models/category.rb', content)
|
663
|
+
runner.review('app/models/category.rb', content)
|
664
664
|
content =<<-EOF
|
665
665
|
<%= select_tag 'category', options_from_collection_for_select(Category.all_hierachic(except: @category), :id, :indented_name) %>
|
666
666
|
EOF
|
667
|
-
runner.review(
|
667
|
+
runner.review('app/views/categories/_form.html.erb', content)
|
668
668
|
runner.after_review
|
669
669
|
expect(runner.errors.size).to eq(0)
|
670
670
|
end
|
671
671
|
end
|
672
672
|
|
673
|
-
it
|
673
|
+
it 'should not remove unused methods for rabl view' do
|
674
674
|
content =<<-EOF
|
675
675
|
class User
|
676
676
|
def first_name; end
|
677
677
|
def last_name; end
|
678
678
|
end
|
679
679
|
EOF
|
680
|
-
runner.prepare(
|
681
|
-
runner.review(
|
680
|
+
runner.prepare('app/models/user.rb', content)
|
681
|
+
runner.review('app/models/user.rb', content)
|
682
682
|
content =<<-EOF
|
683
683
|
node :full_name do |u|
|
684
684
|
u.first_name + " " + u.last_name
|
685
685
|
end
|
686
686
|
EOF
|
687
|
-
runner.review(
|
687
|
+
runner.review('app/views/users/show.json.rabl', content)
|
688
688
|
runner.after_review
|
689
689
|
expect(runner.errors.size).to eq(0)
|
690
690
|
end
|
691
691
|
|
692
|
-
it
|
692
|
+
it 'should not skip :call as call message' do
|
693
693
|
content =<<-EOF
|
694
694
|
module DateRange
|
695
695
|
RANGES = lambda {
|
@@ -700,11 +700,11 @@ module RailsBestPractices
|
|
700
700
|
}[]
|
701
701
|
end
|
702
702
|
EOF
|
703
|
-
runner.prepare(
|
704
|
-
runner.review(
|
703
|
+
runner.prepare('app/mixins/date_range.rb', content)
|
704
|
+
runner.review('app/mixins/date_range.rb', content)
|
705
705
|
end
|
706
706
|
|
707
|
-
it
|
707
|
+
it 'should not check ignored files' do
|
708
708
|
runner = Core::Runner.new(prepares: Prepares::ModelPrepare.new,
|
709
709
|
reviews: RemoveUnusedMethodsInModelsReview.new(except_methods: [], ignored_files: /post/))
|
710
710
|
|