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
@@ -7,7 +9,7 @@ module RailsBestPractices
7
9
 
8
10
  describe 'check_save_return_value' do
9
11
  it 'should warn you if you fail to check save return value' do
10
- content =<<-EOF
12
+ content = <<-EOF
11
13
  def my_method
12
14
  post = Posts.new do |p|
13
15
  p.title = "foo"
@@ -21,7 +23,7 @@ module RailsBestPractices
21
23
  end
22
24
 
23
25
  it 'should allow save return value assigned to var' do
24
- content =<<-EOF
26
+ content = <<-EOF
25
27
  def my_method
26
28
  post = Posts.new do |p|
27
29
  p.title = "foo"
@@ -34,7 +36,7 @@ module RailsBestPractices
34
36
  end
35
37
 
36
38
  it 'should allow save return value used in if' do
37
- content =<<-EOF
39
+ content = <<-EOF
38
40
  def my_method
39
41
  post = Posts.new do |p|
40
42
  p.title = "foo"
@@ -51,7 +53,7 @@ module RailsBestPractices
51
53
  end
52
54
 
53
55
  it 'should allow save return value used in elsif' do
54
- content =<<-EOF
56
+ content = <<-EOF
55
57
  def my_method
56
58
  post = Posts.new do |p|
57
59
  p.title = "foo"
@@ -70,7 +72,7 @@ module RailsBestPractices
70
72
  end
71
73
 
72
74
  it 'should allow save return value used in unless' do
73
- content =<<-EOF
75
+ content = <<-EOF
74
76
  def my_method
75
77
  unless @post.save
76
78
  raise "could not save"
@@ -82,7 +84,7 @@ module RailsBestPractices
82
84
  end
83
85
 
84
86
  it 'should allow save return value used in if_mod' do
85
- content =<<-EOF
87
+ content = <<-EOF
86
88
  def my_method
87
89
  post = Posts.new do |p|
88
90
  p.title = "foo"
@@ -95,7 +97,7 @@ module RailsBestPractices
95
97
  end
96
98
 
97
99
  it 'should allow save return value used in unless_mod' do
98
- content =<<-EOF
100
+ content = <<-EOF
99
101
  def my_method
100
102
  post = Posts.new do |p|
101
103
  p.title = "foo"
@@ -108,7 +110,7 @@ module RailsBestPractices
108
110
  end
109
111
 
110
112
  it 'should allow save return value used in unless with &&' do
111
- content =<<-EOF
113
+ content = <<-EOF
112
114
  def my_method
113
115
  unless some_method(1) && other_method(2) && @post.save
114
116
  raise "could not save"
@@ -120,7 +122,7 @@ module RailsBestPractices
120
122
  end
121
123
 
122
124
  it 'should allow save!' do
123
- content =<<-EOF
125
+ content = <<-EOF
124
126
  def my_method
125
127
  post = Posts.new do |p|
126
128
  p.title = "foo"
@@ -133,7 +135,7 @@ module RailsBestPractices
133
135
  end
134
136
 
135
137
  it 'should warn you if you fail to check update_attributes return value' do
136
- content =<<-EOF
138
+ content = <<-EOF
137
139
  def my_method
138
140
  @post.update_attributes params
139
141
  end
@@ -144,7 +146,7 @@ module RailsBestPractices
144
146
  end
145
147
 
146
148
  it 'should allow update_attributes if return value is checked' do
147
- content =<<-EOF
149
+ content = <<-EOF
148
150
  def my_method
149
151
  @post.update_attributes(params) or raise "failed to save"
150
152
  end
@@ -156,7 +158,7 @@ module RailsBestPractices
156
158
  it 'is not clever enough to allow update_attributes if value is returned from method' do
157
159
  # This review is not clever enough to do a full liveness analysis
158
160
  # of whether the returned value is used in all cases.
159
- content =<<-EOF
161
+ content = <<-EOF
160
162
  class PostsController
161
163
  def update
162
164
  @post = Post.find params(:id)
@@ -178,12 +180,12 @@ module RailsBestPractices
178
180
  end
179
181
 
180
182
  it 'should warn you if you use create which is always unsafe' do
181
- content =<<-EOF
183
+ content = <<-EOF
182
184
  class Post < ActiveRecord::Base
183
185
  end
184
186
  EOF
185
187
  runner.prepare('app/models/post.rb', content)
186
- content =<<-EOF
188
+ content = <<-EOF
187
189
  def my_method
188
190
  if post = Post.create(params)
189
191
  # post may or may not be saved here!
@@ -197,14 +199,14 @@ module RailsBestPractices
197
199
  end
198
200
 
199
201
  it 'should warn you if you use create with a block which is always unsafe' do
200
- content =<<-EOF
202
+ content = <<-EOF
201
203
  module Blog
202
204
  class Post < ActiveRecord::Base
203
205
  end
204
206
  end
205
207
  EOF
206
208
  runner.prepare('app/models/blog/post.rb', content)
207
- content =<<-EOF
209
+ content = <<-EOF
208
210
  module Blog
209
211
  class PostsHelper
210
212
  def my_method
@@ -225,7 +227,7 @@ module RailsBestPractices
225
227
  end
226
228
 
227
229
  it 'allows create called on non-model classes' do
228
- content =<<-EOF
230
+ content = <<-EOF
229
231
  def my_method
230
232
  pk12 = OpenSSL::PKCS12.create(
231
233
  "", # password
@@ -241,7 +243,7 @@ module RailsBestPractices
241
243
 
242
244
  it 'should not check ignored files' do
243
245
  runner = Core::Runner.new(reviews: CheckSaveReturnValueReview.new(ignored_files: /helpers/))
244
- content =<<-EOF
246
+ content = <<-EOF
245
247
  def my_method
246
248
  post = Posts.new do |p|
247
249
  p.title = "foo"
@@ -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
@@ -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: HashSyntaxReview.new) }
7
9
 
8
10
  it 'should find 1.8 Hash with symbol' do
9
- content =<<-EOF
11
+ content = <<-EOF
10
12
  class User < ActiveRecord::Base
11
13
  CONST = { :foo => :bar }
12
14
  end
@@ -17,7 +19,7 @@ module RailsBestPractices
17
19
  end
18
20
 
19
21
  it 'should not find 1.8 Hash with string' do
20
- content =<<-EOF
22
+ content = <<-EOF
21
23
  class User < ActiveRecord::Base
22
24
  CONST = { "foo" => "bar" }
23
25
  end
@@ -27,7 +29,7 @@ module RailsBestPractices
27
29
  end
28
30
 
29
31
  it 'should not alert on 1.9 Syntax' do
30
- content =<<-EOF
32
+ content = <<-EOF
31
33
  class User < ActiveRecord::Base
32
34
  CONST = { foo: :bar }
33
35
  end
@@ -37,7 +39,7 @@ module RailsBestPractices
37
39
  end
38
40
 
39
41
  it 'should ignore haml_out' do
40
- content =<<-EOF
42
+ content = <<-EOF
41
43
  %div{ class: "foo1" }
42
44
  .div{ class: "foo2" }
43
45
  #div{ class: "foo3" }
@@ -47,7 +49,7 @@ module RailsBestPractices
47
49
  end
48
50
 
49
51
  it 'should not consider hash with array key' do
50
- content =<<-EOF
52
+ content = <<-EOF
51
53
  transition [:unverified, :verified] => :deleted
52
54
  EOF
53
55
  runner.review('app/models/post.rb', content)
@@ -55,7 +57,7 @@ module RailsBestPractices
55
57
  end
56
58
 
57
59
  it 'should not consider hash with charaters not valid for symbol' do
58
- content =<<-EOF
60
+ content = <<-EOF
59
61
  receiver.stub(:` => 'Error')
60
62
  EOF
61
63
  runner.review('app/models/post.rb', content)
@@ -64,7 +66,7 @@ module RailsBestPractices
64
66
 
65
67
  it 'should not check ignored files' do
66
68
  runner = Core::Runner.new(reviews: HashSyntaxReview.new(ignored_files: /user/))
67
- content =<<-EOF
69
+ content = <<-EOF
68
70
  class User < ActiveRecord::Base
69
71
  CONST = { :foo => :bar }
70
72
  end
@@ -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
@@ -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
@@ -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
@@ -6,7 +8,7 @@ module RailsBestPractices
6
8
  let(:runner) { Core::Runner.new(reviews: MoveCodeIntoModelReview.new) }
7
9
 
8
10
  it 'should move code into model' do
9
- content =<<-EOF
11
+ content = <<-EOF
10
12
  <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
11
13
  <%= link_to 'Edit this post', edit_post_url(@post) %>
12
14
  <% end %>
@@ -17,7 +19,7 @@ module RailsBestPractices
17
19
  end
18
20
 
19
21
  it 'should move code into model with haml' do
20
- content =<<-EOF
22
+ content = <<-EOF
21
23
  - if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
22
24
  = link_to 'Edit this post', edit_post_url(@post)
23
25
  EOF
@@ -27,7 +29,7 @@ module RailsBestPractices
27
29
  end
28
30
 
29
31
  it 'should move code into model with slim' do
30
- content =<<-EOF
32
+ content = <<-EOF
31
33
  - if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
32
34
  = link_to 'Edit this post', edit_post_url(@post)
33
35
  EOF
@@ -37,7 +39,7 @@ module RailsBestPractices
37
39
  end
38
40
 
39
41
  it 'should move code into model with if in one line' do
40
- content =<<-EOF
42
+ content = <<-EOF
41
43
  <%= link_to 'Edit this post', edit_post_url(@post) if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
42
44
  EOF
43
45
  runner.review('app/views/posts/show.html.erb', content)
@@ -46,7 +48,7 @@ module RailsBestPractices
46
48
  end
47
49
 
48
50
  it "should move code into model with '? :'" do
49
- content =<<-EOF
51
+ content = <<-EOF
50
52
  <%= current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) ? link_to('Edit this post', edit_post_url(@post)) : '' %>
51
53
  EOF
52
54
  runner.review('app/views/posts/show.html.erb', content)
@@ -55,7 +57,7 @@ module RailsBestPractices
55
57
  end
56
58
 
57
59
  it 'should move code into model only review for current if conditional statement' do
58
- content =<<-EOF
60
+ content = <<-EOF
59
61
  <% if @post.title %>
60
62
  <% if @post.user %>
61
63
  <% if @post.description %>
@@ -68,7 +70,7 @@ module RailsBestPractices
68
70
  end
69
71
 
70
72
  it 'should not move code into model' do
71
- content =<<-EOF
73
+ content = <<-EOF
72
74
  <% if @post.editable_by?(current_user) %>
73
75
  <%= link_to 'Edit this post', edit_post_url(@post) %>
74
76
  <% end %>
@@ -78,7 +80,7 @@ module RailsBestPractices
78
80
  end
79
81
 
80
82
  it 'should not move code into model for multiple calls on same variable node' do
81
- content =<<-EOF
83
+ content = <<-EOF
82
84
  <% if !job.company.blank? && job.company.title? %>
83
85
  <% end %>
84
86
  EOF
@@ -88,7 +90,7 @@ module RailsBestPractices
88
90
 
89
91
  it 'should not check ignored files' do
90
92
  runner = Core::Runner.new(reviews: MoveCodeIntoModelReview.new(ignored_files: /app\/views\/post/))
91
- content =<<-EOF
93
+ content = <<-EOF
92
94
  <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
93
95
  <%= link_to 'Edit this post', edit_post_url(@post) %>
94
96
  <% end %>
@@ -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
@@ -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
 
8
10
  describe 'not_rescue_exception' do
9
11
  it 'should not rescue exception in method rescue with named var' do
10
- content =<<-EOF
12
+ content = <<-EOF
11
13
  def my_method
12
14
  do_something
13
15
  rescue Exception => e
@@ -20,7 +22,7 @@ module RailsBestPractices
20
22
  end
21
23
 
22
24
  it 'should not rescue exception in method rescue without named var' do
23
- content =<<-EOF
25
+ content = <<-EOF
24
26
  def my_method
25
27
  do_something
26
28
  rescue Exception
@@ -33,7 +35,7 @@ module RailsBestPractices
33
35
  end
34
36
 
35
37
  it 'should not rescue exception in block rescue with named var' do
36
- content =<<-EOF
38
+ content = <<-EOF
37
39
  def my_method
38
40
  begin
39
41
  do_something
@@ -48,7 +50,7 @@ module RailsBestPractices
48
50
  end
49
51
 
50
52
  it 'should not rescue exception in block rescue without named var' do
51
- content =<<-EOF
53
+ content = <<-EOF
52
54
  def my_method
53
55
  begin
54
56
  do_something
@@ -63,7 +65,7 @@ module RailsBestPractices
63
65
  end
64
66
 
65
67
  it 'should allow rescue implicit StandardError in block rescue without named var' do
66
- content =<<-EOF
68
+ content = <<-EOF
67
69
  def my_method
68
70
  begin
69
71
  do_something
@@ -77,7 +79,7 @@ module RailsBestPractices
77
79
  end
78
80
 
79
81
  it 'should allow rescue explicit StandardError in block rescue without named var' do
80
- content =<<-EOF
82
+ content = <<-EOF
81
83
  def my_method
82
84
  begin
83
85
  do_something
@@ -92,7 +94,7 @@ module RailsBestPractices
92
94
 
93
95
  it 'should not check ignored files' do
94
96
  runner = Core::Runner.new(reviews: NotRescueExceptionReview.new(ignored_files: /posts_helper/))
95
- content =<<-EOF
97
+ content = <<-EOF
96
98
  def my_method
97
99
  do_something
98
100
  rescue Exception => e
@@ -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
 
8
10
  describe 'time_ago_in_words' do
9
11
  it 'should not use in views' do
10
- content =<<-EOF
12
+ content = <<-EOF
11
13
  <%= time_ago_in_words(post.created_at) %>
12
14
  EOF
13
15
  runner.review('app/views/posts/show.html.erb', content)
@@ -16,7 +18,7 @@ module RailsBestPractices
16
18
  end
17
19
 
18
20
  it 'should not use in helpers' do
19
- content =<<-EOF
21
+ content = <<-EOF
20
22
  def timeago
21
23
  content_tag(:p, time_ago_in_words(post.created_at))
22
24
  end
@@ -29,7 +31,7 @@ module RailsBestPractices
29
31
 
30
32
  describe 'distance_of_time_in_words_to_now' do
31
33
  it 'should not use in views' do
32
- content =<<-EOF
34
+ content = <<-EOF
33
35
  <%= distance_of_time_in_words_to_now(post.created_at) %>
34
36
  EOF
35
37
  runner.review('app/views/posts/show.html.erb', content)
@@ -38,7 +40,7 @@ module RailsBestPractices
38
40
  end
39
41
 
40
42
  it 'should not use in helpers' do
41
- content =<<-EOF
43
+ content = <<-EOF
42
44
  def timeago
43
45
  content_tag(:p, distance_of_time_in_words_to_now(post.created_at))
44
46
  end
@@ -51,7 +53,7 @@ module RailsBestPractices
51
53
 
52
54
  it 'should not check ignored files' do
53
55
  runner = Core::Runner.new(reviews: NotUseTimeAgoInWordsReview.new(ignored_files: /posts_helper/))
54
- content =<<-EOF
56
+ content = <<-EOF
55
57
  def timeago
56
58
  content_tag(:p, time_ago_in_words(post.created_at))
57
59
  end