rails_best_practices 1.19.1 → 1.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Guardfile +1 -1
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/bin/rails_best_practices +2 -1
- data/lib/rails_best_practices.rb +2 -1
- data/lib/rails_best_practices/analyzer.rb +13 -12
- data/lib/rails_best_practices/colorize.rb +2 -0
- data/lib/rails_best_practices/command.rb +6 -5
- data/lib/rails_best_practices/core.rb +2 -1
- data/lib/rails_best_practices/core/check.rb +19 -17
- data/lib/rails_best_practices/core/checks_loader.rb +3 -2
- data/lib/rails_best_practices/core/configs.rb +2 -1
- data/lib/rails_best_practices/core/controllers.rb +4 -1
- data/lib/rails_best_practices/core/error.rb +3 -2
- data/lib/rails_best_practices/core/gems.rb +4 -3
- data/lib/rails_best_practices/core/helpers.rb +4 -1
- data/lib/rails_best_practices/core/klasses.rb +3 -2
- data/lib/rails_best_practices/core/mailers.rb +2 -1
- data/lib/rails_best_practices/core/methods.rb +9 -10
- data/lib/rails_best_practices/core/model_associations.rb +6 -5
- data/lib/rails_best_practices/core/model_attributes.rb +2 -1
- data/lib/rails_best_practices/core/models.rb +2 -1
- data/lib/rails_best_practices/core/modules.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +2 -1
- data/lib/rails_best_practices/core/runner.rb +7 -6
- data/lib/rails_best_practices/core_ext/erubis.rb +4 -5
- data/lib/rails_best_practices/lexicals.rb +2 -1
- data/lib/rails_best_practices/lexicals/long_line_check.rb +2 -1
- data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -1
- data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -1
- data/lib/rails_best_practices/prepares.rb +2 -1
- data/lib/rails_best_practices/prepares/config_prepare.rb +3 -2
- data/lib/rails_best_practices/prepares/controller_prepare.rb +9 -8
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/helper_prepare.rb +4 -3
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +3 -2
- data/lib/rails_best_practices/prepares/model_prepare.rb +12 -12
- data/lib/rails_best_practices/prepares/route_prepare.rb +8 -7
- data/lib/rails_best_practices/prepares/schema_prepare.rb +3 -2
- data/lib/rails_best_practices/reviews.rb +2 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +7 -4
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +8 -7
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +4 -3
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +5 -4
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -1
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -1
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +2 -1
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +3 -2
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -1
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +5 -4
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -1
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -1
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -2
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +4 -3
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -1
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -10
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +4 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +6 -5
- 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 -1
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +8 -8
- data/lib/rails_best_practices/reviews/review.rb +4 -3
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -2
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +5 -4
- 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 +5 -5
- data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +4 -3
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +4 -3
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
- data/lib/rails_best_practices/version.rb +3 -2
- data/rails_best_practices.gemspec +11 -10
- data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +3 -2
- data/spec/rails_best_practices/analyzer_spec.rb +6 -8
- data/spec/rails_best_practices/core/check_spec.rb +2 -0
- data/spec/rails_best_practices/core/checks_loader_spec.rb +2 -0
- data/spec/rails_best_practices/core/configs_spec.rb +2 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +2 -0
- data/spec/rails_best_practices/core/error_spec.rb +2 -0
- data/spec/rails_best_practices/core/except_methods_spec.rb +2 -0
- data/spec/rails_best_practices/core/gems_spec.rb +2 -0
- data/spec/rails_best_practices/core/helpers_spec.rb +2 -0
- data/spec/rails_best_practices/core/klasses_spec.rb +2 -0
- data/spec/rails_best_practices/core/mailers_spec.rb +2 -0
- data/spec/rails_best_practices/core/methods_spec.rb +6 -4
- data/spec/rails_best_practices/core/model_associations_spec.rb +4 -2
- data/spec/rails_best_practices/core/model_attributes_spec.rb +2 -0
- data/spec/rails_best_practices/core/models_spec.rb +2 -0
- data/spec/rails_best_practices/core/modules_spec.rb +2 -0
- data/spec/rails_best_practices/core/routes_spec.rb +4 -2
- data/spec/rails_best_practices/core/runner_spec.rb +2 -0
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +3 -1
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +8 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +8 -6
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +9 -7
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +23 -21
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +7 -5
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +4 -2
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +56 -54
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +39 -37
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +12 -10
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +20 -18
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +11 -9
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +21 -19
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -4
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -31
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +13 -11
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +65 -63
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +24 -22
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -11
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +26 -26
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -9,7 +11,7 @@ module RailsBestPractices
|
|
9
11
|
) }
|
10
12
|
|
11
13
|
it 'should remove unused methods' do
|
12
|
-
content
|
14
|
+
content = <<-EOF
|
13
15
|
module PostsHelper
|
14
16
|
def unused; end
|
15
17
|
end
|
@@ -22,14 +24,14 @@ module RailsBestPractices
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'should not remove unused methods if called on views' do
|
25
|
-
content
|
27
|
+
content = <<-EOF
|
26
28
|
module PostsHelper
|
27
29
|
def used?(post); end
|
28
30
|
end
|
29
31
|
EOF
|
30
32
|
runner.prepare('app/helpers/posts_helper.rb', content)
|
31
33
|
runner.review('app/helpers/posts_helper.rb', content)
|
32
|
-
content
|
34
|
+
content = <<-EOF
|
33
35
|
<% if used?(@post) %>
|
34
36
|
<% end %>
|
35
37
|
EOF
|
@@ -39,7 +41,7 @@ module RailsBestPractices
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'should not remove unused methods if called on helpers' do
|
42
|
-
content
|
44
|
+
content = <<-EOF
|
43
45
|
module PostsHelper
|
44
46
|
def used?(post)
|
45
47
|
test?(post)
|
@@ -50,7 +52,7 @@ module RailsBestPractices
|
|
50
52
|
EOF
|
51
53
|
runner.prepare('app/helpers/posts_helper.rb', content)
|
52
54
|
runner.review('app/helpers/posts_helper.rb', content)
|
53
|
-
content
|
55
|
+
content = <<-EOF
|
54
56
|
<% if used?(@post) %>
|
55
57
|
<% end %>
|
56
58
|
EOF
|
@@ -60,12 +62,12 @@ module RailsBestPractices
|
|
60
62
|
end
|
61
63
|
|
62
64
|
it 'should not remove unused methods if called on controllers' do
|
63
|
-
helper_content
|
65
|
+
helper_content = <<-EOF
|
64
66
|
module PostsHelper
|
65
67
|
def used?(post); end
|
66
68
|
end
|
67
69
|
EOF
|
68
|
-
controller_content
|
70
|
+
controller_content = <<-EOF
|
69
71
|
class PostsController < InheritedResources::Base
|
70
72
|
include PostsHelper
|
71
73
|
|
@@ -85,17 +87,17 @@ module RailsBestPractices
|
|
85
87
|
end
|
86
88
|
|
87
89
|
it 'should not remove unused methods if called in descendant controllers' do
|
88
|
-
application_helper_content
|
90
|
+
application_helper_content = <<-EOF
|
89
91
|
module ApplicationHelper
|
90
92
|
def admin?; end
|
91
93
|
end
|
92
94
|
EOF
|
93
|
-
application_controller_content
|
95
|
+
application_controller_content = <<-EOF
|
94
96
|
class ApplicationController
|
95
97
|
include ApplicationHelper
|
96
98
|
end
|
97
99
|
EOF
|
98
|
-
controller_content
|
100
|
+
controller_content = <<-EOF
|
99
101
|
class PostsController < ApplicationController
|
100
102
|
|
101
103
|
def show
|
@@ -118,7 +120,7 @@ module RailsBestPractices
|
|
118
120
|
runner = Core::Runner.new(prepares: [Prepares::ControllerPrepare.new, Prepares::HelperPrepare.new],
|
119
121
|
reviews: RemoveUnusedMethodsInHelpersReview.new(ignored_files: /posts_helper/, except_methods: []))
|
120
122
|
|
121
|
-
content
|
123
|
+
content = <<-EOF
|
122
124
|
module PostsHelper
|
123
125
|
def unused; end
|
124
126
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -5,12 +7,12 @@ module RailsBestPractices
|
|
5
7
|
describe RemoveUnusedMethodsInModelsReview do
|
6
8
|
let(:runner) { Core::Runner.new(
|
7
9
|
prepares: Prepares::ModelPrepare.new,
|
8
|
-
reviews: RemoveUnusedMethodsInModelsReview.new(
|
10
|
+
reviews: RemoveUnusedMethodsInModelsReview.new('except_methods' => ['*#set_cache'])
|
9
11
|
) }
|
10
12
|
|
11
13
|
context 'private' do
|
12
14
|
it 'should remove unused methods' do
|
13
|
-
content
|
15
|
+
content = <<-EOF
|
14
16
|
class Post < ActiveRecord::Base
|
15
17
|
def find; end
|
16
18
|
private
|
@@ -19,7 +21,7 @@ module RailsBestPractices
|
|
19
21
|
EOF
|
20
22
|
runner.prepare('app/models/post.rb', content)
|
21
23
|
runner.review('app/models/post.rb', content)
|
22
|
-
content
|
24
|
+
content = <<-EOF
|
23
25
|
class PostsController < ApplicationController
|
24
26
|
def get
|
25
27
|
Post.new.find
|
@@ -33,7 +35,7 @@ module RailsBestPractices
|
|
33
35
|
end
|
34
36
|
|
35
37
|
it 'should not remove unused methods with except_methods' do
|
36
|
-
content
|
38
|
+
content = <<-EOF
|
37
39
|
class Post < ActiveRecord::Base
|
38
40
|
def set_cache; end
|
39
41
|
end
|
@@ -45,7 +47,7 @@ module RailsBestPractices
|
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'should not remove unused methods with var_ref' do
|
48
|
-
content
|
50
|
+
content = <<-EOF
|
49
51
|
class Post < ActiveRecord::Base
|
50
52
|
def find
|
51
53
|
find_by_sql
|
@@ -56,7 +58,7 @@ module RailsBestPractices
|
|
56
58
|
EOF
|
57
59
|
runner.prepare('app/models/post.rb', content)
|
58
60
|
runner.review('app/models/post.rb', content)
|
59
|
-
content
|
61
|
+
content = <<-EOF
|
60
62
|
class PostsController < ApplicationController
|
61
63
|
def get
|
62
64
|
Post.new.find
|
@@ -69,7 +71,7 @@ module RailsBestPractices
|
|
69
71
|
end
|
70
72
|
|
71
73
|
it 'should not remove unused methods with callback' do
|
72
|
-
content
|
74
|
+
content = <<-EOF
|
73
75
|
class Post < ActiveRecord::Base
|
74
76
|
after_save :expire_cache
|
75
77
|
private
|
@@ -83,7 +85,7 @@ module RailsBestPractices
|
|
83
85
|
end
|
84
86
|
|
85
87
|
it 'should not remove unused method with command' do
|
86
|
-
content
|
88
|
+
content = <<-EOF
|
87
89
|
class Post < ActiveRecord::Base
|
88
90
|
def fetch
|
89
91
|
get(position: 'first')
|
@@ -94,7 +96,7 @@ module RailsBestPractices
|
|
94
96
|
EOF
|
95
97
|
runner.prepare('app/models/post.rb', content)
|
96
98
|
runner.review('app/models/post.rb', content)
|
97
|
-
content
|
99
|
+
content = <<-EOF
|
98
100
|
class PostsController < ApplicationController
|
99
101
|
def get
|
100
102
|
Post.new.fetch
|
@@ -107,7 +109,7 @@ module RailsBestPractices
|
|
107
109
|
end
|
108
110
|
|
109
111
|
it 'should not remove unused method with call' do
|
110
|
-
content
|
112
|
+
content = <<-EOF
|
111
113
|
class Post < ActiveRecord::Base
|
112
114
|
def conditions
|
113
115
|
self.build_conditions({})
|
@@ -118,7 +120,7 @@ module RailsBestPractices
|
|
118
120
|
EOF
|
119
121
|
runner.prepare('app/models/post.rb', content)
|
120
122
|
runner.review('app/models/post.rb', content)
|
121
|
-
content
|
123
|
+
content = <<-EOF
|
122
124
|
class PostsController < ApplicationController
|
123
125
|
def get
|
124
126
|
Post.new.conditions
|
@@ -131,7 +133,7 @@ module RailsBestPractices
|
|
131
133
|
end
|
132
134
|
|
133
135
|
it 'should not remove unused method with message' do
|
134
|
-
content
|
136
|
+
content = <<-EOF
|
135
137
|
class Post < ActiveRecord::Base
|
136
138
|
def save
|
137
139
|
transaction true do
|
@@ -144,7 +146,7 @@ module RailsBestPractices
|
|
144
146
|
EOF
|
145
147
|
runner.prepare('app/models/post.rb', content)
|
146
148
|
runner.review('app/models/post.rb', content)
|
147
|
-
content
|
149
|
+
content = <<-EOF
|
148
150
|
class PostsController < ApplicationController
|
149
151
|
def create
|
150
152
|
Post.new.save
|
@@ -157,7 +159,7 @@ module RailsBestPractices
|
|
157
159
|
end
|
158
160
|
|
159
161
|
it 'should not remove unused method with validation condition' do
|
160
|
-
content
|
162
|
+
content = <<-EOF
|
161
163
|
class Post < ActiveRecord::Base
|
162
164
|
validates_uniqueness_of :login, if: :email_blank?
|
163
165
|
private
|
@@ -171,7 +173,7 @@ module RailsBestPractices
|
|
171
173
|
end
|
172
174
|
|
173
175
|
it 'should not remove unused method with aasm' do
|
174
|
-
content
|
176
|
+
content = <<-EOF
|
175
177
|
class Post < ActiveRecord::Base
|
176
178
|
aasm_state :accepted, enter: [:update_datetime]
|
177
179
|
private
|
@@ -185,7 +187,7 @@ module RailsBestPractices
|
|
185
187
|
end
|
186
188
|
|
187
189
|
it 'should not remove unused method with initialize' do
|
188
|
-
content
|
190
|
+
content = <<-EOF
|
189
191
|
class Post < ActiveRecord::Base
|
190
192
|
private
|
191
193
|
def initialize; end
|
@@ -200,7 +202,7 @@ module RailsBestPractices
|
|
200
202
|
|
201
203
|
context 'public' do
|
202
204
|
it 'should remove unused methods' do
|
203
|
-
content
|
205
|
+
content = <<-EOF
|
204
206
|
class Post < ActiveRecord::Base
|
205
207
|
def fetch; end
|
206
208
|
end
|
@@ -212,13 +214,13 @@ module RailsBestPractices
|
|
212
214
|
end
|
213
215
|
|
214
216
|
it 'should not remove unused methods' do
|
215
|
-
content
|
217
|
+
content = <<-EOF
|
216
218
|
class Post < ActiveRecord::Base
|
217
219
|
def fetch; end
|
218
220
|
end
|
219
221
|
EOF
|
220
222
|
runner.prepare('app/models/post.rb', content)
|
221
|
-
content
|
223
|
+
content = <<-EOF
|
222
224
|
class PostsController < ApplicationController
|
223
225
|
def show
|
224
226
|
@post.fetch
|
@@ -231,7 +233,7 @@ module RailsBestPractices
|
|
231
233
|
end
|
232
234
|
|
233
235
|
it 'should not remove unused methods for attribute assignment' do
|
234
|
-
content
|
236
|
+
content = <<-EOF
|
235
237
|
class Post < ActiveRecord::Base
|
236
238
|
def user=(user); end
|
237
239
|
end
|
@@ -243,14 +245,14 @@ module RailsBestPractices
|
|
243
245
|
end
|
244
246
|
|
245
247
|
it 'should not remove unused methods for try' do
|
246
|
-
content
|
248
|
+
content = <<-EOF
|
247
249
|
class Post < ActiveRecord::Base
|
248
250
|
def find(user_id); end
|
249
251
|
end
|
250
252
|
EOF
|
251
253
|
runner.prepare('app/models/post.rb', content)
|
252
254
|
runner.review('app/models/post.rb', content)
|
253
|
-
content
|
255
|
+
content = <<-EOF
|
254
256
|
class PostsController < ApplicationController
|
255
257
|
def find
|
256
258
|
Post.new.try(:find, current_user.id)
|
@@ -263,14 +265,14 @@ module RailsBestPractices
|
|
263
265
|
end
|
264
266
|
|
265
267
|
it 'should not remove unused methods for send' do
|
266
|
-
content
|
268
|
+
content = <<-EOF
|
267
269
|
class Post < ActiveRecord::Base
|
268
270
|
def find(user_id); end
|
269
271
|
end
|
270
272
|
EOF
|
271
273
|
runner.prepare('app/models/post.rb', content)
|
272
274
|
runner.review('app/models/post.rb', content)
|
273
|
-
content
|
275
|
+
content = <<-EOF
|
274
276
|
class PostsController < ApplicationController
|
275
277
|
def find
|
276
278
|
Post.new.send(:find, current_user.id)
|
@@ -283,14 +285,14 @@ module RailsBestPractices
|
|
283
285
|
end
|
284
286
|
|
285
287
|
it 'should remove unused methods for send string_embexpre' do
|
286
|
-
content
|
288
|
+
content = <<-EOF
|
287
289
|
class Post < ActiveRecord::Base
|
288
290
|
def find_first; end
|
289
291
|
end
|
290
292
|
EOF
|
291
293
|
runner.prepare('app/models/post.rb', content)
|
292
294
|
runner.review('app/models/post.rb', content)
|
293
|
-
content
|
295
|
+
content = <<-EOF
|
294
296
|
class PostsController < ApplicationController
|
295
297
|
def find
|
296
298
|
type = "first"
|
@@ -304,14 +306,14 @@ module RailsBestPractices
|
|
304
306
|
end
|
305
307
|
|
306
308
|
it 'should remove unused methods for send variable' do
|
307
|
-
content
|
309
|
+
content = <<-EOF
|
308
310
|
class Post < ActiveRecord::Base
|
309
311
|
def first; end
|
310
312
|
end
|
311
313
|
EOF
|
312
314
|
runner.prepare('app/models/post.rb', content)
|
313
315
|
runner.review('app/models/post.rb', content)
|
314
|
-
content
|
316
|
+
content = <<-EOF
|
315
317
|
class PostsController < ApplicationController
|
316
318
|
def find
|
317
319
|
type = "first"
|
@@ -327,7 +329,7 @@ module RailsBestPractices
|
|
327
329
|
|
328
330
|
context 'protected' do
|
329
331
|
it 'should not remove unused methods' do
|
330
|
-
content
|
332
|
+
content = <<-EOF
|
331
333
|
class Post < ActiveRecord::Base
|
332
334
|
protected
|
333
335
|
def test; end
|
@@ -335,7 +337,7 @@ module RailsBestPractices
|
|
335
337
|
EOF
|
336
338
|
runner.prepare('app/models/post.rb', content)
|
337
339
|
runner.review('app/models/post.rb', content)
|
338
|
-
content
|
340
|
+
content = <<-EOF
|
339
341
|
class PostsController < ApplicationController
|
340
342
|
def test
|
341
343
|
Post.new.test
|
@@ -349,13 +351,13 @@ module RailsBestPractices
|
|
349
351
|
end
|
350
352
|
|
351
353
|
it 'should not remove unused methods' do
|
352
|
-
post_content
|
354
|
+
post_content = <<-EOF
|
353
355
|
class Post < ActiveRecord::Base
|
354
356
|
protected
|
355
357
|
def test; end
|
356
358
|
end
|
357
359
|
EOF
|
358
|
-
blog_post_content
|
360
|
+
blog_post_content = <<-EOF
|
359
361
|
class BlogPost < Post
|
360
362
|
def play
|
361
363
|
test
|
@@ -366,7 +368,7 @@ module RailsBestPractices
|
|
366
368
|
runner.prepare('app/models/blog_post.rb', blog_post_content)
|
367
369
|
runner.review('app/models/post.rb', post_content)
|
368
370
|
runner.review('app/models/blog_post.rb', blog_post_content)
|
369
|
-
content
|
371
|
+
content = <<-EOF
|
370
372
|
class BlogPostsController < ApplicationController
|
371
373
|
def play
|
372
374
|
BlogPost.new.play
|
@@ -381,14 +383,14 @@ module RailsBestPractices
|
|
381
383
|
|
382
384
|
context 'named_scope' do
|
383
385
|
it 'should not remove unused named_scope' do
|
384
|
-
content
|
386
|
+
content = <<-EOF
|
385
387
|
class Post < ActiveRecord::Base
|
386
388
|
named_scope :active, conditions: {active: true}
|
387
389
|
end
|
388
390
|
EOF
|
389
391
|
runner.prepare('app/models/post.rb', content)
|
390
392
|
runner.review('app/models/post.rb', content)
|
391
|
-
content
|
393
|
+
content = <<-EOF
|
392
394
|
class PostsController < ApplicationController
|
393
395
|
def index
|
394
396
|
@posts = Post.active
|
@@ -401,7 +403,7 @@ module RailsBestPractices
|
|
401
403
|
end
|
402
404
|
|
403
405
|
it 'should remove unused named_scope' do
|
404
|
-
content
|
406
|
+
content = <<-EOF
|
405
407
|
class Post < ActiveRecord::Base
|
406
408
|
named_scope :active, conditions: {active: true}
|
407
409
|
end
|
@@ -416,14 +418,14 @@ module RailsBestPractices
|
|
416
418
|
|
417
419
|
context 'scope' do
|
418
420
|
it 'should not remove unused scope' do
|
419
|
-
content
|
421
|
+
content = <<-EOF
|
420
422
|
class Post < ActiveRecord::Base
|
421
423
|
scope :active, where(active: true)
|
422
424
|
end
|
423
425
|
EOF
|
424
426
|
runner.prepare('app/models/post.rb', content)
|
425
427
|
runner.review('app/models/post.rb', content)
|
426
|
-
content
|
428
|
+
content = <<-EOF
|
427
429
|
class PostsController < ApplicationController
|
428
430
|
def index
|
429
431
|
@posts = Post.active
|
@@ -436,7 +438,7 @@ module RailsBestPractices
|
|
436
438
|
end
|
437
439
|
|
438
440
|
it 'should remove unused named_scope' do
|
439
|
-
content
|
441
|
+
content = <<-EOF
|
440
442
|
class Post < ActiveRecord::Base
|
441
443
|
scope :active, where(active: true)
|
442
444
|
end
|
@@ -451,7 +453,7 @@ module RailsBestPractices
|
|
451
453
|
|
452
454
|
context 'alias' do
|
453
455
|
it 'should not remove unused method with alias' do
|
454
|
-
content
|
456
|
+
content = <<-EOF
|
455
457
|
class Post < ActiveRecord::Base
|
456
458
|
def old; end
|
457
459
|
alias new old
|
@@ -459,7 +461,7 @@ module RailsBestPractices
|
|
459
461
|
EOF
|
460
462
|
runner.prepare('app/models/post.rb', content)
|
461
463
|
runner.review('app/models/post.rb', content)
|
462
|
-
content
|
464
|
+
content = <<-EOF
|
463
465
|
class PostsController < ApplicationController
|
464
466
|
def show
|
465
467
|
@post.new
|
@@ -472,7 +474,7 @@ module RailsBestPractices
|
|
472
474
|
end
|
473
475
|
|
474
476
|
it 'should not remove unused method with symbol alias' do
|
475
|
-
content
|
477
|
+
content = <<-EOF
|
476
478
|
class Post < ActiveRecord::Base
|
477
479
|
def old; end
|
478
480
|
alias :new :old
|
@@ -480,7 +482,7 @@ module RailsBestPractices
|
|
480
482
|
EOF
|
481
483
|
runner.prepare('app/models/post.rb', content)
|
482
484
|
runner.review('app/models/post.rb', content)
|
483
|
-
content
|
485
|
+
content = <<-EOF
|
484
486
|
class PostsController < ApplicationController
|
485
487
|
def show
|
486
488
|
@post.new
|
@@ -493,7 +495,7 @@ module RailsBestPractices
|
|
493
495
|
end
|
494
496
|
|
495
497
|
it 'should not remove unused method with alias_method' do
|
496
|
-
content
|
498
|
+
content = <<-EOF
|
497
499
|
class Post < ActiveRecord::Base
|
498
500
|
def old; end
|
499
501
|
alias_method :new, :old
|
@@ -501,7 +503,7 @@ module RailsBestPractices
|
|
501
503
|
EOF
|
502
504
|
runner.prepare('app/models/post.rb', content)
|
503
505
|
runner.review('app/models/post.rb', content)
|
504
|
-
content
|
506
|
+
content = <<-EOF
|
505
507
|
class PostsController < ApplicationController
|
506
508
|
def show
|
507
509
|
@post.new
|
@@ -514,7 +516,7 @@ module RailsBestPractices
|
|
514
516
|
end
|
515
517
|
|
516
518
|
it 'should not remove unused method with alias_method_chain' do
|
517
|
-
content
|
519
|
+
content = <<-EOF
|
518
520
|
class Post < ActiveRecord::Base
|
519
521
|
def method_with_feature; end
|
520
522
|
alias_method_chain :method, :feature
|
@@ -522,7 +524,7 @@ module RailsBestPractices
|
|
522
524
|
EOF
|
523
525
|
runner.prepare('app/models/post.rb', content)
|
524
526
|
runner.review('app/models/post.rb', content)
|
525
|
-
content
|
527
|
+
content = <<-EOF
|
526
528
|
class PostsController < ApplicationController
|
527
529
|
def show
|
528
530
|
@post.method
|
@@ -537,7 +539,7 @@ module RailsBestPractices
|
|
537
539
|
|
538
540
|
context 'methods hash' do
|
539
541
|
it 'should not remove unused method with methods hash' do
|
540
|
-
content
|
542
|
+
content = <<-EOF
|
541
543
|
class Post < ActiveRecord::Base
|
542
544
|
def to_xml(options = {})
|
543
545
|
super options.merge(exclude: :visible, methods: [:is_discussion_conversation])
|
@@ -555,7 +557,7 @@ module RailsBestPractices
|
|
555
557
|
|
556
558
|
context 'callbacks' do
|
557
559
|
it 'should not remove unused method' do
|
558
|
-
content
|
560
|
+
content = <<-EOF
|
559
561
|
class Post < ActiveRecord::Base
|
560
562
|
before_save :init_columns
|
561
563
|
after_destroy :remove_dependencies
|
@@ -574,7 +576,7 @@ module RailsBestPractices
|
|
574
576
|
|
575
577
|
context 'validates' do
|
576
578
|
it 'should not remove unused method' do
|
577
|
-
content
|
579
|
+
content = <<-EOF
|
578
580
|
class Post < ActiveRecord::Base
|
579
581
|
validate :valid_birth_date
|
580
582
|
|
@@ -589,7 +591,7 @@ module RailsBestPractices
|
|
589
591
|
end
|
590
592
|
|
591
593
|
it 'should not remove unused method for validate_on_create and validate_on_update' do
|
592
|
-
content
|
594
|
+
content = <<-EOF
|
593
595
|
class Post < ActiveRecord::Base
|
594
596
|
validate_on_create :valid_email
|
595
597
|
validate_on_update :valid_birth_date
|
@@ -606,7 +608,7 @@ module RailsBestPractices
|
|
606
608
|
end
|
607
609
|
|
608
610
|
it 'should not remove unused methods for to_param' do
|
609
|
-
content
|
611
|
+
content = <<-EOF
|
610
612
|
class Post < ActiveRecord::Base
|
611
613
|
def to_param
|
612
614
|
id
|
@@ -622,14 +624,14 @@ module RailsBestPractices
|
|
622
624
|
|
623
625
|
context 'helper method' do
|
624
626
|
it 'should not remove unused method for coommand_call collection_select' do
|
625
|
-
content
|
627
|
+
content = <<-EOF
|
626
628
|
class Category < ActiveRecord::Base
|
627
629
|
def indented_name; end
|
628
630
|
end
|
629
631
|
EOF
|
630
632
|
runner.prepare('app/models/category.rb', content)
|
631
633
|
runner.review('app/models/category.rb', content)
|
632
|
-
content
|
634
|
+
content = <<-EOF
|
633
635
|
<%= f.collection_select :parent_id, Category.all_hierarchic(except: @category), :id, :indented_name, {include_blank: true} %>
|
634
636
|
EOF
|
635
637
|
runner.review('app/views/categories/_form.html.erb', content)
|
@@ -638,14 +640,14 @@ module RailsBestPractices
|
|
638
640
|
end
|
639
641
|
|
640
642
|
it 'should not remove unused method for command collection_select' do
|
641
|
-
content
|
643
|
+
content = <<-EOF
|
642
644
|
class Category < ActiveRecord::Base
|
643
645
|
def indented_name; end
|
644
646
|
end
|
645
647
|
EOF
|
646
648
|
runner.prepare('app/models/category.rb', content)
|
647
649
|
runner.review('app/models/category.rb', content)
|
648
|
-
content
|
650
|
+
content = <<-EOF
|
649
651
|
<%= collection_select :category, :parent_id, Category.all_hierarchic(except: @category), :id, :indented_name, {include_blank: true} %>
|
650
652
|
EOF
|
651
653
|
runner.review('app/views/categories/_form.html.erb', content)
|
@@ -654,14 +656,14 @@ module RailsBestPractices
|
|
654
656
|
end
|
655
657
|
|
656
658
|
it 'should not remove unused method for options_from_collection_for_select' do
|
657
|
-
content
|
659
|
+
content = <<-EOF
|
658
660
|
class Category < ActiveRecord::Base
|
659
661
|
def indented_name; end
|
660
662
|
end
|
661
663
|
EOF
|
662
664
|
runner.prepare('app/models/category.rb', content)
|
663
665
|
runner.review('app/models/category.rb', content)
|
664
|
-
content
|
666
|
+
content = <<-EOF
|
665
667
|
<%= select_tag 'category', options_from_collection_for_select(Category.all_hierachic(except: @category), :id, :indented_name) %>
|
666
668
|
EOF
|
667
669
|
runner.review('app/views/categories/_form.html.erb', content)
|
@@ -671,7 +673,7 @@ module RailsBestPractices
|
|
671
673
|
end
|
672
674
|
|
673
675
|
it 'should not remove unused methods for rabl view' do
|
674
|
-
content
|
676
|
+
content = <<-EOF
|
675
677
|
class User
|
676
678
|
def first_name; end
|
677
679
|
def last_name; end
|
@@ -679,7 +681,7 @@ module RailsBestPractices
|
|
679
681
|
EOF
|
680
682
|
runner.prepare('app/models/user.rb', content)
|
681
683
|
runner.review('app/models/user.rb', content)
|
682
|
-
content
|
684
|
+
content = <<-EOF
|
683
685
|
node :full_name do |u|
|
684
686
|
u.first_name + " " + u.last_name
|
685
687
|
end
|
@@ -690,7 +692,7 @@ module RailsBestPractices
|
|
690
692
|
end
|
691
693
|
|
692
694
|
it 'should not skip :call as call message' do
|
693
|
-
content
|
695
|
+
content = <<-EOF
|
694
696
|
module DateRange
|
695
697
|
RANGES = lambda {
|
696
698
|
last_month = {
|
@@ -708,7 +710,7 @@ module RailsBestPractices
|
|
708
710
|
runner = Core::Runner.new(prepares: Prepares::ModelPrepare.new,
|
709
711
|
reviews: RemoveUnusedMethodsInModelsReview.new(except_methods: [], ignored_files: /post/))
|
710
712
|
|
711
|
-
content
|
713
|
+
content = <<-EOF
|
712
714
|
class Post < ActiveRecord::Base
|
713
715
|
def find; end
|
714
716
|
private
|
@@ -717,7 +719,7 @@ module RailsBestPractices
|
|
717
719
|
EOF
|
718
720
|
runner.prepare('app/models/post.rb', content)
|
719
721
|
runner.review('app/models/post.rb', content)
|
720
|
-
content
|
722
|
+
content = <<-EOF
|
721
723
|
class PostsController < ApplicationController
|
722
724
|
def get
|
723
725
|
Post.new.find
|