rails_best_practices 1.20.0 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +30 -26
  4. data/Guardfile +2 -0
  5. data/Rakefile +2 -0
  6. data/lib/rails_best_practices.rb +1 -2
  7. data/lib/rails_best_practices/analyzer.rb +56 -46
  8. data/lib/rails_best_practices/core/check.rb +39 -32
  9. data/lib/rails_best_practices/core/checks_loader.rb +8 -6
  10. data/lib/rails_best_practices/core/configs.rb +1 -2
  11. data/lib/rails_best_practices/core/controllers.rb +1 -2
  12. data/lib/rails_best_practices/core/error.rb +1 -1
  13. data/lib/rails_best_practices/core/helpers.rb +1 -2
  14. data/lib/rails_best_practices/core/mailers.rb +1 -2
  15. data/lib/rails_best_practices/core/methods.rb +21 -16
  16. data/lib/rails_best_practices/core/model_associations.rb +9 -4
  17. data/lib/rails_best_practices/core/models.rb +1 -2
  18. data/lib/rails_best_practices/core/modules.rb +1 -1
  19. data/lib/rails_best_practices/core/routes.rb +2 -2
  20. data/lib/rails_best_practices/core/runner.rb +29 -33
  21. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  22. data/lib/rails_best_practices/option_parser.rb +17 -6
  23. data/lib/rails_best_practices/prepares.rb +1 -1
  24. data/lib/rails_best_practices/prepares/controller_prepare.rb +15 -3
  25. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
  26. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  27. data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -2
  28. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -0
  29. data/lib/rails_best_practices/prepares/model_prepare.rb +52 -12
  30. data/lib/rails_best_practices/prepares/route_prepare.rb +16 -10
  31. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +15 -13
  32. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +34 -29
  33. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +14 -5
  34. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +19 -8
  35. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +5 -5
  36. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +4 -4
  37. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +7 -8
  38. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +6 -6
  39. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +6 -7
  41. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +7 -8
  42. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +12 -10
  43. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +5 -5
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +5 -2
  46. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +6 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -4
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +29 -9
  49. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +3 -3
  50. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +17 -15
  51. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -2
  52. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -3
  53. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -1
  54. data/lib/rails_best_practices/reviews/use_model_association_review.rb +5 -5
  55. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +9 -8
  56. data/lib/rails_best_practices/reviews/use_observer_review.rb +9 -9
  57. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +26 -26
  58. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +8 -7
  59. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +17 -15
  60. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  61. data/lib/rails_best_practices/version.rb +1 -1
  62. data/rails_best_practices.gemspec +35 -36
  63. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  64. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  65. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  66. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  67. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  68. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  69. data/spec/rails_best_practices/core/error_spec.rb +21 -21
  70. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  71. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  72. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  73. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  74. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  75. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  76. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  77. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  78. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  79. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  80. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  82. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  83. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +11 -10
  84. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  85. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  86. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  87. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  88. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +2 -2
  89. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  90. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  91. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  92. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  93. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +138 -77
  94. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  95. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  96. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  97. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  98. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  99. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  100. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  101. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  103. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  104. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +21 -14
  105. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  106. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  107. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +26 -16
  108. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  109. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  110. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  111. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  112. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  113. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  114. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  115. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -19
  116. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +44 -31
  118. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +17 -12
  119. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +46 -44
  120. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  121. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -10
  122. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  123. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  124. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  125. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  126. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  127. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +21 -17
  128. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  129. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +9 -7
  130. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  131. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  132. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  133. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +10 -8
  134. metadata +7 -7
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe DefaultScopeIsEvilReview do
8
- let(:runner) { Core::Runner.new(reviews: DefaultScopeIsEvilReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should detect default_scope with -> syntax' do
10
+ it 'detects default_scope with -> syntax' do
11
11
  content = <<-EOF
12
12
  class User < ActiveRecord::Base
13
13
  default_scope -> { order('created_at desc') }
@@ -18,7 +18,7 @@ module RailsBestPractices
18
18
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:2 - default_scope is evil')
19
19
  end
20
20
 
21
- it 'should detect default_scope with old syntax' do
21
+ it 'detects default_scope with old syntax' do
22
22
  content = <<-EOF
23
23
  class User < ActiveRecord::Base
24
24
  default_scope order('created_at desc')
@@ -29,7 +29,7 @@ module RailsBestPractices
29
29
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:2 - default_scope is evil')
30
30
  end
31
31
 
32
- it 'should not detect default_scope' do
32
+ it 'does not detect default_scope' do
33
33
  content = <<-EOF
34
34
  class User < ActiveRecord::Base
35
35
  scope :default, -> { order('created_at desc') }
@@ -39,8 +39,8 @@ module RailsBestPractices
39
39
  expect(runner.errors.size).to eq(0)
40
40
  end
41
41
 
42
- it 'should not check ignored files' do
43
- runner = Core::Runner.new(reviews: DefaultScopeIsEvilReview.new(ignored_files: /user/))
42
+ it 'does not check ignored files' do
43
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /user/))
44
44
  content = <<-EOF
45
45
  class User < ActiveRecord::Base
46
46
  default_scope -> { order('created_at desc') }
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe DryBundlerInCapistranoReview do
8
- let(:runner) { Core::Runner.new(reviews: DryBundlerInCapistranoReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should dry bundler in capistrno' do
10
+ it 'dries bundler in capistrno' do
11
11
  content = <<-EOF
12
12
  namespace :bundler do
13
13
  task :create_symlink, roles: :app do
@@ -29,7 +29,7 @@ module RailsBestPractices
29
29
  expect(runner.errors[0].to_s).to eq('config/deploy.rb:1 - dry bundler in capistrano')
30
30
  end
31
31
 
32
- it 'should not dry bundler in capistrano' do
32
+ it 'does not dry bundler in capistrano' do
33
33
  content = <<-EOF
34
34
  require 'bundler/capistrano'
35
35
  EOF
@@ -37,8 +37,8 @@ module RailsBestPractices
37
37
  expect(runner.errors.size).to eq(0)
38
38
  end
39
39
 
40
- it 'should not check ignored files' do
41
- runner = Core::Runner.new(reviews: DryBundlerInCapistranoReview.new(ignored_files: /deploy\.rb/))
40
+ it 'does not check ignored files' do
41
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /deploy\.rb/))
42
42
  content = <<-EOF
43
43
  namespace :bundler do
44
44
  task :create_symlink, roles: :app do
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe HashSyntaxReview do
8
- let(:runner) { Core::Runner.new(reviews: HashSyntaxReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should find 1.8 Hash with symbol' do
10
+ it 'finds 1.8 Hash with symbol' do
11
11
  content = <<-EOF
12
12
  class User < ActiveRecord::Base
13
13
  CONST = { :foo => :bar }
@@ -18,7 +18,7 @@ module RailsBestPractices
18
18
  expect(runner.errors[0].to_s).to eq('app/models/user.rb:2 - change Hash Syntax to 1.9')
19
19
  end
20
20
 
21
- it 'should not find 1.8 Hash with string' do
21
+ it 'does not find 1.8 Hash with string' do
22
22
  content = <<-EOF
23
23
  class User < ActiveRecord::Base
24
24
  CONST = { "foo" => "bar" }
@@ -28,7 +28,7 @@ module RailsBestPractices
28
28
  expect(runner.errors.size).to eq(0)
29
29
  end
30
30
 
31
- it 'should not alert on 1.9 Syntax' do
31
+ it 'does not alert on 1.9 Syntax' do
32
32
  content = <<-EOF
33
33
  class User < ActiveRecord::Base
34
34
  CONST = { foo: :bar }
@@ -38,7 +38,7 @@ module RailsBestPractices
38
38
  expect(runner.errors.size).to eq(0)
39
39
  end
40
40
 
41
- it 'should ignore haml_out' do
41
+ it 'ignores haml_out' do
42
42
  content = <<~EOF
43
43
  %div{ class: "foo1" }
44
44
  .div{ class: "foo2" }
@@ -48,7 +48,7 @@ module RailsBestPractices
48
48
  expect(runner.errors.size).to eq(0)
49
49
  end
50
50
 
51
- it 'should not consider hash with array key' do
51
+ it 'does not consider hash with array key' do
52
52
  content = <<-EOF
53
53
  transition [:unverified, :verified] => :deleted
54
54
  EOF
@@ -56,7 +56,7 @@ module RailsBestPractices
56
56
  expect(runner.errors.size).to eq(0)
57
57
  end
58
58
 
59
- it 'should not consider hash with charaters not valid for symbol' do
59
+ it 'does not consider hash with charaters not valid for symbol' do
60
60
  content = <<-EOF
61
61
  receiver.stub(:` => 'Error')
62
62
  EOF
@@ -64,8 +64,8 @@ module RailsBestPractices
64
64
  expect(runner.errors.size).to eq(0)
65
65
  end
66
66
 
67
- it 'should not check ignored files' do
68
- runner = Core::Runner.new(reviews: HashSyntaxReview.new(ignored_files: /user/))
67
+ it 'does not check ignored files' do
68
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /user/))
69
69
  content = <<-EOF
70
70
  class User < ActiveRecord::Base
71
71
  CONST = { :foo => :bar }
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe IsolateSeedDataReview do
8
- let(:runner) { Core::Runner.new(reviews: IsolateSeedDataReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
10
  context 'create' do
11
- it 'should isolate seed data' do
11
+ it 'isolates seed data' do
12
12
  content = <<-EOF
13
13
  class CreateRoles < ActiveRecord::Migration
14
14
  def self.up
@@ -33,7 +33,7 @@ module RailsBestPractices
33
33
  end
34
34
 
35
35
  context 'new and save' do
36
- it 'should isolate seed data for local variable' do
36
+ it 'isolates seed data for local variable' do
37
37
  content = <<-EOF
38
38
  class CreateRoles < ActiveRecord::Migration
39
39
  def self.up
@@ -57,7 +57,7 @@ module RailsBestPractices
57
57
  expect(runner.errors[0].to_s).to eq('db/migrate/20090818130258_create_roles.rb:9 - isolate seed data')
58
58
  end
59
59
 
60
- it 'should isolate seed data for instance variable' do
60
+ it 'isolates seed data for instance variable' do
61
61
  content = <<-EOF
62
62
  class CreateRoles < ActiveRecord::Migration
63
63
  def self.up
@@ -82,7 +82,7 @@ module RailsBestPractices
82
82
  end
83
83
  end
84
84
 
85
- it 'should not isolate seed data without data insert' do
85
+ it 'does not isolate seed data without data insert' do
86
86
  content = <<-EOF
87
87
  class CreateRoles < ActiveRecord::Migration
88
88
  def self.up
@@ -100,8 +100,8 @@ module RailsBestPractices
100
100
  expect(runner.errors.size).to eq(0)
101
101
  end
102
102
 
103
- it 'should not check ignored files' do
104
- runner = Core::Runner.new(reviews: IsolateSeedDataReview.new(ignored_files: /create_roles/))
103
+ it 'does not check ignored files' do
104
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: /create_roles/))
105
105
  content = <<-EOF
106
106
  class CreateRoles < ActiveRecord::Migration
107
107
  def self.up
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe KeepFindersOnTheirOwnModelReview do
8
- let(:runner) { Core::Runner.new(reviews: KeepFindersOnTheirOwnModelReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should keep finders on thier own model' do
10
+ it 'keeps finders on thier own model' do
11
11
  content = <<-EOF
12
12
  class Post < ActiveRecord::Base
13
13
  has_many :comments
@@ -23,7 +23,7 @@ module RailsBestPractices
23
23
  expect(runner.errors[0].to_s).to eq('app/models/post.rb:5 - keep finders on their own model')
24
24
  end
25
25
 
26
- it 'should keep finders on thier own model with all method' do
26
+ it 'keeps finders on thier own model with all method' do
27
27
  content = <<-EOF
28
28
  class Post < ActiveRecord::Base
29
29
  has_many :comments
@@ -39,7 +39,7 @@ module RailsBestPractices
39
39
  expect(runner.errors[0].to_s).to eq('app/models/post.rb:5 - keep finders on their own model')
40
40
  end
41
41
 
42
- it 'should not keep finders on thier own model with self finder' do
42
+ it 'does not keep finders on thier own model with self finder' do
43
43
  content = <<-EOF
44
44
  class Post < ActiveRecord::Base
45
45
  has_many :comments
@@ -54,7 +54,7 @@ module RailsBestPractices
54
54
  expect(runner.errors.size).to eq(0)
55
55
  end
56
56
 
57
- it 'should not keep finders on thier own model with own finder' do
57
+ it 'does not keep finders on thier own model with own finder' do
58
58
  content = <<-EOF
59
59
  class Post < ActiveRecord::Base
60
60
  has_many :comments
@@ -69,7 +69,7 @@ module RailsBestPractices
69
69
  expect(runner.errors.size).to eq(0)
70
70
  end
71
71
 
72
- it 'should not keep finders on their own model without finder' do
72
+ it 'does not keep finders on their own model without finder' do
73
73
  content = <<-EOF
74
74
  class Post < ActiveRecord::Base
75
75
  has_many :comments
@@ -83,7 +83,7 @@ module RailsBestPractices
83
83
  expect(runner.errors.size).to eq(0)
84
84
  end
85
85
 
86
- it 'should not keep finders on their own model with ruby Array#find' do
86
+ it 'does not keep finders on their own model with ruby Array#find' do
87
87
  content = <<-EOF
88
88
  class Post < ActiveRecord::Base
89
89
  has_many :comments
@@ -97,8 +97,8 @@ module RailsBestPractices
97
97
  expect(runner.errors.size).to eq(0)
98
98
  end
99
99
 
100
- it 'should not check ignored files' do
101
- runner = Core::Runner.new(reviews: KeepFindersOnTheirOwnModelReview.new(ignored_files: /app\/models\/post\.rb/))
100
+ it 'does not check ignored files' do
101
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/models/post\.rb}))
102
102
  content = <<-EOF
103
103
  class Post < ActiveRecord::Base
104
104
  has_many :comments
@@ -5,10 +5,14 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe LawOfDemeterReview do
8
- let(:runner) { Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new], reviews: LawOfDemeterReview.new) }
8
+ let(:runner) do
9
+ Core::Runner.new(
10
+ prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new], reviews: described_class.new
11
+ )
12
+ end
9
13
 
10
14
  describe 'belongs_to' do
11
- before(:each) do
15
+ before do
12
16
  content = <<-EOF
13
17
  class Invoice < ActiveRecord::Base
14
18
  belongs_to :user
@@ -28,7 +32,7 @@ module RailsBestPractices
28
32
  runner.prepare('db/schema.rb', content)
29
33
  end
30
34
 
31
- it 'should law of demeter with erb' do
35
+ it 'laws of demeter with erb' do
32
36
  content = <<-EOF
33
37
  <%= @invoice.user.name %>
34
38
  <%= @invoice.user.address %>
@@ -39,7 +43,7 @@ module RailsBestPractices
39
43
  expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.erb:1 - law of demeter')
40
44
  end
41
45
 
42
- it 'should law of demeter with haml' do
46
+ it 'laws of demeter with haml' do
43
47
  content = <<~EOF
44
48
  = @invoice.user.name
45
49
  = @invoice.user.address
@@ -50,7 +54,7 @@ module RailsBestPractices
50
54
  expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.haml:1 - law of demeter')
51
55
  end
52
56
 
53
- it 'should law of demeter with slim' do
57
+ it 'laws of demeter with slim' do
54
58
  content = <<~EOF
55
59
  = @invoice.user.name
56
60
  = @invoice.user.address
@@ -61,7 +65,7 @@ module RailsBestPractices
61
65
  expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.slim:1 - law of demeter')
62
66
  end
63
67
 
64
- it 'should no law of demeter' do
68
+ it 'noes law of demeter' do
65
69
  content = <<-EOF
66
70
  <%= @invoice.user_name %>
67
71
  <%= @invoice.user_address %>
@@ -73,7 +77,7 @@ module RailsBestPractices
73
77
  end
74
78
 
75
79
  describe 'has_one' do
76
- before(:each) do
80
+ before do
77
81
  content = <<-EOF
78
82
  class Invoice < ActiveRecord::Base
79
83
  has_one :price
@@ -92,7 +96,7 @@ module RailsBestPractices
92
96
  runner.prepare('db/schema.rb', content)
93
97
  end
94
98
 
95
- it 'should law of demeter' do
99
+ it 'laws of demeter' do
96
100
  content = <<-EOF
97
101
  <%= @invoice.price.currency %>
98
102
  <%= @invoice.price.number %>
@@ -104,7 +108,7 @@ module RailsBestPractices
104
108
  end
105
109
 
106
110
  context 'polymorphic association' do
107
- before :each do
111
+ before do
108
112
  content = <<-EOF
109
113
  class Comment < ActiveRecord::Base
110
114
  belongs_to :commentable, polymorphic: true
@@ -129,7 +133,7 @@ module RailsBestPractices
129
133
  runner.prepare('db/schema.rb', content)
130
134
  end
131
135
 
132
- it 'should law of demeter' do
136
+ it 'laws of demeter' do
133
137
  content = <<-EOF
134
138
  <%= @comment.commentable.title %>
135
139
  EOF
@@ -139,7 +143,7 @@ module RailsBestPractices
139
143
  end
140
144
  end
141
145
 
142
- it 'should no law of demeter with method call' do
146
+ it 'noes law of demeter with method call' do
143
147
  content = <<-EOF
144
148
  class Question < ActiveRecord::Base
145
149
  has_many :answers, dependent: :destroy
@@ -163,9 +167,12 @@ module RailsBestPractices
163
167
  expect(runner.errors.size).to eq(0)
164
168
  end
165
169
 
166
- it 'should not check ignored files' do
167
- runner = Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
168
- reviews: LawOfDemeterReview.new(ignored_files: /app\/views\/invoices/))
170
+ it 'does not check ignored files' do
171
+ runner =
172
+ Core::Runner.new(
173
+ prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
174
+ reviews: described_class.new(ignored_files: %r{app/views/invoices})
175
+ )
169
176
  content = <<-EOF
170
177
  <%= @invoice.user.name %>
171
178
  <%= @invoice.user.address %>
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe MoveCodeIntoControllerReview do
8
- let(:runner) { Core::Runner.new(reviews: MoveCodeIntoControllerReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should move code into controller for method call' do
10
+ it 'moves code into controller for method call' do
11
11
  content = <<-EOF
12
12
  <% Post.find(:all).each do |post| %>
13
13
  <%=h post.title %>
@@ -19,7 +19,7 @@ module RailsBestPractices
19
19
  expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - move code into controller')
20
20
  end
21
21
 
22
- it 'should move code into controller for assign' do
22
+ it 'moves code into controller for assign' do
23
23
  content = <<-EOF
24
24
  <% @posts = Post.all %>
25
25
  <% @posts.each do |post| %>
@@ -32,7 +32,7 @@ module RailsBestPractices
32
32
  expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - move code into controller')
33
33
  end
34
34
 
35
- it 'should not move code into controller' do
35
+ it 'does not move code into controller' do
36
36
  content = <<-EOF
37
37
  <% @posts.each do |post| %>
38
38
  <%=h post.title %>
@@ -43,8 +43,8 @@ module RailsBestPractices
43
43
  expect(runner.errors.size).to eq(0)
44
44
  end
45
45
 
46
- it 'should not check ignored files' do
47
- runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new(ignored_files: /app\/views\/post/))
46
+ it 'does not check ignored files' do
47
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/views/post}))
48
48
  content = <<-EOF
49
49
  <% Post.find(:all).each do |post| %>
50
50
  <%=h post.title %>
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe MoveCodeIntoHelperReview do
8
- let(:runner) { Core::Runner.new(reviews: MoveCodeIntoHelperReview.new('array_count' => 2)) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new('array_count' => 2)) }
9
9
 
10
- it 'should move code into helper' do
10
+ it 'moves code into helper' do
11
11
  content = <<-EOF
12
12
  <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
13
13
  [t(:published), "published"]],
@@ -15,10 +15,12 @@ module RailsBestPractices
15
15
  EOF
16
16
  runner.review('app/views/posts/show.html.erb', content)
17
17
  expect(runner.errors.size).to eq(1)
18
- expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)')
18
+ expect(runner.errors[0].to_s).to eq(
19
+ 'app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)'
20
+ )
19
21
  end
20
22
 
21
- it 'should not move code into helper with simple arguments' do
23
+ it 'does not move code into helper with simple arguments' do
22
24
  content = <<-EOF
23
25
  <%= select_tag :state, options_for_select( Post.STATES ) %>
24
26
  EOF
@@ -26,8 +28,11 @@ module RailsBestPractices
26
28
  expect(runner.errors.size).to eq(0)
27
29
  end
28
30
 
29
- it 'should not check ignored files' do
30
- runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new('array_count' => 2, 'ignored_files' => /app\/views\/post/))
31
+ it 'does not check ignored files' do
32
+ runner =
33
+ Core::Runner.new(
34
+ reviews: MoveCodeIntoControllerReview.new('array_count' => 2, 'ignored_files' => %r{app/views/post})
35
+ )
31
36
  content = <<-EOF
32
37
  <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
33
38
  [t(:published), "published"]],
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Reviews
7
7
  describe MoveCodeIntoModelReview do
8
- let(:runner) { Core::Runner.new(reviews: MoveCodeIntoModelReview.new) }
8
+ let(:runner) { Core::Runner.new(reviews: described_class.new) }
9
9
 
10
- it 'should move code into model' do
10
+ it 'moves code into model' do
11
11
  content = <<-EOF
12
12
  <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
13
13
  <%= link_to 'Edit this post', edit_post_url(@post) %>
@@ -15,48 +15,58 @@ module RailsBestPractices
15
15
  EOF
16
16
  runner.review('app/views/posts/show.html.erb', content)
17
17
  expect(runner.errors.size).to eq(1)
18
- expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)')
18
+ expect(runner.errors[0].to_s).to eq(
19
+ 'app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)'
20
+ )
19
21
  end
20
22
 
21
- it 'should move code into model with haml' do
23
+ it 'moves code into model with haml' do
22
24
  content = <<~EOF
23
25
  - if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
24
26
  = link_to 'Edit this post', edit_post_url(@post)
25
27
  EOF
26
28
  runner.review('app/views/posts/show.html.haml', content)
27
29
  expect(runner.errors.size).to eq(1)
28
- expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)')
30
+ expect(runner.errors[0].to_s).to eq(
31
+ 'app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)'
32
+ )
29
33
  end
30
34
 
31
- it 'should move code into model with slim' do
35
+ it 'moves code into model with slim' do
32
36
  content = <<~EOF
33
37
  - if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
34
38
  = link_to 'Edit this post', edit_post_url(@post)
35
39
  EOF
36
40
  runner.review('app/views/posts/show.html.slim', content)
37
41
  expect(runner.errors.size).to eq(1)
38
- expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)')
42
+ expect(runner.errors[0].to_s).to eq(
43
+ 'app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)'
44
+ )
39
45
  end
40
46
 
41
- it 'should move code into model with if in one line' do
47
+ it 'moves code into model with if in one line' do
42
48
  content = <<-EOF
43
49
  <%= link_to 'Edit this post', edit_post_url(@post) if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
44
50
  EOF
45
51
  runner.review('app/views/posts/show.html.erb', content)
46
52
  expect(runner.errors.size).to eq(1)
47
- expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)')
53
+ expect(runner.errors[0].to_s).to eq(
54
+ 'app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)'
55
+ )
48
56
  end
49
57
 
50
- it "should move code into model with '? :'" do
58
+ it "moves code into model with '? :'" do
51
59
  content = <<-EOF
52
60
  <%= current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) ? link_to('Edit this post', edit_post_url(@post)) : '' %>
53
61
  EOF
54
62
  runner.review('app/views/posts/show.html.erb', content)
55
63
  expect(runner.errors.size).to eq(1)
56
- expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)')
64
+ expect(runner.errors[0].to_s).to eq(
65
+ 'app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)'
66
+ )
57
67
  end
58
68
 
59
- it 'should move code into model only review for current if conditional statement' do
69
+ it 'moves code into model only review for current if conditional statement' do
60
70
  content = <<-EOF
61
71
  <% if @post.title %>
62
72
  <% if @post.user %>
@@ -69,7 +79,7 @@ module RailsBestPractices
69
79
  expect(runner.errors.size).to eq(0)
70
80
  end
71
81
 
72
- it 'should not move code into model' do
82
+ it 'does not move code into model' do
73
83
  content = <<-EOF
74
84
  <% if @post.editable_by?(current_user) %>
75
85
  <%= link_to 'Edit this post', edit_post_url(@post) %>
@@ -79,7 +89,7 @@ module RailsBestPractices
79
89
  expect(runner.errors.size).to eq(0)
80
90
  end
81
91
 
82
- it 'should not move code into model for multiple calls on same variable node' do
92
+ it 'does not move code into model for multiple calls on same variable node' do
83
93
  content = <<-EOF
84
94
  <% if !job.company.blank? && job.company.title? %>
85
95
  <% end %>
@@ -88,8 +98,8 @@ module RailsBestPractices
88
98
  expect(runner.errors.size).to eq(0)
89
99
  end
90
100
 
91
- it 'should not check ignored files' do
92
- runner = Core::Runner.new(reviews: MoveCodeIntoModelReview.new(ignored_files: /app\/views\/post/))
101
+ it 'does not check ignored files' do
102
+ runner = Core::Runner.new(reviews: described_class.new(ignored_files: %r{app/views/post}))
93
103
  content = <<-EOF
94
104
  <% if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user)) %>
95
105
  <%= link_to 'Edit this post', edit_post_url(@post) %>