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.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Guardfile +1 -1
  4. data/README.md +1 -0
  5. data/Rakefile +2 -2
  6. data/bin/rails_best_practices +2 -1
  7. data/lib/rails_best_practices.rb +2 -1
  8. data/lib/rails_best_practices/analyzer.rb +13 -12
  9. data/lib/rails_best_practices/colorize.rb +2 -0
  10. data/lib/rails_best_practices/command.rb +6 -5
  11. data/lib/rails_best_practices/core.rb +2 -1
  12. data/lib/rails_best_practices/core/check.rb +19 -17
  13. data/lib/rails_best_practices/core/checks_loader.rb +3 -2
  14. data/lib/rails_best_practices/core/configs.rb +2 -1
  15. data/lib/rails_best_practices/core/controllers.rb +4 -1
  16. data/lib/rails_best_practices/core/error.rb +3 -2
  17. data/lib/rails_best_practices/core/gems.rb +4 -3
  18. data/lib/rails_best_practices/core/helpers.rb +4 -1
  19. data/lib/rails_best_practices/core/klasses.rb +3 -2
  20. data/lib/rails_best_practices/core/mailers.rb +2 -1
  21. data/lib/rails_best_practices/core/methods.rb +9 -10
  22. data/lib/rails_best_practices/core/model_associations.rb +6 -5
  23. data/lib/rails_best_practices/core/model_attributes.rb +2 -1
  24. data/lib/rails_best_practices/core/models.rb +2 -1
  25. data/lib/rails_best_practices/core/modules.rb +2 -1
  26. data/lib/rails_best_practices/core/routes.rb +2 -1
  27. data/lib/rails_best_practices/core/runner.rb +7 -6
  28. data/lib/rails_best_practices/core_ext/erubis.rb +4 -5
  29. data/lib/rails_best_practices/lexicals.rb +2 -1
  30. data/lib/rails_best_practices/lexicals/long_line_check.rb +2 -1
  31. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -1
  32. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -1
  33. data/lib/rails_best_practices/prepares.rb +2 -1
  34. data/lib/rails_best_practices/prepares/config_prepare.rb +3 -2
  35. data/lib/rails_best_practices/prepares/controller_prepare.rb +9 -8
  36. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -1
  37. data/lib/rails_best_practices/prepares/helper_prepare.rb +4 -3
  38. data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -1
  39. data/lib/rails_best_practices/prepares/mailer_prepare.rb +3 -2
  40. data/lib/rails_best_practices/prepares/model_prepare.rb +12 -12
  41. data/lib/rails_best_practices/prepares/route_prepare.rb +8 -7
  42. data/lib/rails_best_practices/prepares/schema_prepare.rb +3 -2
  43. data/lib/rails_best_practices/reviews.rb +2 -1
  44. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +7 -4
  45. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +8 -7
  46. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +4 -3
  47. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +5 -4
  48. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -1
  49. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -1
  50. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +2 -1
  51. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +3 -2
  52. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +3 -2
  53. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +3 -2
  54. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -2
  55. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -1
  56. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +3 -2
  57. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +3 -2
  58. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +3 -2
  59. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +5 -4
  60. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -1
  61. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -1
  62. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -1
  63. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -2
  64. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +4 -3
  65. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -1
  66. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -10
  67. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +4 -3
  68. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +6 -5
  69. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
  70. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -1
  71. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +8 -8
  72. data/lib/rails_best_practices/reviews/review.rb +4 -3
  73. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -1
  74. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -2
  75. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +5 -4
  76. data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
  77. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +5 -5
  78. data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -1
  79. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +2 -1
  80. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +4 -3
  81. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +4 -3
  82. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -1
  83. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  84. data/lib/rails_best_practices/version.rb +3 -2
  85. data/rails_best_practices.gemspec +11 -10
  86. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +3 -2
  87. data/spec/rails_best_practices/analyzer_spec.rb +6 -8
  88. data/spec/rails_best_practices/core/check_spec.rb +2 -0
  89. data/spec/rails_best_practices/core/checks_loader_spec.rb +2 -0
  90. data/spec/rails_best_practices/core/configs_spec.rb +2 -0
  91. data/spec/rails_best_practices/core/controllers_spec.rb +2 -0
  92. data/spec/rails_best_practices/core/error_spec.rb +2 -0
  93. data/spec/rails_best_practices/core/except_methods_spec.rb +2 -0
  94. data/spec/rails_best_practices/core/gems_spec.rb +2 -0
  95. data/spec/rails_best_practices/core/helpers_spec.rb +2 -0
  96. data/spec/rails_best_practices/core/klasses_spec.rb +2 -0
  97. data/spec/rails_best_practices/core/mailers_spec.rb +2 -0
  98. data/spec/rails_best_practices/core/methods_spec.rb +6 -4
  99. data/spec/rails_best_practices/core/model_associations_spec.rb +4 -2
  100. data/spec/rails_best_practices/core/model_attributes_spec.rb +2 -0
  101. data/spec/rails_best_practices/core/models_spec.rb +2 -0
  102. data/spec/rails_best_practices/core/modules_spec.rb +2 -0
  103. data/spec/rails_best_practices/core/routes_spec.rb +4 -2
  104. data/spec/rails_best_practices/core/runner_spec.rb +2 -0
  105. data/spec/rails_best_practices/core_ext/erubis_spec.rb +3 -1
  106. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +8 -7
  107. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +8 -6
  108. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +9 -7
  109. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -1
  110. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +23 -21
  111. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -1
  112. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +7 -5
  113. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +4 -2
  114. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +3 -1
  115. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +56 -54
  116. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +39 -37
  117. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +3 -1
  118. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +2 -0
  119. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +7 -5
  120. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +12 -10
  121. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +20 -18
  122. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +2 -0
  123. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +2 -0
  124. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -7
  125. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +2 -0
  126. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +2 -0
  127. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +2 -0
  128. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +2 -0
  129. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +2 -0
  130. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +11 -9
  131. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +2 -0
  132. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +2 -0
  133. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +2 -0
  134. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -7
  135. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +2 -0
  136. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -5
  137. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +2 -0
  138. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +21 -19
  139. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -4
  140. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -31
  141. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +13 -11
  142. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +65 -63
  143. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +2 -0
  144. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +2 -0
  145. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +24 -22
  146. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -7
  147. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -11
  148. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +3 -1
  149. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +2 -0
  150. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +2 -0
  151. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +7 -5
  152. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +2 -0
  153. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +3 -1
  154. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -7
  155. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +2 -0
  156. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +2 -0
  157. data/spec/spec_helper.rb +2 -0
  158. metadata +26 -26
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices
@@ -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
  reviews: ProtectMassAssignmentReview.new) }
8
10
 
9
11
  it 'should protect mass assignment' do
10
- content =<<-EOF
12
+ content = <<-EOF
11
13
  class User < ActiveRecord::Base
12
14
  end
13
15
  EOF
@@ -17,7 +19,7 @@ module RailsBestPractices
17
19
  end
18
20
 
19
21
  it 'should not protect mass assignment if attr_accessible is used with arguments and user set config.active_record.whitelist_attributes' do
20
- content =<<-EOF
22
+ content = <<-EOF
21
23
  module RailsBestPracticesCom
22
24
  class Application < Rails::Application
23
25
  config.active_record.whitelist_attributes = true
@@ -25,7 +27,7 @@ module RailsBestPractices
25
27
  end
26
28
  EOF
27
29
  runner.prepare('config/application.rb', content)
28
- content =<<-EOF
30
+ content = <<-EOF
29
31
  class User < ActiveRecord::Base
30
32
  attr_accessible :email, :password, :password_confirmation
31
33
  end
@@ -35,7 +37,7 @@ module RailsBestPractices
35
37
  end
36
38
 
37
39
  it 'should not protect mass assignment if attr_accessible is used without arguments and user set config.active_record.whitelist_attributes' do
38
- content =<<-EOF
40
+ content = <<-EOF
39
41
  module RailsBestPracticesCom
40
42
  class Application < Rails::Application
41
43
  config.active_record.whitelist_attributes = true
@@ -43,7 +45,7 @@ module RailsBestPractices
43
45
  end
44
46
  EOF
45
47
  runner.prepare('config/application.rb', content)
46
- content =<<-EOF
48
+ content = <<-EOF
47
49
  class User < ActiveRecord::Base
48
50
  attr_accessible
49
51
  end
@@ -53,7 +55,7 @@ module RailsBestPractices
53
55
  end
54
56
 
55
57
  it 'should not protect mass assignment with attr_protected if user set config.active_record.whitelist_attributes' do
56
- content =<<-EOF
58
+ content = <<-EOF
57
59
  module RailsBestPracticesCom
58
60
  class Application < Rails::Application
59
61
  config.active_record.whitelist_attributes = true
@@ -61,7 +63,7 @@ module RailsBestPractices
61
63
  end
62
64
  EOF
63
65
  runner.prepare('config/application.rb', content)
64
- content =<<-EOF
66
+ content = <<-EOF
65
67
  class User < ActiveRecord::Base
66
68
  attr_protected :role
67
69
  end
@@ -71,7 +73,7 @@ module RailsBestPractices
71
73
  end
72
74
 
73
75
  it 'should not protect mass assignment if using devise' do
74
- content =<<-EOF
76
+ content = <<-EOF
75
77
  class User < ActiveRecord::Base
76
78
  devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
77
79
  end
@@ -81,7 +83,7 @@ module RailsBestPractices
81
83
  end
82
84
 
83
85
  it 'should not protect mass assignment if using authlogic with configuration' do
84
- content =<<-EOF
86
+ content = <<-EOF
85
87
  class User < ActiveRecord::Base
86
88
  acts_as_authentic do |c|
87
89
  c.my_config_option = my_value
@@ -93,7 +95,7 @@ module RailsBestPractices
93
95
  end
94
96
 
95
97
  it 'should not protect mass assignment if using authlogic without configuration' do
96
- content =<<-EOF
98
+ content = <<-EOF
97
99
  class User < ActiveRecord::Base
98
100
  acts_as_authentic
99
101
  end
@@ -103,7 +105,7 @@ module RailsBestPractices
103
105
  end
104
106
 
105
107
  it 'should not protect mass assignment if checking non ActiveRecord::Base inherited model' do
106
- content =<<-EOF
108
+ content = <<-EOF
107
109
  class User < Person
108
110
  end
109
111
  EOF
@@ -113,7 +115,7 @@ module RailsBestPractices
113
115
 
114
116
  context 'strong_parameters' do
115
117
  it 'should not protect mass assignment for strong_parameters' do
116
- content =<<-EOF
118
+ content = <<-EOF
117
119
  class User < ActiveRecord::Base
118
120
  include ActiveModel::ForbiddenAttributesProtection
119
121
  end
@@ -123,13 +125,13 @@ module RailsBestPractices
123
125
  end
124
126
 
125
127
  it 'should not protect mass assignment for strong_parameters' do
126
- content =<<-EOF
128
+ content = <<-EOF
127
129
  class AR
128
130
  ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
129
131
  end
130
132
  EOF
131
133
  runner.prepare('config/initializers/ar.rb', content)
132
- content =<<-EOF
134
+ content = <<-EOF
133
135
  class User < ActiveRecord::Base
134
136
  end
135
137
  EOF
@@ -140,14 +142,14 @@ module RailsBestPractices
140
142
 
141
143
  context 'activerecord 4' do
142
144
  it 'should not protect mass assignment for activerecord 4' do
143
- content =<<-EOF
145
+ content = <<-EOF
144
146
  GEM
145
147
  remote: https://rubygems.org
146
148
  specs:
147
149
  activerecord (4.0.0)
148
150
  EOF
149
151
  runner.prepare('Gemfile.lock', content)
150
- content =<<-EOF
152
+ content = <<-EOF
151
153
  class User < ActiveRecord::Base
152
154
  end
153
155
  EOF
@@ -156,14 +158,14 @@ module RailsBestPractices
156
158
  end
157
159
 
158
160
  it 'should protect mass assignment for activerecord 3' do
159
- content =<<-EOF
161
+ content = <<-EOF
160
162
  GEM
161
163
  remote: https://rubygems.org
162
164
  specs:
163
165
  activerecord (3.2.13)
164
166
  EOF
165
167
  runner.prepare('Gemfile.lock', content)
166
- content =<<-EOF
168
+ content = <<-EOF
167
169
  class User < ActiveRecord::Base
168
170
  end
169
171
  EOF
@@ -175,7 +177,7 @@ module RailsBestPractices
175
177
  it 'should not check ignored files' do
176
178
  runner = Core::Runner.new(prepares: [Prepares::GemfilePrepare.new, Prepares::ConfigPrepare.new, Prepares::InitializerPrepare.new],
177
179
  reviews: ProtectMassAssignmentReview.new(ignored_files: /app\/models\/user\.rb/))
178
- content =<<-EOF
180
+ content = <<-EOF
179
181
  class User < ActiveRecord::Base
180
182
  end
181
183
  EOF
@@ -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: RemoveEmptyHelpersReview.new) }
7
9
 
8
10
  it 'should remove empty helpers' do
9
- content =<<-EOF
11
+ content = <<-EOF
10
12
  module PostsHelper
11
13
  end
12
14
  EOF
@@ -16,7 +18,7 @@ module RailsBestPractices
16
18
  end
17
19
 
18
20
  it 'should not remove empty helpers' do
19
- content =<<-EOF
21
+ content = <<-EOF
20
22
  module PostsHelper
21
23
  def post_link(post)
22
24
  post_path(post)
@@ -28,7 +30,7 @@ module RailsBestPractices
28
30
  end
29
31
 
30
32
  it 'should not remove empty application_helper' do
31
- content =<<-EOF
33
+ content = <<-EOF
32
34
  module ApplicationHelper
33
35
  end
34
36
  EOF
@@ -38,7 +40,7 @@ module RailsBestPractices
38
40
 
39
41
  it 'should not check ignored files' do
40
42
  runner = Core::Runner.new(reviews: RemoveEmptyHelpersReview.new(ignored_files: /posts_helper/))
41
- content =<<-EOF
43
+ content = <<-EOF
42
44
  module PostsHelper
43
45
  end
44
46
  EOF
@@ -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 RemoveUnusedMethodsInControllersReview do
6
8
  let(:runner) { Core::Runner.new(
7
9
  prepares: [Prepares::ControllerPrepare.new, Prepares::RoutePrepare.new],
8
- reviews: RemoveUnusedMethodsInControllersReview.new({'except_methods' => ['ExceptableController#*']})
10
+ reviews: RemoveUnusedMethodsInControllersReview.new('except_methods' => ['ExceptableController#*'])
9
11
  ) }
10
12
 
11
13
  context 'private/protected' do
12
14
  it 'should remove unused methods' do
13
- content =<<-EOF
15
+ content = <<-EOF
14
16
  RailsBestPracticesCom::Application.routes.draw do
15
17
  resources :posts do
16
18
  member do
@@ -21,7 +23,7 @@ module RailsBestPractices
21
23
  end
22
24
  EOF
23
25
  runner.prepare('config/routes.rb', content)
24
- content =<<-EOF
26
+ content = <<-EOF
25
27
  class PostsController < ActiveRecord::Base
26
28
  def show; end
27
29
  def extra_update; end
@@ -41,13 +43,13 @@ module RailsBestPractices
41
43
  end
42
44
 
43
45
  it 'should not remove unused methods for before_filter' do
44
- content =<<-EOF
46
+ content = <<-EOF
45
47
  RailsBestPracticesCom::Application.routes.draw do
46
48
  resources :posts
47
49
  end
48
50
  EOF
49
51
  runner.prepare('config/routes.rb', content)
50
- content =<<-EOF
52
+ content = <<-EOF
51
53
  class PostsController < ActiveRecord::Base
52
54
  before_filter :load_post, :load_user
53
55
  def show; end
@@ -63,13 +65,13 @@ module RailsBestPractices
63
65
  end
64
66
 
65
67
  it 'should not remove unused methods for around_filter' do
66
- content =<<-EOF
68
+ content = <<-EOF
67
69
  RailsBestPracticesCom::Application.routes.draw do
68
70
  resources :posts
69
71
  end
70
72
  EOF
71
73
  runner.prepare('config/routes.rb', content)
72
- content =<<-EOF
74
+ content = <<-EOF
73
75
  class PostsController < ActiveRecord::Base
74
76
  around_filter :set_timestamp
75
77
  protected
@@ -88,13 +90,13 @@ module RailsBestPractices
88
90
  end
89
91
 
90
92
  it 'should not remove unused methods for layout' do
91
- content =<<-EOF
93
+ content = <<-EOF
92
94
  RailsBestPracticesCom::Application.routes.draw do
93
95
  resources :posts
94
96
  end
95
97
  EOF
96
98
  runner.prepare('config/routes.rb', content)
97
- content =<<-EOF
99
+ content = <<-EOF
98
100
  class PostsController < ActiveRecord::Base
99
101
  layout :choose_layout
100
102
  private
@@ -110,13 +112,13 @@ module RailsBestPractices
110
112
  end
111
113
 
112
114
  it 'should not remove inherited_resources methods' do
113
- content =<<-EOF
115
+ content = <<-EOF
114
116
  RailsBestPracticesCom::Application.routes.draw do
115
117
  resources :posts
116
118
  end
117
119
  EOF
118
120
  runner.prepare('config/routes.rb', content)
119
- content =<<-EOF
121
+ content = <<-EOF
120
122
  class PostsController < InheritedResources::Base
121
123
  def show; end
122
124
  protected
@@ -134,13 +136,13 @@ module RailsBestPractices
134
136
 
135
137
  context 'public' do
136
138
  it 'should remove unused methods' do
137
- content =<<-EOF
139
+ content = <<-EOF
138
140
  RailsBestPracticesCom::Application.routes.draw do
139
141
  resources :posts
140
142
  end
141
143
  EOF
142
144
  runner.prepare('config/routes.rb', content)
143
- content =<<-EOF
145
+ content = <<-EOF
144
146
  class PostsController < ApplicationController
145
147
  def show; end
146
148
  def list; end
@@ -154,7 +156,7 @@ module RailsBestPractices
154
156
  end
155
157
 
156
158
  it 'should not remove inline routes' do
157
- content =<<-EOF
159
+ content = <<-EOF
158
160
  RailsBestPracticesCom::Application.routes.draw do
159
161
  resources :posts, only: :none do
160
162
  get :display, :list, on: :member
@@ -162,7 +164,7 @@ module RailsBestPractices
162
164
  end
163
165
  EOF
164
166
  runner.prepare('config/routes.rb', content)
165
- content =<<-EOF
167
+ content = <<-EOF
166
168
  class PostsController < ApplicationController
167
169
  def display; end
168
170
  def list; end
@@ -175,13 +177,13 @@ module RailsBestPractices
175
177
  end
176
178
 
177
179
  it 'should not remove unused methods if all actions are used in route' do
178
- content =<<-EOF
180
+ content = <<-EOF
179
181
  ActionController::Routing::Routes.draw do |map|
180
182
  map.connect 'internal/:action/*whatever', controller: "internal"
181
183
  end
182
184
  EOF
183
185
  runner.prepare('config/routes.rb', content)
184
- content =<<-EOF
186
+ content = <<-EOF
185
187
  class InternalController < ApplicationController
186
188
  def list; end
187
189
  def delete; end
@@ -195,7 +197,7 @@ module RailsBestPractices
195
197
  end
196
198
 
197
199
  it 'should not remove unused methods if they are except_methods' do
198
- content =<<-EOF
200
+ content = <<-EOF
199
201
  class ExceptableController < ApplicationController
200
202
  def list; end
201
203
  end
@@ -209,19 +211,19 @@ module RailsBestPractices
209
211
 
210
212
  context 'assignment' do
211
213
  it 'should not remove unused methods if call in base class' do
212
- content =<<-EOF
214
+ content = <<-EOF
213
215
  RailsBestPracticesCom::Application.routes.draw do
214
216
  resources :user, only: :show do; end
215
217
  end
216
218
  EOF
217
219
  runner.prepare('config/routes.rb', content)
218
- application_content =<<-EOF
220
+ application_content = <<-EOF
219
221
  class ApplicationController
220
222
  def current_user=(user); end
221
223
  end
222
224
  EOF
223
225
  runner.prepare('app/controllers/application_controller.rb', application_content)
224
- users_content =<<-EOF
226
+ users_content = <<-EOF
225
227
  class UsersController < ApplicationController
226
228
  def show
227
229
  current_user = @user
@@ -340,7 +342,7 @@ module RailsBestPractices
340
342
 
341
343
  context 'cells' do
342
344
  it 'should remove unused methods' do
343
- content =<<-EOF
345
+ content = <<-EOF
344
346
  class PostsCell < Cell::Rails
345
347
  def list; end
346
348
  end
@@ -353,7 +355,7 @@ module RailsBestPractices
353
355
  end
354
356
 
355
357
  it 'should not remove unused methods if render_cell' do
356
- content =<<-EOF
358
+ content = <<-EOF
357
359
  class PostsCell < Cell::Rails
358
360
  def list; end
359
361
  def display; end
@@ -361,7 +363,7 @@ module RailsBestPractices
361
363
  EOF
362
364
  runner.prepare('app/cells/posts_cell.rb', content)
363
365
  runner.review('app/cells/posts_cell.rb', content)
364
- content =<<-EOF
366
+ content = <<-EOF
365
367
  <%= render_cell :posts, :list %>
366
368
  <%= render_cell(:posts, :display) %>
367
369
  EOF
@@ -371,7 +373,7 @@ module RailsBestPractices
371
373
  end
372
374
 
373
375
  it 'should not remove unused methods if render with state' do
374
- content =<<-EOF
376
+ content = <<-EOF
375
377
  class PostsCell < Cell::Rails
376
378
  def list
377
379
  render state: :show
@@ -384,7 +386,7 @@ module RailsBestPractices
384
386
  EOF
385
387
  runner.prepare('app/cells/posts_cell.rb', content)
386
388
  runner.review('app/cells/posts_cell.rb', content)
387
- content =<<-EOF
389
+ content = <<-EOF
388
390
  <%= render_cell :posts, :list %>
389
391
  EOF
390
392
  runner.review('app/views/posts/index.html.erb', content)
@@ -394,14 +396,14 @@ module RailsBestPractices
394
396
  end
395
397
 
396
398
  it 'should not remove unused methods' do
397
- route_content =<<-EOF
399
+ route_content = <<-EOF
398
400
  RailsBestPracticesCom::Application.routes.draw do
399
401
  namespace :admin do
400
402
  resources :users, only: :index
401
403
  end
402
404
  end
403
405
  EOF
404
- app_controller_content =<<-EOF
406
+ app_controller_content = <<-EOF
405
407
  module Admin
406
408
  class AppController < ApplicationController
407
409
  def index
@@ -410,7 +412,7 @@ module RailsBestPractices
410
412
  end
411
413
  end
412
414
  EOF
413
- users_controller_content =<<-EOF
415
+ users_controller_content = <<-EOF
414
416
  module Admin
415
417
  class UsersController < AppController
416
418
  private
@@ -433,7 +435,7 @@ module RailsBestPractices
433
435
  it 'should not check ignored files' do
434
436
  runner = Core::Runner.new(prepares: [Prepares::ControllerPrepare.new, Prepares::RoutePrepare.new],
435
437
  reviews: RemoveUnusedMethodsInControllersReview.new(ignored_files: /posts_controller/, except_methods: []))
436
- content =<<-EOF
438
+ content = <<-EOF
437
439
  RailsBestPracticesCom::Application.routes.draw do
438
440
  resources :posts do
439
441
  member do
@@ -444,7 +446,7 @@ module RailsBestPractices
444
446
  end
445
447
  EOF
446
448
  runner.prepare('config/routes.rb', content)
447
- content =<<-EOF
449
+ content = <<-EOF
448
450
  class PostsController < ActiveRecord::Base
449
451
  def show; end
450
452
  def extra_update; end