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
|
@@ -7,7 +9,7 @@ module RailsBestPractices
|
|
7
9
|
|
8
10
|
describe 'resources' do
|
9
11
|
before :each do
|
10
|
-
content
|
12
|
+
content = <<-EOF
|
11
13
|
class PostsController < ApplicationController
|
12
14
|
def show; end
|
13
15
|
def new; end
|
@@ -21,7 +23,7 @@ module RailsBestPractices
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'should restrict auto-generated routes' do
|
24
|
-
content
|
26
|
+
content = <<-EOF
|
25
27
|
RailsBestPracticesCom::Application.routes.draw do
|
26
28
|
resources :posts
|
27
29
|
end
|
@@ -32,7 +34,7 @@ module RailsBestPractices
|
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'should not restrict auto-generated routes with only' do
|
35
|
-
content
|
37
|
+
content = <<-EOF
|
36
38
|
RailsBestPracticesCom::Application.routes.draw do
|
37
39
|
resources :posts, only: %w(show new create edit update destroy)
|
38
40
|
end
|
@@ -42,7 +44,7 @@ module RailsBestPractices
|
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'should not restrict auto-generated routes with except' do
|
45
|
-
content
|
47
|
+
content = <<-EOF
|
46
48
|
RailsBestPracticesCom::Application.routes.draw do
|
47
49
|
resources :posts, except: :index
|
48
50
|
end
|
@@ -53,7 +55,7 @@ module RailsBestPractices
|
|
53
55
|
|
54
56
|
describe 'specify a controller' do
|
55
57
|
it 'should restrict auto-generated routes' do
|
56
|
-
content
|
58
|
+
content = <<-EOF
|
57
59
|
RailsBestPracticesCom::Application.routes.draw do
|
58
60
|
resources :articles, controller: "posts"
|
59
61
|
end
|
@@ -66,7 +68,7 @@ module RailsBestPractices
|
|
66
68
|
|
67
69
|
describe 'namespace' do
|
68
70
|
before do
|
69
|
-
content
|
71
|
+
content = <<-EOF
|
70
72
|
class Admin::CommentsController < ApplicationController
|
71
73
|
def show; end
|
72
74
|
def new; end
|
@@ -80,7 +82,7 @@ module RailsBestPractices
|
|
80
82
|
end
|
81
83
|
|
82
84
|
it 'should restrict auto-generated routes' do
|
83
|
-
content
|
85
|
+
content = <<-EOF
|
84
86
|
RailsBestPracticesCom::Application.routes.draw do
|
85
87
|
namespace :admin do
|
86
88
|
resources :comments
|
@@ -93,7 +95,7 @@ module RailsBestPractices
|
|
93
95
|
end
|
94
96
|
|
95
97
|
it 'should restrict auto-generated routes with scope :module' do
|
96
|
-
content
|
98
|
+
content = <<-EOF
|
97
99
|
RailsBestPracticesCom::Application.routes.draw do
|
98
100
|
scope module: :admin do
|
99
101
|
resources :comments
|
@@ -106,7 +108,7 @@ module RailsBestPractices
|
|
106
108
|
end
|
107
109
|
|
108
110
|
it 'should restrict auto-generated routes with resources :module' do
|
109
|
-
content
|
111
|
+
content = <<-EOF
|
110
112
|
RailsBestPracticesCom::Application.routes.draw do
|
111
113
|
resources :comments, module: :admin
|
112
114
|
end
|
@@ -119,7 +121,7 @@ module RailsBestPractices
|
|
119
121
|
|
120
122
|
describe 'nested routes' do
|
121
123
|
before :each do
|
122
|
-
content
|
124
|
+
content = <<-EOF
|
123
125
|
class CommentsController < ApplicationController
|
124
126
|
def index; end
|
125
127
|
def show; end
|
@@ -134,7 +136,7 @@ module RailsBestPractices
|
|
134
136
|
end
|
135
137
|
|
136
138
|
it 'should restrict auto-generated routes' do
|
137
|
-
content
|
139
|
+
content = <<-EOF
|
138
140
|
RailsBestPracticesCom::Application.routes.draw do
|
139
141
|
resources :posts do
|
140
142
|
resources :comments
|
@@ -147,7 +149,7 @@ module RailsBestPractices
|
|
147
149
|
end
|
148
150
|
|
149
151
|
it 'should not restrict auto-generated routes with only' do
|
150
|
-
content
|
152
|
+
content = <<-EOF
|
151
153
|
RailsBestPracticesCom::Application.routes.draw do
|
152
154
|
resources :posts, only: %w(show new create edit update destroy) do
|
153
155
|
resources :comments
|
@@ -159,7 +161,7 @@ module RailsBestPractices
|
|
159
161
|
end
|
160
162
|
|
161
163
|
it 'should not restrict auto-generated routes with except' do
|
162
|
-
content
|
164
|
+
content = <<-EOF
|
163
165
|
RailsBestPracticesCom::Application.routes.draw do
|
164
166
|
resources :posts, except: :index do
|
165
167
|
resources :comments
|
@@ -174,7 +176,7 @@ module RailsBestPractices
|
|
174
176
|
|
175
177
|
describe 'resource' do
|
176
178
|
before :each do
|
177
|
-
content
|
179
|
+
content = <<-EOF
|
178
180
|
class AccountsController < ApplicationController
|
179
181
|
def show; end
|
180
182
|
def new; end
|
@@ -187,7 +189,7 @@ module RailsBestPractices
|
|
187
189
|
end
|
188
190
|
|
189
191
|
it 'should restrict auto-generated routes' do
|
190
|
-
content
|
192
|
+
content = <<-EOF
|
191
193
|
ActionController::Routing::Routes.draw do |map|
|
192
194
|
map.resource :account
|
193
195
|
end
|
@@ -198,7 +200,7 @@ module RailsBestPractices
|
|
198
200
|
end
|
199
201
|
|
200
202
|
it 'should not restrict auto-generated routes with only' do
|
201
|
-
content
|
203
|
+
content = <<-EOF
|
202
204
|
ActionController::Routing::Routes.draw do |map|
|
203
205
|
map.resource :account, only: %w(show new create edit update)
|
204
206
|
end
|
@@ -208,7 +210,7 @@ module RailsBestPractices
|
|
208
210
|
end
|
209
211
|
|
210
212
|
it 'should not restrict auto-generated routes with except' do
|
211
|
-
content
|
213
|
+
content = <<-EOF
|
212
214
|
ActionController::Routing::Routes.draw do |map|
|
213
215
|
map.resource :account, except: :destroy
|
214
216
|
end
|
@@ -221,7 +223,7 @@ module RailsBestPractices
|
|
221
223
|
runner = Core::Runner.new(prepares: Prepares::ControllerPrepare.new,
|
222
224
|
reviews: RestrictAutoGeneratedRoutesReview.new(ignored_files: /config\/routes\.rb/))
|
223
225
|
|
224
|
-
content
|
226
|
+
content = <<-EOF
|
225
227
|
ActionController::Routing::Routes.draw do |map|
|
226
228
|
map.resource :account
|
227
229
|
end
|
@@ -235,7 +237,7 @@ module RailsBestPractices
|
|
235
237
|
let(:runner) { Core::Runner.new(prepares: [Prepares::ConfigPrepare.new, Prepares::ControllerPrepare.new], reviews: RestrictAutoGeneratedRoutesReview.new) }
|
236
238
|
|
237
239
|
before do
|
238
|
-
content
|
240
|
+
content = <<-EOF
|
239
241
|
module RailsBestPracticesCom
|
240
242
|
class Application < Rails::Application
|
241
243
|
config.api_only = true
|
@@ -243,7 +245,7 @@ module RailsBestPractices
|
|
243
245
|
end
|
244
246
|
EOF
|
245
247
|
runner.prepare('config/application.rb', content)
|
246
|
-
content
|
248
|
+
content = <<-EOF
|
247
249
|
class PostsController < ApplicationController
|
248
250
|
def show; end
|
249
251
|
def create; end
|
@@ -255,7 +257,7 @@ module RailsBestPractices
|
|
255
257
|
end
|
256
258
|
|
257
259
|
it 'should restrict auto-generated routes' do
|
258
|
-
content
|
260
|
+
content = <<-EOF
|
259
261
|
RailsBestPracticesCom::Application.routes.draw do
|
260
262
|
resources :posts
|
261
263
|
end
|
@@ -266,7 +268,7 @@ module RailsBestPractices
|
|
266
268
|
end
|
267
269
|
|
268
270
|
it 'should not restrict auto-generated routes with only' do
|
269
|
-
content
|
271
|
+
content = <<-EOF
|
270
272
|
RailsBestPracticesCom::Application.routes.draw do
|
271
273
|
resources :posts, only: %w(show create update destroy)
|
272
274
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -6,7 +8,7 @@ module RailsBestPractices
|
|
6
8
|
let(:runner) { Core::Runner.new(reviews: SimplifyRenderInControllersReview.new) }
|
7
9
|
|
8
10
|
it 'should simplify render action view' do
|
9
|
-
content
|
11
|
+
content = <<-EOF
|
10
12
|
def edit
|
11
13
|
render action: :edit
|
12
14
|
end
|
@@ -17,7 +19,7 @@ module RailsBestPractices
|
|
17
19
|
end
|
18
20
|
|
19
21
|
it "should simplify render actions's template" do
|
20
|
-
content
|
22
|
+
content = <<-EOF
|
21
23
|
def edit
|
22
24
|
render template: 'books/edit'
|
23
25
|
end
|
@@ -28,7 +30,7 @@ module RailsBestPractices
|
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'should simplify render an arbitrary file' do
|
31
|
-
content
|
33
|
+
content = <<-EOF
|
32
34
|
def edit
|
33
35
|
render file: '/path/to/rails/app/views/books/edit'
|
34
36
|
end
|
@@ -39,7 +41,7 @@ module RailsBestPractices
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'should not simplify render action view' do
|
42
|
-
content
|
44
|
+
content = <<-EOF
|
43
45
|
render :edit
|
44
46
|
EOF
|
45
47
|
runner.review('app/controllers/posts_controller', content)
|
@@ -47,7 +49,7 @@ module RailsBestPractices
|
|
47
49
|
end
|
48
50
|
|
49
51
|
it "should not simplify render actions's template" do
|
50
|
-
content
|
52
|
+
content = <<-EOF
|
51
53
|
def edit
|
52
54
|
render 'books/edit'
|
53
55
|
end
|
@@ -57,7 +59,7 @@ module RailsBestPractices
|
|
57
59
|
end
|
58
60
|
|
59
61
|
it 'should not simplify render an arbitrary file' do
|
60
|
-
content
|
62
|
+
content = <<-EOF
|
61
63
|
def edit
|
62
64
|
render '/path/to/rails/app/views/books/edit'
|
63
65
|
end
|
@@ -68,7 +70,7 @@ module RailsBestPractices
|
|
68
70
|
|
69
71
|
it 'should not check ignored files' do
|
70
72
|
runner = Core::Runner.new(reviews: SimplifyRenderInControllersReview.new(ignored_files: /posts_controller/))
|
71
|
-
content
|
73
|
+
content = <<-EOF
|
72
74
|
def edit
|
73
75
|
render action: :edit
|
74
76
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -6,7 +8,7 @@ module RailsBestPractices
|
|
6
8
|
let(:runner) { Core::Runner.new(reviews: SimplifyRenderInViewsReview.new) }
|
7
9
|
|
8
10
|
it 'should simplify render simple partial' do
|
9
|
-
content
|
11
|
+
content = <<-EOF
|
10
12
|
<%= render partial: 'sidebar' %>
|
11
13
|
EOF
|
12
14
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -15,7 +17,7 @@ module RailsBestPractices
|
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'should simplify render partial with object' do
|
18
|
-
content
|
20
|
+
content = <<-EOF
|
19
21
|
<%= render partial: 'post', object: @post %>
|
20
22
|
EOF
|
21
23
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -24,7 +26,7 @@ module RailsBestPractices
|
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'should simplify render partial with collection' do
|
27
|
-
content
|
29
|
+
content = <<-EOF
|
28
30
|
<%= render partial: 'posts', collection: @posts %>
|
29
31
|
EOF
|
30
32
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -33,7 +35,7 @@ module RailsBestPractices
|
|
33
35
|
end
|
34
36
|
|
35
37
|
it 'should simplify render partial with local variables' do
|
36
|
-
content
|
38
|
+
content = <<-EOF
|
37
39
|
<%= render partial: 'comment', locals: { parent: post } %>
|
38
40
|
EOF
|
39
41
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -42,7 +44,7 @@ module RailsBestPractices
|
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'should not simplify render simple partial' do
|
45
|
-
content
|
47
|
+
content = <<-EOF
|
46
48
|
<%= render 'sidebar' %>
|
47
49
|
<%= render 'shared/sidebar' %>
|
48
50
|
EOF
|
@@ -51,7 +53,7 @@ module RailsBestPractices
|
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'should not simplify render partial with object' do
|
54
|
-
content
|
56
|
+
content = <<-EOF
|
55
57
|
<%= render @post %>
|
56
58
|
EOF
|
57
59
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -59,7 +61,7 @@ module RailsBestPractices
|
|
59
61
|
end
|
60
62
|
|
61
63
|
it 'should not simplify render partial with collection' do
|
62
|
-
content
|
64
|
+
content = <<-EOF
|
63
65
|
<%= render @posts %>
|
64
66
|
EOF
|
65
67
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -67,7 +69,7 @@ module RailsBestPractices
|
|
67
69
|
end
|
68
70
|
|
69
71
|
it 'should not simplify render partial with local variables' do
|
70
|
-
content
|
72
|
+
content = <<-EOF
|
71
73
|
<%= render 'comment', parent: post %>
|
72
74
|
EOF
|
73
75
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -75,7 +77,7 @@ module RailsBestPractices
|
|
75
77
|
end
|
76
78
|
|
77
79
|
it 'should not simplify render partial with complex partial' do
|
78
|
-
content
|
80
|
+
content = <<-EOF
|
79
81
|
<%= render partial: 'shared/post', object: @post %>
|
80
82
|
EOF
|
81
83
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -83,7 +85,7 @@ module RailsBestPractices
|
|
83
85
|
end
|
84
86
|
|
85
87
|
it 'should not simplify render partial with layout option' do
|
86
|
-
content
|
88
|
+
content = <<-EOF
|
87
89
|
<%= render partial: 'post', layout: 'post' %>
|
88
90
|
EOF
|
89
91
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -92,7 +94,7 @@ module RailsBestPractices
|
|
92
94
|
|
93
95
|
it 'should not check ignored files' do
|
94
96
|
runner = Core::Runner.new(reviews: SimplifyRenderInViewsReview.new(ignored_files: /views\/posts\/index/))
|
95
|
-
content
|
97
|
+
content = <<-EOF
|
96
98
|
<%= render partial: 'sidebar' %>
|
97
99
|
EOF
|
98
100
|
runner.review('app/views/posts/index.html.erb', content)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -85,7 +87,7 @@ module RailsBestPractices
|
|
85
87
|
end
|
86
88
|
|
87
89
|
it 'should not use before_filter for protected/private methods' do
|
88
|
-
content
|
90
|
+
content = <<-EOF
|
89
91
|
class PostsController < ApplicationController
|
90
92
|
protected
|
91
93
|
def load_comments
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module RailsBestPractices
|
@@ -6,7 +8,7 @@ module RailsBestPractices
|
|
6
8
|
let(:runner) { Core::Runner.new(prepares: Prepares::MailerPrepare.new, reviews: UseObserverReview.new) }
|
7
9
|
|
8
10
|
before :each do
|
9
|
-
content
|
11
|
+
content = <<-EOF
|
10
12
|
class ProjectMailer < ActionMailer::Base
|
11
13
|
end
|
12
14
|
EOF
|
@@ -14,7 +16,7 @@ module RailsBestPractices
|
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'should use observer' do
|
17
|
-
content
|
19
|
+
content = <<-EOF
|
18
20
|
class Project < ActiveRecord::Base
|
19
21
|
after_create :send_create_notification
|
20
22
|
|
@@ -32,7 +34,7 @@ module RailsBestPractices
|
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'should not use observer without callback' do
|
35
|
-
content
|
37
|
+
content = <<-EOF
|
36
38
|
class Project < ActiveRecord::Base
|
37
39
|
private
|
38
40
|
def send_create_notification
|
@@ -47,7 +49,7 @@ module RailsBestPractices
|
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'should use observer with two after_create' do
|
50
|
-
content
|
52
|
+
content = <<-EOF
|
51
53
|
class Project < ActiveRecord::Base
|
52
54
|
after_create :send_create_notification, :update_author
|
53
55
|
|
@@ -68,7 +70,7 @@ module RailsBestPractices
|
|
68
70
|
end
|
69
71
|
|
70
72
|
it 'should not raise when initiate an object in callback' do
|
71
|
-
content
|
73
|
+
content = <<-EOF
|
72
74
|
class Project < ActiveRecord::Base
|
73
75
|
after_create ProjectMailer.new
|
74
76
|
end
|