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,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'rails_best_practices/reviews/review'
3
4
 
4
5
  module RailsBestPractices
@@ -8,4 +9,4 @@ module RailsBestPractices
8
9
  end
9
10
  end
10
11
  end
11
- end
12
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'tmpdir'
3
5
 
@@ -83,7 +85,6 @@ module RailsBestPractices
83
85
  expect(subject).to have_received(:output_xml_errors)
84
86
  end
85
87
  end
86
-
87
88
  end
88
89
 
89
90
  describe 'output_terminal_errors' do
@@ -94,7 +95,7 @@ module RailsBestPractices
94
95
  check1.add_error 'law of demeter', 'app/models/user.rb', 10
95
96
  check2.add_error 'use query attribute', 'app/models/post.rb', 100
96
97
  subject.runner = runner
97
- subject.instance_variable_set('@options', {'without-color' => false})
98
+ subject.instance_variable_set('@options', 'without-color' => false)
98
99
 
99
100
  $origin_stdout = $stdout
100
101
  $stdout = StringIO.new
@@ -113,10 +114,10 @@ module RailsBestPractices
113
114
  let(:output_file) { 'rails_best_practices_output.json' }
114
115
 
115
116
  subject do
116
- described_class.new('.', {
117
+ described_class.new('.',
117
118
  'format' => 'json',
118
119
  'output-file' => output_file
119
- })
120
+ )
120
121
  end
121
122
 
122
123
  let(:check1) { Reviews::LawOfDemeterReview.new }
@@ -132,7 +133,7 @@ module RailsBestPractices
132
133
  end
133
134
 
134
135
  after do
135
- File.delete(output_file) if File.exists?(output_file)
136
+ File.delete(output_file) if File.exist?(output_file)
136
137
  end
137
138
 
138
139
  it 'saves output as json into output file' do
@@ -141,7 +142,6 @@ module RailsBestPractices
141
142
  end
142
143
 
143
144
  describe 'parse_files' do
144
-
145
145
  it 'should not filter out all files when the path contains "vendor"' do
146
146
  Dir.mktmpdir { |random_dir|
147
147
  Dir.mkdir(File.join(random_dir, 'vendor'))
@@ -191,8 +191,6 @@ module RailsBestPractices
191
191
  expect(analyzer.parse_files).to be_include File.join(random_dir, 'tmp', 'my_project', 'my_file.rb')
192
192
  }
193
193
  end
194
-
195
194
  end
196
-
197
195
  end
198
196
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -13,8 +15,8 @@ module RailsBestPractices::Core
13
15
  end
14
16
 
15
17
  it 'should get_methods' do
16
- expect(methods.get_methods('Post').map(&:method_name)).to eq(['create', 'destroy', 'save_or_update', 'find_by_sql'])
17
- expect(methods.get_methods('Post', 'public').map(&:method_name)).to eq(['create', 'destroy'])
18
+ expect(methods.get_methods('Post').map(&:method_name)).to eq(%w[create destroy save_or_update find_by_sql])
19
+ expect(methods.get_methods('Post', 'public').map(&:method_name)).to eq(%w[create destroy])
18
20
  expect(methods.get_methods('Post', 'protected').map(&:method_name)).to eq(['save_or_update'])
19
21
  expect(methods.get_methods('Post', 'private').map(&:method_name)).to eq(['find_by_sql'])
20
22
  expect(methods.get_methods('Comment').map(&:method_name)).to eq(['create'])
@@ -37,10 +39,10 @@ module RailsBestPractices::Core
37
39
 
38
40
  it 'should get_all_unused_methods' do
39
41
  methods.get_method('Comment', 'create').mark_used
40
- expect(methods.get_all_unused_methods('public').map(&:method_name)).to eq(['create', 'destroy'])
42
+ expect(methods.get_all_unused_methods('public').map(&:method_name)).to eq(%w[create destroy])
41
43
  expect(methods.get_all_unused_methods('protected').map(&:method_name)).to eq(['save_or_update'])
42
44
  expect(methods.get_all_unused_methods('private').map(&:method_name)).to eq(['find_by_sql'])
43
- expect(methods.get_all_unused_methods.map(&:method_name)).to eq(['create', 'destroy', 'save_or_update', 'find_by_sql'])
45
+ expect(methods.get_all_unused_methods.map(&:method_name)).to eq(%w[create destroy save_or_update find_by_sql])
44
46
  end
45
47
  end
46
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -10,8 +12,8 @@ module RailsBestPractices::Core
10
12
  end
11
13
 
12
14
  it 'should get model associations' do
13
- expect(model_associations.get_association('Project', 'project_manager')).to eq({'meta' => 'belongs_to', 'class_name' => 'ProjectManager'})
14
- expect(model_associations.get_association('Project', 'people')).to eq({'meta' => 'has_many', 'class_name' => 'Person'})
15
+ expect(model_associations.get_association('Project', 'project_manager')).to eq('meta' => 'belongs_to', 'class_name' => 'ProjectManager')
16
+ expect(model_associations.get_association('Project', 'people')).to eq('meta' => 'has_many', 'class_name' => 'Person')
15
17
  expect(model_associations.get_association('Project', 'unknown')).to be_nil
16
18
  end
17
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -5,13 +7,13 @@ module RailsBestPractices::Core
5
7
  let(:routes) { Routes.new }
6
8
 
7
9
  it 'should add route' do
8
- routes.add_route(['admin', 'test'], 'posts', 'new')
10
+ routes.add_route(%w[admin test], 'posts', 'new')
9
11
  expect(routes.map(&:to_s)).to eq(['Admin::Test::PostsController#new'])
10
12
  end
11
13
 
12
14
  context 'route' do
13
15
  it 'should add namesapces, controller name and action name' do
14
- route = Route.new(['admin', 'test'], 'posts', 'new')
16
+ route = Route.new(%w[admin test], 'posts', 'new')
15
17
  expect(route.to_s).to eq('Admin::Test::PostsController#new')
16
18
  end
17
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices::Core
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Erubis::OnlyRuby do
4
6
  subject {
5
- content =<<-EOF
7
+ content = <<-EOF
6
8
  <h1>Title</h1>
7
9
  <% if current_user %>
8
10
  <%= link_to 'account', edit_user_path(current_user) %>
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices
4
6
  module Lexicals
5
7
  describe LongLineCheck do
6
-
7
8
  it 'should find long lines' do
8
9
  runner = Core::Runner.new(lexicals: LongLineCheck.new)
9
- content =<<-EOF
10
+ content = <<-EOF
10
11
  class User < ActiveRecord::Base
11
12
  # 81 Chars
12
13
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -14,14 +15,14 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14
15
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
15
16
  end
16
17
  EOF
17
- content.gsub!("\n", "\t\n")
18
+ content = content.gsub("\n", "\t\n")
18
19
  runner.lexical('app/models/user.rb', content)
19
20
  expect(runner.errors.size).to eq(1)
20
21
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - line is longer than 80 characters (81 characters)')
21
22
  end
22
23
  it 'should find long lines with own max size' do
23
24
  runner = Core::Runner.new(lexicals: LongLineCheck.new('max_line_length' => 90))
24
- content =<<-EOF
25
+ content = <<-EOF
25
26
  class User < ActiveRecord::Base
26
27
  # 91 Chars
27
28
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -29,7 +30,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
29
30
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
30
31
  end
31
32
  EOF
32
- content.gsub!("\n", "\t\n")
33
+ content = content.gsub("\n", "\t\n")
33
34
  runner.lexical('app/models/user.rb', content)
34
35
  expect(runner.errors.size).to eq(1)
35
36
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - line is longer than 90 characters (91 characters)')
@@ -44,13 +45,13 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
44
45
  end
45
46
  it 'should not check ignored files' do
46
47
  runner = Core::Runner.new(lexicals: LongLineCheck.new(max_line_length: 80, ignored_files: /user/))
47
- content =<<-EOF
48
+ content = <<-EOF
48
49
  class User < ActiveRecord::Base
49
50
  # 81 Chars
50
51
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
51
52
  end
52
53
  EOF
53
- content.gsub!("\n", "\t\n")
54
+ content = content.gsub("\n", "\t\n")
54
55
  runner.lexical('app/models/user.rb', content)
55
56
  expect(runner.errors.size).to eq(0)
56
57
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices
@@ -6,19 +8,19 @@ module RailsBestPractices
6
8
  let(:runner) { Core::Runner.new(lexicals: RemoveTabCheck.new) }
7
9
 
8
10
  it 'should remove tab' do
9
- content =<<-EOF
11
+ content = <<-EOF
10
12
  class User < ActiveRecord::Base
11
13
  has_many :projects
12
14
  end
13
15
  EOF
14
- content.gsub!("\n", "\t\n")
16
+ content = content.gsub("\n", "\t\n")
15
17
  runner.lexical('app/models/user.rb', content)
16
18
  expect(runner.errors.size).to eq(1)
17
19
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:1 - remove tab, use spaces instead')
18
20
  end
19
21
 
20
22
  it 'should remove tab with third line' do
21
- content =<<-EOF
23
+ content = <<-EOF
22
24
  class User < ActiveRecord::Base
23
25
  has_many :projects
24
26
  \t
@@ -30,7 +32,7 @@ module RailsBestPractices
30
32
  end
31
33
 
32
34
  it 'should not remove trailing whitespace' do
33
- content =<<-EOF
35
+ content = <<-EOF
34
36
  class User < ActiveRecord::Base
35
37
  has_many :projects
36
38
  end
@@ -40,14 +42,14 @@ module RailsBestPractices
40
42
  end
41
43
  it 'should not check ignored files' do
42
44
  runner = Core::Runner.new(lexicals: RemoveTabCheck.new(ignored_files: /user/))
43
- content =<<-EOF
45
+ content = <<-EOF
44
46
  class User < ActiveRecord::Base
45
47
  has_many :projects
46
48
 
47
49
  \t
48
50
  end
49
51
  EOF
50
- content.gsub!("\n", "\t\n")
52
+ content = content.gsub("\n", "\t\n")
51
53
  runner.lexical('app/models/user.rb', content)
52
54
  expect(runner.errors.size).to eq(0)
53
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module RailsBestPractices
@@ -6,31 +8,31 @@ module RailsBestPractices
6
8
  let(:runner) { Core::Runner.new(lexicals: RemoveTrailingWhitespaceCheck.new) }
7
9
 
8
10
  it 'should remove trailing whitespace' do
9
- content =<<-EOF
11
+ content = <<-EOF
10
12
  class User < ActiveRecord::Base
11
13
  has_many :projects
12
14
  end
13
15
  EOF
14
- content.gsub!("\n", " \n")
16
+ content = content.gsub("\n", " \n")
15
17
  runner.lexical('app/models/user.rb', content)
16
18
  expect(runner.errors.size).to eq(1)
17
19
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:1 - remove trailing whitespace')
18
20
  end
19
21
 
20
22
  it 'should remove whitespace with third line' do
21
- content =<<-EOF
23
+ content = <<-EOF
22
24
  class User < ActiveRecord::Base
23
25
  has_many :projects
24
26
  end
25
27
  EOF
26
- content.gsub!("d\n", "d \n")
28
+ content = content.gsub("d\n", "d \n")
27
29
  runner.lexical('app/models/user.rb', content)
28
30
  expect(runner.errors.size).to eq(1)
29
31
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - remove trailing whitespace')
30
32
  end
31
33
 
32
34
  it 'should not remove trailing whitespace' do
33
- content =<<-EOF
35
+ content = <<-EOF
34
36
  class User < ActiveRecord::Base
35
37
  has_many :projects
36
38
  end
@@ -41,12 +43,12 @@ module RailsBestPractices
41
43
 
42
44
  it 'should not check ignored files' do
43
45
  runner = Core::Runner.new(lexicals: RemoveTrailingWhitespaceCheck.new(ignored_files: /user/))
44
- content =<<-EOF
46
+ content = <<-EOF
45
47
  class User < ActiveRecord::Base
46
48
  has_many :projects
47
49
  end
48
50
  EOF
49
- content.gsub!("\n", " \n")
51
+ content = content.gsub("\n", " \n")
50
52
  runner.lexical('app/models/user.rb', content)
51
53
  expect(runner.errors.size).to eq(0)
52
54
  end
@@ -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
  context 'configs' do
9
11
  it 'should parse configs' do
10
- content =<<-EOF
12
+ content = <<-EOF
11
13
  module RailsBestPracticesCom
12
14
  class Application < Rails::Application
13
15
  config.active_record.whitelist_attributes = true
@@ -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
  context 'methods' do
9
11
  it 'should parse controller methods' do
10
- content =<<-EOF
12
+ content = <<-EOF
11
13
  class PostsController < ApplicationController
12
14
  def index; end
13
15
  def show; end
@@ -15,11 +17,11 @@ module RailsBestPractices
15
17
  EOF
16
18
  runner.prepare('app/controllers/posts_controller.rb', content)
17
19
  methods = Prepares.controller_methods
18
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'show'])
20
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index show])
19
21
  end
20
22
 
21
23
  it 'should parse model methods with access control' do
22
- content =<<-EOF
24
+ content = <<-EOF
23
25
  class PostsController < ApplicationController
24
26
  def index; end
25
27
  def show; end
@@ -31,14 +33,14 @@ module RailsBestPractices
31
33
  EOF
32
34
  runner.prepare('app/controllers/posts_controller.rb', content)
33
35
  methods = Prepares.controller_methods
34
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'show', 'resources', 'resource'])
35
- expect(methods.get_methods('PostsController', 'public').map(&:method_name)).to eq(['index', 'show'])
36
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index show resources resource])
37
+ expect(methods.get_methods('PostsController', 'public').map(&:method_name)).to eq(%w[index show])
36
38
  expect(methods.get_methods('PostsController', 'protected').map(&:method_name)).to eq(['resources'])
37
39
  expect(methods.get_methods('PostsController', 'private').map(&:method_name)).to eq(['resource'])
38
40
  end
39
41
 
40
42
  it 'should parse controller methods with module ::' do
41
- content =<<-EOF
43
+ content = <<-EOF
42
44
  class Admin::Blog::PostsController < ApplicationController
43
45
  def index; end
44
46
  def show; end
@@ -46,11 +48,11 @@ module RailsBestPractices
46
48
  EOF
47
49
  runner.prepare('app/controllers/admin/posts_controller.rb', content)
48
50
  methods = Prepares.controller_methods
49
- expect(methods.get_methods('Admin::Blog::PostsController').map(&:method_name)).to eq(['index', 'show'])
51
+ expect(methods.get_methods('Admin::Blog::PostsController').map(&:method_name)).to eq(%w[index show])
50
52
  end
51
53
 
52
54
  it 'should parse controller methods with module' do
53
- content =<<-EOF
55
+ content = <<-EOF
54
56
  module Admin
55
57
  module Blog
56
58
  class PostsController < ApplicationController
@@ -62,74 +64,74 @@ module RailsBestPractices
62
64
  EOF
63
65
  runner.prepare('app/controllers/admin/posts_controller.rb', content)
64
66
  methods = Prepares.controller_methods
65
- expect(methods.get_methods('Admin::Blog::PostsController').map(&:method_name)).to eq(['index', 'show'])
67
+ expect(methods.get_methods('Admin::Blog::PostsController').map(&:method_name)).to eq(%w[index show])
66
68
  end
67
69
 
68
70
  context 'inherited_resources' do
69
71
  it 'extend inherited_resources' do
70
- content =<<-EOF
72
+ content = <<-EOF
71
73
  class PostsController < InheritedResources::Base
72
74
  end
73
75
  EOF
74
76
  runner.prepare('app/controllers/posts_controller.rb', content)
75
77
  methods = Prepares.controller_methods
76
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'show', 'new', 'create', 'edit', 'update', 'destroy'])
78
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index show new create edit update destroy])
77
79
  end
78
80
 
79
81
  it 'extend inherited_resources with actions' do
80
- content =<<-EOF
82
+ content = <<-EOF
81
83
  class PostsController < InheritedResources::Base
82
84
  actions :index, :show
83
85
  end
84
86
  EOF
85
87
  runner.prepare('app/controllers/posts_controller.rb', content)
86
88
  methods = Prepares.controller_methods
87
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'show'])
89
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index show])
88
90
  end
89
91
 
90
92
  it 'extend inherited_resources with all actions' do
91
- content =<<-EOF
93
+ content = <<-EOF
92
94
  class PostsController < InheritedResources::Base
93
95
  actions :all, except: [:show]
94
96
  end
95
97
  EOF
96
98
  runner.prepare('app/controllers/posts_controller.rb', content)
97
99
  methods = Prepares.controller_methods
98
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'new', 'create', 'edit', 'update', 'destroy'])
100
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index new create edit update destroy])
99
101
  end
100
102
 
101
103
  it 'extend inherited_resources with all actions with no arguments' do
102
- content =<<-EOF
104
+ content = <<-EOF
103
105
  class PostsController < InheritedResources::Base
104
106
  actions :all
105
107
  end
106
108
  EOF
107
109
  runner.prepare('app/controllers/posts_controller.rb', content)
108
110
  methods = Prepares.controller_methods
109
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'show', 'new', 'create', 'edit', 'update', 'destroy'])
111
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index show new create edit update destroy])
110
112
  end
111
113
 
112
114
  it 'DSL inherit_resources' do
113
- content =<<-EOF
115
+ content = <<-EOF
114
116
  class PostsController
115
117
  inherit_resources
116
118
  end
117
119
  EOF
118
120
  runner.prepare('app/controllers/posts_controller.rb', content)
119
121
  methods = Prepares.controller_methods
120
- expect(methods.get_methods('PostsController').map(&:method_name)).to eq(['index', 'show', 'new', 'create', 'edit', 'update', 'destroy'])
122
+ expect(methods.get_methods('PostsController').map(&:method_name)).to eq(%w[index show new create edit update destroy])
121
123
  end
122
124
  end
123
125
  end
124
126
 
125
127
  context 'helpers' do
126
128
  it 'should add helper descendant' do
127
- content =<<-EOF
129
+ content = <<-EOF
128
130
  module PostsHelper
129
131
  end
130
132
  EOF
131
133
  runner.prepare('app/helpers/posts_helper.rb', content)
132
- content =<<-EOF
134
+ content = <<-EOF
133
135
  class PostsController
134
136
  include PostsHelper
135
137
  end