rails_best_practices 1.19.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Guardfile +2 -2
  4. data/Rakefile +8 -8
  5. data/bin/rails_best_practices +1 -1
  6. data/lib/rails_best_practices/analyzer.rb +45 -45
  7. data/lib/rails_best_practices/command.rb +40 -40
  8. data/lib/rails_best_practices/core/check.rb +15 -15
  9. data/lib/rails_best_practices/core/klasses.rb +1 -1
  10. data/lib/rails_best_practices/core/methods.rb +7 -7
  11. data/lib/rails_best_practices/core/model_associations.rb +3 -3
  12. data/lib/rails_best_practices/core/modules.rb +1 -1
  13. data/lib/rails_best_practices/core/routes.rb +2 -2
  14. data/lib/rails_best_practices/core/runner.rb +3 -3
  15. data/lib/rails_best_practices/core_ext/erubis.rb +4 -4
  16. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -2
  17. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -2
  18. data/lib/rails_best_practices/prepares/config_prepare.rb +1 -1
  19. data/lib/rails_best_practices/prepares/controller_prepare.rb +8 -8
  20. data/lib/rails_best_practices/prepares/helper_prepare.rb +1 -1
  21. data/lib/rails_best_practices/prepares/initializer_prepare.rb +4 -4
  22. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -1
  23. data/lib/rails_best_practices/prepares/model_prepare.rb +19 -19
  24. data/lib/rails_best_practices/prepares/route_prepare.rb +34 -34
  25. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  26. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
  27. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +7 -7
  28. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +1 -1
  29. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +3 -3
  30. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +3 -3
  31. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +1 -1
  32. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +6 -6
  33. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +2 -2
  34. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +4 -4
  35. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -3
  36. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
  37. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
  38. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +2 -2
  39. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +4 -4
  41. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -2
  42. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +4 -4
  43. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +3 -3
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -2
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +9 -9
  46. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +3 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -11
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +1 -1
  49. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +8 -7
  50. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
  51. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -2
  52. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +22 -22
  53. data/lib/rails_best_practices/reviews/review.rb +2 -2
  54. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +3 -3
  55. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +4 -4
  56. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -2
  57. data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
  58. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +2 -2
  59. data/lib/rails_best_practices/reviews/use_observer_review.rb +3 -3
  60. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +1 -1
  61. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +3 -3
  62. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -2
  63. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +5 -5
  64. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +4 -4
  65. data/lib/rails_best_practices/version.rb +1 -1
  66. data/rails_best_practices.gemspec +24 -24
  67. data/spec/rails_best_practices/analyzer_spec.rb +43 -43
  68. data/spec/rails_best_practices/core/check_spec.rb +2 -2
  69. data/spec/rails_best_practices/core/checks_loader_spec.rb +4 -4
  70. data/spec/rails_best_practices/core/error_spec.rb +16 -16
  71. data/spec/rails_best_practices/core/except_methods_spec.rb +15 -15
  72. data/spec/rails_best_practices/core/gems_spec.rb +9 -9
  73. data/spec/rails_best_practices/core/klasses_spec.rb +17 -17
  74. data/spec/rails_best_practices/core/methods_spec.rb +28 -28
  75. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -10
  76. data/spec/rails_best_practices/core/model_attributes_spec.rb +10 -10
  77. data/spec/rails_best_practices/core/modules_spec.rb +10 -10
  78. data/spec/rails_best_practices/core/routes_spec.rb +10 -10
  79. data/spec/rails_best_practices/core/runner_spec.rb +4 -4
  80. data/spec/rails_best_practices/core_ext/erubis_spec.rb +7 -7
  81. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +7 -7
  82. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  83. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  84. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -3
  85. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +26 -26
  86. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -3
  87. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +6 -6
  88. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +5 -5
  89. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  90. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +108 -108
  91. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +77 -77
  92. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +8 -8
  93. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +10 -10
  94. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +27 -27
  95. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +11 -11
  96. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +17 -17
  97. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  98. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +4 -4
  99. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +8 -8
  100. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +10 -10
  101. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +16 -16
  103. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  104. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +4 -4
  105. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +13 -13
  106. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  107. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +5 -5
  108. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +10 -10
  109. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +8 -8
  110. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +4 -4
  111. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +11 -11
  112. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  113. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +16 -16
  114. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +5 -5
  115. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -33
  116. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +7 -7
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +106 -106
  118. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +5 -5
  119. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +8 -8
  120. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +29 -29
  121. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +15 -15
  122. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +15 -15
  123. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  125. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +29 -29
  126. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  127. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +28 -28
  129. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -9
  130. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +23 -23
  131. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +6 -6
  132. data/spec/spec_helper.rb +1 -1
  133. metadata +7 -7
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe DefaultScopeIsEvilReview do
6
6
  let(:runner) { Core::Runner.new(reviews: DefaultScopeIsEvilReview.new) }
7
7
 
8
- it "should detect default_scope with -> syntax" do
8
+ it 'should detect default_scope with -> syntax' do
9
9
  content = <<-EOF
10
10
  class User < ActiveRecord::Base
11
11
  default_scope -> { order('created_at desc') }
@@ -13,10 +13,10 @@ module RailsBestPractices
13
13
  EOF
14
14
  runner.review('app/models/user.rb', content)
15
15
  expect(runner.errors.size).to eq(1)
16
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - default_scope is evil")
16
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:2 - default_scope is evil')
17
17
  end
18
18
 
19
- it "should detect default_scope with old syntax" do
19
+ it 'should detect default_scope with old syntax' do
20
20
  content = <<-EOF
21
21
  class User < ActiveRecord::Base
22
22
  default_scope order('created_at desc')
@@ -24,10 +24,10 @@ module RailsBestPractices
24
24
  EOF
25
25
  runner.review('app/models/user.rb', content)
26
26
  expect(runner.errors.size).to eq(1)
27
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - default_scope is evil")
27
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:2 - default_scope is evil')
28
28
  end
29
29
 
30
- it "should not detect default_scope" do
30
+ it 'should not detect default_scope' do
31
31
  content = <<-EOF
32
32
  class User < ActiveRecord::Base
33
33
  scope :default, -> { order('created_at desc') }
@@ -37,7 +37,7 @@ module RailsBestPractices
37
37
  expect(runner.errors.size).to eq(0)
38
38
  end
39
39
 
40
- it "should not check ignored files" do
40
+ it 'should not check ignored files' do
41
41
  runner = Core::Runner.new(reviews: DefaultScopeIsEvilReview.new(ignored_files: /user/))
42
42
  content = <<-EOF
43
43
  class User < ActiveRecord::Base
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe DryBundlerInCapistranoReview do
6
6
  let(:runner) { Core::Runner.new(reviews: DryBundlerInCapistranoReview.new) }
7
7
 
8
- it "should dry bundler in capistrno" do
8
+ it 'should dry bundler in capistrno' do
9
9
  content = <<-EOF
10
10
  namespace :bundler do
11
11
  task :create_symlink, roles: :app do
@@ -24,10 +24,10 @@ module RailsBestPractices
24
24
  EOF
25
25
  runner.review('config/deploy.rb', content)
26
26
  expect(runner.errors.size).to eq(1)
27
- expect(runner.errors[0].to_s).to eq("config/deploy.rb:1 - dry bundler in capistrano")
27
+ expect(runner.errors[0].to_s).to eq('config/deploy.rb:1 - dry bundler in capistrano')
28
28
  end
29
29
 
30
- it "should not dry bundler in capistrano" do
30
+ it 'should not dry bundler in capistrano' do
31
31
  content = <<-EOF
32
32
  require 'bundler/capistrano'
33
33
  EOF
@@ -35,7 +35,7 @@ module RailsBestPractices
35
35
  expect(runner.errors.size).to eq(0)
36
36
  end
37
37
 
38
- it "should not check ignored files" do
38
+ it 'should not check ignored files' do
39
39
  runner = Core::Runner.new(reviews: DryBundlerInCapistranoReview.new(ignored_files: /deploy\.rb/))
40
40
  content = <<-EOF
41
41
  namespace :bundler do
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe HashSyntaxReview do
6
6
  let(:runner) { Core::Runner.new(reviews: HashSyntaxReview.new) }
7
7
 
8
- it "should find 1.8 Hash with symbol" do
8
+ it 'should find 1.8 Hash with symbol' do
9
9
  content =<<-EOF
10
10
  class User < ActiveRecord::Base
11
11
  CONST = { :foo => :bar }
@@ -13,10 +13,10 @@ module RailsBestPractices
13
13
  EOF
14
14
  runner.review('app/models/user.rb', content)
15
15
  expect(runner.errors.size).to eq(1)
16
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - change Hash Syntax to 1.9")
16
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:2 - change Hash Syntax to 1.9')
17
17
  end
18
18
 
19
- it "should not find 1.8 Hash with string" do
19
+ it 'should not find 1.8 Hash with string' do
20
20
  content =<<-EOF
21
21
  class User < ActiveRecord::Base
22
22
  CONST = { "foo" => "bar" }
@@ -26,7 +26,7 @@ module RailsBestPractices
26
26
  expect(runner.errors.size).to eq(0)
27
27
  end
28
28
 
29
- it "should not alert on 1.9 Syntax" do
29
+ it 'should not alert on 1.9 Syntax' do
30
30
  content =<<-EOF
31
31
  class User < ActiveRecord::Base
32
32
  CONST = { foo: :bar }
@@ -36,7 +36,7 @@ module RailsBestPractices
36
36
  expect(runner.errors.size).to eq(0)
37
37
  end
38
38
 
39
- it "should ignore haml_out" do
39
+ it 'should ignore haml_out' do
40
40
  content =<<-EOF
41
41
  %div{ class: "foo1" }
42
42
  .div{ class: "foo2" }
@@ -46,7 +46,7 @@ module RailsBestPractices
46
46
  expect(runner.errors.size).to eq(0)
47
47
  end
48
48
 
49
- it "should not consider hash with array key" do
49
+ it 'should not consider hash with array key' do
50
50
  content =<<-EOF
51
51
  transition [:unverified, :verified] => :deleted
52
52
  EOF
@@ -54,7 +54,7 @@ module RailsBestPractices
54
54
  expect(runner.errors.size).to eq(0)
55
55
  end
56
56
 
57
- it "should not consider hash with charaters not valid for symbol" do
57
+ it 'should not consider hash with charaters not valid for symbol' do
58
58
  content =<<-EOF
59
59
  receiver.stub(:` => 'Error')
60
60
  EOF
@@ -62,7 +62,7 @@ module RailsBestPractices
62
62
  expect(runner.errors.size).to eq(0)
63
63
  end
64
64
 
65
- it "should not check ignored files" do
65
+ it 'should not check ignored files' do
66
66
  runner = Core::Runner.new(reviews: HashSyntaxReview.new(ignored_files: /user/))
67
67
  content =<<-EOF
68
68
  class User < ActiveRecord::Base
@@ -5,8 +5,8 @@ module RailsBestPractices
5
5
  describe IsolateSeedDataReview do
6
6
  let(:runner) { Core::Runner.new(reviews: IsolateSeedDataReview.new) }
7
7
 
8
- context "create" do
9
- it "should isolate seed data" do
8
+ context 'create' do
9
+ it 'should isolate seed data' do
10
10
  content = <<-EOF
11
11
  class CreateRoles < ActiveRecord::Migration
12
12
  def self.up
@@ -26,12 +26,12 @@ module RailsBestPractices
26
26
  EOF
27
27
  runner.review('db/migrate/20090818130258_create_roles.rb', content)
28
28
  expect(runner.errors.size).to eq(1)
29
- expect(runner.errors[0].to_s).to eq("db/migrate/20090818130258_create_roles.rb:8 - isolate seed data")
29
+ expect(runner.errors[0].to_s).to eq('db/migrate/20090818130258_create_roles.rb:8 - isolate seed data')
30
30
  end
31
31
  end
32
32
 
33
- context "new and save" do
34
- it "should isolate seed data for local variable" do
33
+ context 'new and save' do
34
+ it 'should isolate seed data for local variable' do
35
35
  content = <<-EOF
36
36
  class CreateRoles < ActiveRecord::Migration
37
37
  def self.up
@@ -52,10 +52,10 @@ module RailsBestPractices
52
52
  EOF
53
53
  runner.review('db/migrate/20090818130258_create_roles.rb', content)
54
54
  expect(runner.errors.size).to eq(1)
55
- expect(runner.errors[0].to_s).to eq("db/migrate/20090818130258_create_roles.rb:9 - isolate seed data")
55
+ expect(runner.errors[0].to_s).to eq('db/migrate/20090818130258_create_roles.rb:9 - isolate seed data')
56
56
  end
57
57
 
58
- it "should isolate seed data for instance variable" do
58
+ it 'should isolate seed data for instance variable' do
59
59
  content = <<-EOF
60
60
  class CreateRoles < ActiveRecord::Migration
61
61
  def self.up
@@ -76,11 +76,11 @@ module RailsBestPractices
76
76
  EOF
77
77
  runner.review('db/migrate/20090818130258_create_roles.rb', content)
78
78
  expect(runner.errors.size).to eq(1)
79
- expect(runner.errors[0].to_s).to eq("db/migrate/20090818130258_create_roles.rb:9 - isolate seed data")
79
+ expect(runner.errors[0].to_s).to eq('db/migrate/20090818130258_create_roles.rb:9 - isolate seed data')
80
80
  end
81
81
  end
82
82
 
83
- it "should not isolate seed data without data insert" do
83
+ it 'should not isolate seed data without data insert' do
84
84
  content = <<-EOF
85
85
  class CreateRoles < ActiveRecord::Migration
86
86
  def self.up
@@ -98,7 +98,7 @@ module RailsBestPractices
98
98
  expect(runner.errors.size).to eq(0)
99
99
  end
100
100
 
101
- it "should not check ignored files" do
101
+ it 'should not check ignored files' do
102
102
  runner = Core::Runner.new(reviews: IsolateSeedDataReview.new(ignored_files: /create_roles/))
103
103
  content = <<-EOF
104
104
  class CreateRoles < ActiveRecord::Migration
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe KeepFindersOnTheirOwnModelReview do
6
6
  let(:runner) { Core::Runner.new(reviews: KeepFindersOnTheirOwnModelReview.new) }
7
7
 
8
- it "should keep finders on thier own model" do
8
+ it 'should keep finders on thier own model' do
9
9
  content = <<-EOF
10
10
  class Post < ActiveRecord::Base
11
11
  has_many :comments
@@ -18,10 +18,10 @@ module RailsBestPractices
18
18
  EOF
19
19
  runner.review('app/models/post.rb', content)
20
20
  expect(runner.errors.size).to eq(1)
21
- expect(runner.errors[0].to_s).to eq("app/models/post.rb:5 - keep finders on their own model")
21
+ expect(runner.errors[0].to_s).to eq('app/models/post.rb:5 - keep finders on their own model')
22
22
  end
23
23
 
24
- it "should keep finders on thier own model with all method" do
24
+ it 'should keep finders on thier own model with all method' do
25
25
  content = <<-EOF
26
26
  class Post < ActiveRecord::Base
27
27
  has_many :comments
@@ -34,10 +34,10 @@ module RailsBestPractices
34
34
  EOF
35
35
  runner.review('app/models/post.rb', content)
36
36
  expect(runner.errors.size).to eq(1)
37
- expect(runner.errors[0].to_s).to eq("app/models/post.rb:5 - keep finders on their own model")
37
+ expect(runner.errors[0].to_s).to eq('app/models/post.rb:5 - keep finders on their own model')
38
38
  end
39
39
 
40
- it "should not keep finders on thier own model with self finder" do
40
+ it 'should not keep finders on thier own model with self finder' do
41
41
  content = <<-EOF
42
42
  class Post < ActiveRecord::Base
43
43
  has_many :comments
@@ -52,7 +52,7 @@ module RailsBestPractices
52
52
  expect(runner.errors.size).to eq(0)
53
53
  end
54
54
 
55
- it "should not keep finders on thier own model with own finder" do
55
+ it 'should not keep finders on thier own model with own finder' do
56
56
  content = <<-EOF
57
57
  class Post < ActiveRecord::Base
58
58
  has_many :comments
@@ -67,7 +67,7 @@ module RailsBestPractices
67
67
  expect(runner.errors.size).to eq(0)
68
68
  end
69
69
 
70
- it "should not keep finders on their own model without finder" do
70
+ it 'should not keep finders on their own model without finder' do
71
71
  content = <<-EOF
72
72
  class Post < ActiveRecord::Base
73
73
  has_many :comments
@@ -81,7 +81,7 @@ module RailsBestPractices
81
81
  expect(runner.errors.size).to eq(0)
82
82
  end
83
83
 
84
- it "should not keep finders on their own model with ruby Array#find" do
84
+ it 'should not keep finders on their own model with ruby Array#find' do
85
85
  content = <<-EOF
86
86
  class Post < ActiveRecord::Base
87
87
  has_many :comments
@@ -95,7 +95,7 @@ module RailsBestPractices
95
95
  expect(runner.errors.size).to eq(0)
96
96
  end
97
97
 
98
- it "should not check ignored files" do
98
+ it 'should not check ignored files' do
99
99
  runner = Core::Runner.new(reviews: KeepFindersOnTheirOwnModelReview.new(ignored_files: /app\/models\/post\.rb/))
100
100
  content = <<-EOF
101
101
  class Post < ActiveRecord::Base
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe LawOfDemeterReview do
6
6
  let(:runner) { Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new], reviews: LawOfDemeterReview.new) }
7
7
 
8
- describe "belongs_to" do
8
+ describe 'belongs_to' do
9
9
  before(:each) do
10
10
  content = <<-EOF
11
11
  class Invoice < ActiveRecord::Base
@@ -26,7 +26,7 @@ module RailsBestPractices
26
26
  runner.prepare('db/schema.rb', content)
27
27
  end
28
28
 
29
- it "should law of demeter with erb" do
29
+ it 'should law of demeter with erb' do
30
30
  content = <<-EOF
31
31
  <%= @invoice.user.name %>
32
32
  <%= @invoice.user.address %>
@@ -34,10 +34,10 @@ module RailsBestPractices
34
34
  EOF
35
35
  runner.review('app/views/invoices/show.html.erb', content)
36
36
  expect(runner.errors.size).to eq(3)
37
- expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.erb:1 - law of demeter")
37
+ expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.erb:1 - law of demeter')
38
38
  end
39
39
 
40
- it "should law of demeter with haml" do
40
+ it 'should law of demeter with haml' do
41
41
  content = <<-EOF
42
42
  = @invoice.user.name
43
43
  = @invoice.user.address
@@ -45,10 +45,10 @@ module RailsBestPractices
45
45
  EOF
46
46
  runner.review('app/views/invoices/show.html.haml', content)
47
47
  expect(runner.errors.size).to eq(3)
48
- expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.haml:1 - law of demeter")
48
+ expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.haml:1 - law of demeter')
49
49
  end
50
50
 
51
- it "should law of demeter with slim" do
51
+ it 'should law of demeter with slim' do
52
52
  content = <<-EOF
53
53
  = @invoice.user.name
54
54
  = @invoice.user.address
@@ -56,10 +56,10 @@ module RailsBestPractices
56
56
  EOF
57
57
  runner.review('app/views/invoices/show.html.slim', content)
58
58
  expect(runner.errors.size).to eq(3)
59
- expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.slim:1 - law of demeter")
59
+ expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.slim:1 - law of demeter')
60
60
  end
61
61
 
62
- it "should no law of demeter" do
62
+ it 'should no law of demeter' do
63
63
  content = <<-EOF
64
64
  <%= @invoice.user_name %>
65
65
  <%= @invoice.user_address %>
@@ -70,7 +70,7 @@ module RailsBestPractices
70
70
  end
71
71
  end
72
72
 
73
- describe "has_one" do
73
+ describe 'has_one' do
74
74
  before(:each) do
75
75
  content = <<-EOF
76
76
  class Invoice < ActiveRecord::Base
@@ -90,18 +90,18 @@ module RailsBestPractices
90
90
  runner.prepare('db/schema.rb', content)
91
91
  end
92
92
 
93
- it "should law of demeter" do
93
+ it 'should law of demeter' do
94
94
  content = <<-EOF
95
95
  <%= @invoice.price.currency %>
96
96
  <%= @invoice.price.number %>
97
97
  EOF
98
98
  runner.review('app/views/invoices/show.html.erb', content)
99
99
  expect(runner.errors.size).to eq(2)
100
- expect(runner.errors[0].to_s).to eq("app/views/invoices/show.html.erb:1 - law of demeter")
100
+ expect(runner.errors[0].to_s).to eq('app/views/invoices/show.html.erb:1 - law of demeter')
101
101
  end
102
102
  end
103
103
 
104
- context "polymorphic association" do
104
+ context 'polymorphic association' do
105
105
  before :each do
106
106
  content = <<-EOF
107
107
  class Comment < ActiveRecord::Base
@@ -127,17 +127,17 @@ module RailsBestPractices
127
127
  runner.prepare('db/schema.rb', content)
128
128
  end
129
129
 
130
- it "should law of demeter" do
130
+ it 'should law of demeter' do
131
131
  content = <<-EOF
132
132
  <%= @comment.commentable.title %>
133
133
  EOF
134
134
  runner.review('app/views/comments/index.html.erb', content)
135
135
  expect(runner.errors.size).to eq(1)
136
- expect(runner.errors[0].to_s).to eq("app/views/comments/index.html.erb:1 - law of demeter")
136
+ expect(runner.errors[0].to_s).to eq('app/views/comments/index.html.erb:1 - law of demeter')
137
137
  end
138
138
  end
139
139
 
140
- it "should no law of demeter with method call" do
140
+ it 'should no law of demeter with method call' do
141
141
  content = <<-EOF
142
142
  class Question < ActiveRecord::Base
143
143
  has_many :answers, dependent: :destroy
@@ -161,7 +161,7 @@ module RailsBestPractices
161
161
  expect(runner.errors.size).to eq(0)
162
162
  end
163
163
 
164
- it "should not check ignored files" do
164
+ it 'should not check ignored files' do
165
165
  runner = Core::Runner.new(prepares: [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new],
166
166
  reviews: LawOfDemeterReview.new(ignored_files: /app\/views\/invoices/))
167
167
  content = <<-EOF
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe MoveCodeIntoControllerReview do
6
6
  let(:runner) { Core::Runner.new(reviews: MoveCodeIntoControllerReview.new) }
7
7
 
8
- it "should move code into controller for method call" do
8
+ it 'should move code into controller for method call' do
9
9
  content = <<-EOF
10
10
  <% Post.find(:all).each do |post| %>
11
11
  <%=h post.title %>
@@ -14,10 +14,10 @@ module RailsBestPractices
14
14
  EOF
15
15
  runner.review('app/views/posts/index.html.erb', content)
16
16
  expect(runner.errors.size).to eq(1)
17
- expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - move code into controller")
17
+ expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - move code into controller')
18
18
  end
19
19
 
20
- it "should move code into controller for assign" do
20
+ it 'should move code into controller for assign' do
21
21
  content = <<-EOF
22
22
  <% @posts = Post.all %>
23
23
  <% @posts.each do |post| %>
@@ -27,10 +27,10 @@ module RailsBestPractices
27
27
  EOF
28
28
  runner.review('app/views/posts/index.html.erb', content)
29
29
  expect(runner.errors.size).to eq(1)
30
- expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - move code into controller")
30
+ expect(runner.errors[0].to_s).to eq('app/views/posts/index.html.erb:1 - move code into controller')
31
31
  end
32
32
 
33
- it "should not move code into controller" do
33
+ it 'should not move code into controller' do
34
34
  content = <<-EOF
35
35
  <% @posts.each do |post| %>
36
36
  <%=h post.title %>
@@ -41,7 +41,7 @@ module RailsBestPractices
41
41
  expect(runner.errors.size).to eq(0)
42
42
  end
43
43
 
44
- it "should not check ignored files" do
44
+ it 'should not check ignored files' do
45
45
  runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new(ignored_files: /app\/views\/post/))
46
46
  content = <<-EOF
47
47
  <% Post.find(:all).each do |post| %>
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe MoveCodeIntoHelperReview do
6
6
  let(:runner) { Core::Runner.new(reviews: MoveCodeIntoHelperReview.new('array_count' => 2)) }
7
7
 
8
- it "should move code into helper" do
8
+ it 'should move code into helper' do
9
9
  content = <<-EOF
10
10
  <%= select_tag :state, options_for_select( [[t(:draft), "draft"],
11
11
  [t(:published), "published"]],
@@ -13,10 +13,10 @@ module RailsBestPractices
13
13
  EOF
14
14
  runner.review('app/views/posts/show.html.erb', content)
15
15
  expect(runner.errors.size).to eq(1)
16
- expect(runner.errors[0].to_s).to eq("app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)")
16
+ expect(runner.errors[0].to_s).to eq('app/views/posts/show.html.erb:1 - move code into helper (array_count >= 2)')
17
17
  end
18
18
 
19
- it "should not move code into helper with simple arguments" do
19
+ it 'should not move code into helper with simple arguments' do
20
20
  content = <<-EOF
21
21
  <%= select_tag :state, options_for_select( Post.STATES ) %>
22
22
  EOF
@@ -24,7 +24,7 @@ module RailsBestPractices
24
24
  expect(runner.errors.size).to eq(0)
25
25
  end
26
26
 
27
- it "should not check ignored files" do
27
+ it 'should not check ignored files' do
28
28
  runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new('array_count' => 2, 'ignored_files' => /app\/views\/post/))
29
29
  content = <<-EOF
30
30
  <%= select_tag :state, options_for_select( [[t(:draft), "draft"],