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
@@ -6,23 +6,23 @@ module RailsBestPractices::Core
6
6
 
7
7
  let(:gems) { Gems.new }
8
8
  before do
9
- gems << Gem.new("rails", "4.0.0")
10
- gems << Gem.new("mysql2", "0.2.0")
9
+ gems << Gem.new('rails', '4.0.0')
10
+ gems << Gem.new('mysql2', '0.2.0')
11
11
  end
12
12
 
13
- context "#has_gem?" do
14
- it "has rails gem" do
15
- expect(gems).to be_has_gem "rails"
13
+ context '#has_gem?' do
14
+ it 'has rails gem' do
15
+ expect(gems).to be_has_gem 'rails'
16
16
  end
17
17
 
18
18
  it "hasn't sinatra gem" do
19
- expect(gems).not_to be_has_gem "sinatra"
19
+ expect(gems).not_to be_has_gem 'sinatra'
20
20
  end
21
21
  end
22
22
 
23
- context "#gem_version" do
24
- it "gets rails version" do
25
- expect(gems.gem_version("rails")).to eq "4.0.0"
23
+ context '#gem_version' do
24
+ it 'gets rails version' do
25
+ expect(gems.gem_version('rails')).to eq '4.0.0'
26
26
  end
27
27
  end
28
28
  end
@@ -4,33 +4,33 @@ module RailsBestPractices::Core
4
4
  describe Klasses do
5
5
  it { should be_a_kind_of Array }
6
6
 
7
- context "Klass" do
8
- context "#class_name" do
9
- it "gets class name without module" do
10
- klass = Klass.new("BlogPost", "Post", [])
11
- expect(klass.class_name).to eq("BlogPost")
7
+ context 'Klass' do
8
+ context '#class_name' do
9
+ it 'gets class name without module' do
10
+ klass = Klass.new('BlogPost', 'Post', [])
11
+ expect(klass.class_name).to eq('BlogPost')
12
12
  end
13
13
 
14
- it "gets class name with moduel" do
15
- klass = Klass.new("BlogPost", "Post", ["Admin"])
16
- expect(klass.class_name).to eq("Admin::BlogPost")
14
+ it 'gets class name with moduel' do
15
+ klass = Klass.new('BlogPost', 'Post', ['Admin'])
16
+ expect(klass.class_name).to eq('Admin::BlogPost')
17
17
  end
18
18
  end
19
19
 
20
- context "#extend_class_name" do
21
- it "gets extend class name without module" do
22
- klass = Klass.new("BlogPost", "Post", [])
23
- expect(klass.extend_class_name).to eq("Post")
20
+ context '#extend_class_name' do
21
+ it 'gets extend class name without module' do
22
+ klass = Klass.new('BlogPost', 'Post', [])
23
+ expect(klass.extend_class_name).to eq('Post')
24
24
  end
25
25
 
26
- it "gets extend class name with module" do
27
- klass = Klass.new("BlogPost", "Post", ["Admin"])
28
- expect(klass.extend_class_name).to eq("Admin::Post")
26
+ it 'gets extend class name with module' do
27
+ klass = Klass.new('BlogPost', 'Post', ['Admin'])
28
+ expect(klass.extend_class_name).to eq('Admin::Post')
29
29
  end
30
30
  end
31
31
 
32
- it "gets to_s equal to class_name" do
33
- klass = Klass.new("BlogPost", "Post", ["Admin"])
32
+ it 'gets to_s equal to class_name' do
33
+ klass = Klass.new('BlogPost', 'Post', ['Admin'])
34
34
  expect(klass.to_s).to eq(klass.class_name)
35
35
  end
36
36
  end
@@ -5,42 +5,42 @@ module RailsBestPractices::Core
5
5
  let(:methods) { Methods.new }
6
6
 
7
7
  before :each do
8
- methods.add_method("Post", "create")
9
- methods.add_method("Post", "destroy")
10
- methods.add_method("Post", "save_or_update", {}, "protected")
11
- methods.add_method("Post", "find_by_sql", {}, "private")
12
- methods.add_method("Comment", "create")
8
+ methods.add_method('Post', 'create')
9
+ methods.add_method('Post', 'destroy')
10
+ methods.add_method('Post', 'save_or_update', {}, 'protected')
11
+ methods.add_method('Post', 'find_by_sql', {}, 'private')
12
+ methods.add_method('Comment', 'create')
13
13
  end
14
14
 
15
- 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", "protected").map(&:method_name)).to eq(["save_or_update"])
19
- expect(methods.get_methods("Post", "private").map(&:method_name)).to eq(["find_by_sql"])
20
- expect(methods.get_methods("Comment").map(&:method_name)).to eq(["create"])
15
+ 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', 'protected').map(&:method_name)).to eq(['save_or_update'])
19
+ expect(methods.get_methods('Post', 'private').map(&:method_name)).to eq(['find_by_sql'])
20
+ expect(methods.get_methods('Comment').map(&:method_name)).to eq(['create'])
21
21
  end
22
22
 
23
- it "should has_method?" do
24
- expect(methods).to be_has_method("Post", "create", "public")
25
- expect(methods).to be_has_method("Post", "destroy", "public")
26
- expect(methods).not_to be_has_method("Post", "save_or_update", "public")
27
- expect(methods).to be_has_method("Post", "save_or_update", "protected")
28
- expect(methods).not_to be_has_method("Post", "find_by_sql", "public")
29
- expect(methods).to be_has_method("Post", "find_by_sql", "private")
30
- expect(methods).not_to be_has_method("Comment", "destroy")
23
+ it 'should has_method?' do
24
+ expect(methods).to be_has_method('Post', 'create', 'public')
25
+ expect(methods).to be_has_method('Post', 'destroy', 'public')
26
+ expect(methods).not_to be_has_method('Post', 'save_or_update', 'public')
27
+ expect(methods).to be_has_method('Post', 'save_or_update', 'protected')
28
+ expect(methods).not_to be_has_method('Post', 'find_by_sql', 'public')
29
+ expect(methods).to be_has_method('Post', 'find_by_sql', 'private')
30
+ expect(methods).not_to be_has_method('Comment', 'destroy')
31
31
  end
32
32
 
33
- it "should get_method" do
34
- expect(methods.get_method("Post", "create", "public")).not_to be_nil
35
- expect(methods.get_method("Post", "create", "protected")).to be_nil
33
+ it 'should get_method' do
34
+ expect(methods.get_method('Post', 'create', 'public')).not_to be_nil
35
+ expect(methods.get_method('Post', 'create', 'protected')).to be_nil
36
36
  end
37
37
 
38
- it "should get_all_unused_methods" do
39
- methods.get_method("Comment", "create").mark_used
40
- expect(methods.get_all_unused_methods("public").map(&:method_name)).to eq(["create", "destroy"])
41
- expect(methods.get_all_unused_methods("protected").map(&:method_name)).to eq(["save_or_update"])
42
- 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"])
38
+ it 'should get_all_unused_methods' do
39
+ methods.get_method('Comment', 'create').mark_used
40
+ expect(methods.get_all_unused_methods('public').map(&:method_name)).to eq(['create', 'destroy'])
41
+ expect(methods.get_all_unused_methods('protected').map(&:method_name)).to eq(['save_or_update'])
42
+ 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'])
44
44
  end
45
45
  end
46
46
  end
@@ -5,20 +5,20 @@ module RailsBestPractices::Core
5
5
  let(:model_associations) { ModelAssociations.new }
6
6
 
7
7
  before :each do
8
- model_associations.add_association("Project", "project_manager", "belongs_to")
9
- model_associations.add_association("Project", "people", "has_many", "Person")
8
+ model_associations.add_association('Project', 'project_manager', 'belongs_to')
9
+ model_associations.add_association('Project', 'people', 'has_many', 'Person')
10
10
  end
11
11
 
12
- 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", "unknown")).to be_nil
12
+ 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', 'unknown')).to be_nil
16
16
  end
17
17
 
18
- it "should check is model associatiosn" do
19
- expect(model_associations.is_association?("Project", "project_manager")).to eq true
20
- expect(model_associations.is_association?("Project", "people")).to eq true
21
- expect(model_associations.is_association?("Project", "unknown")).to eq false
18
+ it 'should check is model associatiosn' do
19
+ expect(model_associations.is_association?('Project', 'project_manager')).to eq true
20
+ expect(model_associations.is_association?('Project', 'people')).to eq true
21
+ expect(model_associations.is_association?('Project', 'unknown')).to eq false
22
22
  end
23
23
  end
24
24
  end
@@ -5,20 +5,20 @@ module RailsBestPractices::Core
5
5
  let(:model_attributes) { ModelAttributes.new }
6
6
 
7
7
  before :each do
8
- model_attributes.add_attribute("Post", "title", :string)
9
- model_attributes.add_attribute("Post", "user_id", :integer)
8
+ model_attributes.add_attribute('Post', 'title', :string)
9
+ model_attributes.add_attribute('Post', 'user_id', :integer)
10
10
  end
11
11
 
12
- it "should get model attributes" do
13
- expect(model_attributes.get_attribute_type("Post", "title")).to eq(:string)
14
- expect(model_attributes.get_attribute_type("Post", "user_id")).to eq(:integer)
15
- expect(model_attributes.get_attribute_type("Post", "unknonw")).to be_nil
12
+ it 'should get model attributes' do
13
+ expect(model_attributes.get_attribute_type('Post', 'title')).to eq(:string)
14
+ expect(model_attributes.get_attribute_type('Post', 'user_id')).to eq(:integer)
15
+ expect(model_attributes.get_attribute_type('Post', 'unknonw')).to be_nil
16
16
  end
17
17
 
18
- it "should check is model attributes" do
19
- expect(model_attributes.is_attribute?("Post", "title")).to be true
20
- expect(model_attributes.is_attribute?("Post", "user_id")).to be true
21
- expect(model_attributes.is_attribute?("Post", "unknonw")).to be false
18
+ it 'should check is model attributes' do
19
+ expect(model_attributes.is_attribute?('Post', 'title')).to be true
20
+ expect(model_attributes.is_attribute?('Post', 'user_id')).to be true
21
+ expect(model_attributes.is_attribute?('Post', 'unknonw')).to be false
22
22
  end
23
23
  end
24
24
  end
@@ -4,25 +4,25 @@ module RailsBestPractices::Core
4
4
  describe Modules do
5
5
  it { should be_a_kind_of Array }
6
6
 
7
- context "Modules" do
7
+ context 'Modules' do
8
8
  before do
9
- @mod = Mod.new("PostsHelper", [])
9
+ @mod = Mod.new('PostsHelper', [])
10
10
  end
11
11
  subject { Modules.new.tap { |modules| modules << @mod } }
12
- it "should add descendant to the corresponding module" do
13
- expect(@mod).to receive(:add_descendant).with("PostsController")
14
- subject.add_module_descendant("PostsHelper", "PostsController")
12
+ it 'should add descendant to the corresponding module' do
13
+ expect(@mod).to receive(:add_descendant).with('PostsController')
14
+ subject.add_module_descendant('PostsHelper', 'PostsController')
15
15
  end
16
16
  end
17
17
 
18
- context "Mod" do
18
+ context 'Mod' do
19
19
  subject {
20
- Mod.new("UsersHelper", ["Admin"]).tap do |mod|
21
- mod.add_descendant("Admin::UsersController")
20
+ Mod.new('UsersHelper', ['Admin']).tap do |mod|
21
+ mod.add_descendant('Admin::UsersController')
22
22
  end
23
23
  }
24
- it { expect(subject.to_s).to eq("Admin::UsersHelper") }
25
- it { expect(subject.descendants).to eq(["Admin::UsersController"]) }
24
+ it { expect(subject.to_s).to eq('Admin::UsersHelper') }
25
+ it { expect(subject.descendants).to eq(['Admin::UsersController']) }
26
26
  end
27
27
  end
28
28
  end
@@ -4,25 +4,25 @@ module RailsBestPractices::Core
4
4
  describe Routes do
5
5
  let(:routes) { Routes.new }
6
6
 
7
- it "should add route" do
8
- routes.add_route(["admin", "test"], "posts", "new")
9
- expect(routes.map(&:to_s)).to eq(["Admin::Test::PostsController#new"])
7
+ it 'should add route' do
8
+ routes.add_route(['admin', 'test'], 'posts', 'new')
9
+ expect(routes.map(&:to_s)).to eq(['Admin::Test::PostsController#new'])
10
10
  end
11
11
 
12
- context "route" do
13
- it "should add namesapces, controller name and action name" do
12
+ context 'route' do
13
+ it 'should add namesapces, controller name and action name' do
14
14
  route = Route.new(['admin', 'test'], 'posts', 'new')
15
- expect(route.to_s).to eq("Admin::Test::PostsController#new")
15
+ expect(route.to_s).to eq('Admin::Test::PostsController#new')
16
16
  end
17
17
 
18
- it "should add controller name with namespace" do
18
+ it 'should add controller name with namespace' do
19
19
  route = Route.new(['admin'], 'test/posts', 'new')
20
- expect(route.to_s).to eq("Admin::Test::PostsController#new")
20
+ expect(route.to_s).to eq('Admin::Test::PostsController#new')
21
21
  end
22
22
 
23
- it "should add routes without controller" do
23
+ it 'should add routes without controller' do
24
24
  route = Route.new(['posts'], nil, 'new')
25
- expect(route.to_s).to eq("PostsController#new")
25
+ expect(route.to_s).to eq('PostsController#new')
26
26
  end
27
27
  end
28
28
  end
@@ -2,20 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  module RailsBestPractices::Core
4
4
  describe Runner do
5
- describe "load_plugin_reviews" do
5
+ describe 'load_plugin_reviews' do
6
6
  shared_examples_for 'load_plugin_reviews' do
7
- it "should load plugins in lib/rails_best_practices/plugins/reviews" do
7
+ it 'should load plugins in lib/rails_best_practices/plugins/reviews' do
8
8
  runner = Runner.new
9
9
  expect(runner.instance_variable_get('@reviews').map(&:class)).to include(RailsBestPractices::Plugins::Reviews::NotUseRailsRootReview)
10
10
  end
11
11
  end
12
12
 
13
- context "given a path that ends with a slash" do
13
+ context 'given a path that ends with a slash' do
14
14
  before { Runner.base_path = 'spec/fixtures/' }
15
15
  it_should_behave_like 'load_plugin_reviews'
16
16
  end
17
17
 
18
- context "given a path that does not end with a slash" do
18
+ context 'given a path that does not end with a slash' do
19
19
  before { Runner.base_path = 'spec/fixtures' }
20
20
  it_should_behave_like 'load_plugin_reviews'
21
21
  end
@@ -14,11 +14,11 @@ describe Erubis::OnlyRuby do
14
14
  Erubis::OnlyRuby.new(content).src
15
15
  }
16
16
 
17
- it { should_not include("h1") }
18
- it { should_not include("Title") }
19
- it { should_not include("Not logged in") }
20
- it { should include("current_user") }
21
- it { should include("if") }
22
- it { should include("else") }
23
- it { should include("end") }
17
+ it { should_not include('h1') }
18
+ it { should_not include('Title') }
19
+ it { should_not include('Not logged in') }
20
+ it { should include('current_user') }
21
+ it { should include('if') }
22
+ it { should include('else') }
23
+ it { should include('end') }
24
24
  end
@@ -4,7 +4,7 @@ module RailsBestPractices
4
4
  module Lexicals
5
5
  describe LongLineCheck do
6
6
 
7
- it "should find long lines" do
7
+ it 'should find long lines' do
8
8
  runner = Core::Runner.new(lexicals: LongLineCheck.new)
9
9
  content =<<-EOF
10
10
  class User < ActiveRecord::Base
@@ -17,10 +17,10 @@ EOF
17
17
  content.gsub!("\n", "\t\n")
18
18
  runner.lexical('app/models/user.rb', content)
19
19
  expect(runner.errors.size).to eq(1)
20
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:3 - line is longer than 80 characters (81 characters)")
20
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - line is longer than 80 characters (81 characters)')
21
21
  end
22
- it "should find long lines with own max size" do
23
- runner = Core::Runner.new(lexicals: LongLineCheck.new("max_line_length" => 90))
22
+ it 'should find long lines with own max size' do
23
+ runner = Core::Runner.new(lexicals: LongLineCheck.new('max_line_length' => 90))
24
24
  content =<<-EOF
25
25
  class User < ActiveRecord::Base
26
26
  # 91 Chars
@@ -32,9 +32,9 @@ EOF
32
32
  content.gsub!("\n", "\t\n")
33
33
  runner.lexical('app/models/user.rb', content)
34
34
  expect(runner.errors.size).to eq(1)
35
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:3 - line is longer than 90 characters (91 characters)")
35
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - line is longer than 90 characters (91 characters)')
36
36
  end
37
- it "should not check non .rb files" do
37
+ it 'should not check non .rb files' do
38
38
  runner = Core::Runner.new(lexicals: LongLineCheck.new)
39
39
  content = "
40
40
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -42,7 +42,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
42
42
  runner.lexical('app/views/users/index.html.erb', content)
43
43
  expect(runner.errors.size).to eq(0)
44
44
  end
45
- it "should not check ignored files" do
45
+ it 'should not check ignored files' do
46
46
  runner = Core::Runner.new(lexicals: LongLineCheck.new(max_line_length: 80, ignored_files: /user/))
47
47
  content =<<-EOF
48
48
  class User < ActiveRecord::Base
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe RemoveTabCheck do
6
6
  let(:runner) { Core::Runner.new(lexicals: RemoveTabCheck.new) }
7
7
 
8
- it "should remove tab" do
8
+ it 'should remove tab' do
9
9
  content =<<-EOF
10
10
  class User < ActiveRecord::Base
11
11
  has_many :projects
@@ -14,10 +14,10 @@ module RailsBestPractices
14
14
  content.gsub!("\n", "\t\n")
15
15
  runner.lexical('app/models/user.rb', content)
16
16
  expect(runner.errors.size).to eq(1)
17
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:1 - remove tab, use spaces instead")
17
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:1 - remove tab, use spaces instead')
18
18
  end
19
19
 
20
- it "should remove tab with third line" do
20
+ it 'should remove tab with third line' do
21
21
  content =<<-EOF
22
22
  class User < ActiveRecord::Base
23
23
  has_many :projects
@@ -26,10 +26,10 @@ module RailsBestPractices
26
26
  EOF
27
27
  runner.lexical('app/models/user.rb', content)
28
28
  expect(runner.errors.size).to eq(1)
29
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:3 - remove tab, use spaces instead")
29
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - remove tab, use spaces instead')
30
30
  end
31
31
 
32
- it "should not remove trailing whitespace" do
32
+ it 'should not remove trailing whitespace' do
33
33
  content =<<-EOF
34
34
  class User < ActiveRecord::Base
35
35
  has_many :projects
@@ -38,7 +38,7 @@ module RailsBestPractices
38
38
  runner.lexical('app/models/user.rb', content)
39
39
  expect(runner.errors.size).to eq(0)
40
40
  end
41
- it "should not check ignored files" do
41
+ it 'should not check ignored files' do
42
42
  runner = Core::Runner.new(lexicals: RemoveTabCheck.new(ignored_files: /user/))
43
43
  content =<<-EOF
44
44
  class User < ActiveRecord::Base
@@ -5,7 +5,7 @@ module RailsBestPractices
5
5
  describe RemoveTrailingWhitespaceCheck do
6
6
  let(:runner) { Core::Runner.new(lexicals: RemoveTrailingWhitespaceCheck.new) }
7
7
 
8
- it "should remove trailing whitespace" do
8
+ it 'should remove trailing whitespace' do
9
9
  content =<<-EOF
10
10
  class User < ActiveRecord::Base
11
11
  has_many :projects
@@ -14,10 +14,10 @@ module RailsBestPractices
14
14
  content.gsub!("\n", " \n")
15
15
  runner.lexical('app/models/user.rb', content)
16
16
  expect(runner.errors.size).to eq(1)
17
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:1 - remove trailing whitespace")
17
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:1 - remove trailing whitespace')
18
18
  end
19
19
 
20
- it "should remove whitespace with third line" do
20
+ it 'should remove whitespace with third line' do
21
21
  content =<<-EOF
22
22
  class User < ActiveRecord::Base
23
23
  has_many :projects
@@ -26,10 +26,10 @@ module RailsBestPractices
26
26
  content.gsub!("d\n", "d \n")
27
27
  runner.lexical('app/models/user.rb', content)
28
28
  expect(runner.errors.size).to eq(1)
29
- expect(runner.errors[0].to_s).to eq("app/models/user.rb:3 - remove trailing whitespace")
29
+ expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - remove trailing whitespace')
30
30
  end
31
31
 
32
- it "should not remove trailing whitespace" do
32
+ it 'should not remove trailing whitespace' do
33
33
  content =<<-EOF
34
34
  class User < ActiveRecord::Base
35
35
  has_many :projects
@@ -39,7 +39,7 @@ module RailsBestPractices
39
39
  expect(runner.errors.size).to eq(0)
40
40
  end
41
41
 
42
- it "should not check ignored files" do
42
+ it 'should not check ignored files' do
43
43
  runner = Core::Runner.new(lexicals: RemoveTrailingWhitespaceCheck.new(ignored_files: /user/))
44
44
  content =<<-EOF
45
45
  class User < ActiveRecord::Base