rails_best_practices 1.19.2 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.travis.yml +2 -3
  4. data/CHANGELOG.md +7 -7
  5. data/Gemfile +3 -5
  6. data/Gemfile.lock +125 -0
  7. data/Guardfile +2 -0
  8. data/README.md +6 -6
  9. data/Rakefile +2 -17
  10. data/assets/result.html.erb +2 -0
  11. data/lib/rails_best_practices.rb +3 -2
  12. data/lib/rails_best_practices/analyzer.rb +61 -49
  13. data/lib/rails_best_practices/cli.rb +22 -0
  14. data/lib/rails_best_practices/command.rb +1 -131
  15. data/lib/rails_best_practices/core/check.rb +64 -56
  16. data/lib/rails_best_practices/core/checks_loader.rb +24 -23
  17. data/lib/rails_best_practices/core/configs.rb +1 -2
  18. data/lib/rails_best_practices/core/controllers.rb +1 -2
  19. data/lib/rails_best_practices/core/error.rb +1 -1
  20. data/lib/rails_best_practices/core/helpers.rb +1 -2
  21. data/lib/rails_best_practices/core/mailers.rb +1 -2
  22. data/lib/rails_best_practices/core/methods.rb +27 -21
  23. data/lib/rails_best_practices/core/model_associations.rb +10 -5
  24. data/lib/rails_best_practices/core/models.rb +1 -2
  25. data/lib/rails_best_practices/core/modules.rb +1 -1
  26. data/lib/rails_best_practices/core/routes.rb +2 -2
  27. data/lib/rails_best_practices/core/runner.rb +67 -73
  28. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  29. data/lib/rails_best_practices/option_parser.rb +156 -0
  30. data/lib/rails_best_practices/prepares.rb +1 -1
  31. data/lib/rails_best_practices/prepares/controller_prepare.rb +24 -17
  32. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -2
  33. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  34. data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
  35. data/lib/rails_best_practices/prepares/mailer_prepare.rb +2 -1
  36. data/lib/rails_best_practices/prepares/model_prepare.rb +63 -23
  37. data/lib/rails_best_practices/prepares/route_prepare.rb +28 -21
  38. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  39. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +38 -34
  40. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +94 -89
  41. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +15 -5
  42. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +20 -8
  43. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
  44. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
  45. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +16 -16
  46. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +12 -12
  47. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +10 -11
  48. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +25 -24
  49. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +4 -4
  50. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +9 -10
  51. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +10 -11
  52. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +24 -22
  53. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
  54. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  55. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
  56. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +8 -8
  57. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +35 -32
  58. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
  59. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +26 -19
  60. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +12 -10
  61. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +38 -18
  62. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +11 -11
  63. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +77 -74
  64. data/lib/rails_best_practices/reviews/review.rb +2 -1
  65. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -3
  66. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +12 -12
  67. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +18 -15
  68. data/lib/rails_best_practices/reviews/use_model_association_review.rb +15 -15
  69. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +24 -22
  70. data/lib/rails_best_practices/reviews/use_observer_review.rb +28 -28
  71. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
  72. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +68 -66
  73. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -8
  74. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +16 -14
  75. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  76. data/lib/rails_best_practices/version.rb +1 -1
  77. data/rails_best_practices.gemspec +38 -43
  78. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  79. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  80. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  82. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  83. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  84. data/spec/rails_best_practices/core/error_spec.rb +21 -18
  85. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  86. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  87. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  88. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  89. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  90. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  91. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  92. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  93. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  94. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  95. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  96. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  97. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  98. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +32 -31
  99. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  100. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  101. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  102. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  103. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +17 -17
  104. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  105. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  106. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  107. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  108. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +141 -76
  109. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  110. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  111. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  112. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  113. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  114. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  115. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  116. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +13 -13
  117. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  118. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  119. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +29 -22
  120. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  121. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  122. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +32 -22
  123. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  125. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  126. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  127. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  129. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  130. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -17
  131. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  132. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +64 -31
  133. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +21 -14
  134. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +57 -53
  135. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  136. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +20 -14
  137. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  138. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  139. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  140. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  141. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  142. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +35 -31
  143. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  144. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +10 -8
  145. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  146. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  147. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  148. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +61 -59
  149. metadata +16 -18
@@ -5,26 +5,26 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Prepares
7
7
  describe GemfilePrepare do
8
- let(:runner) { Core::Runner.new(prepares: GemfilePrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
10
  context 'gemfile' do
11
- it 'should parse gems' do
12
- content = <<-EOF
13
- GEM
14
- remote: https://rubygems.org/
15
- specs:
16
- rails (3.2.13)
17
- actionmailer (= 3.2.13)
18
- actionpack (= 3.2.13)
19
- activerecord (= 3.2.13)
20
- activeresource (= 3.2.13)
21
- activesupport (= 3.2.13)
22
- bundler (~> 1.0)
23
- railties (= 3.2.13)
24
- mysql2 (0.3.12b6)
11
+ it 'parses gems' do
12
+ content = <<~EOF
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ rails (3.2.13)
17
+ actionmailer (= 3.2.13)
18
+ actionpack (= 3.2.13)
19
+ activerecord (= 3.2.13)
20
+ activeresource (= 3.2.13)
21
+ activesupport (= 3.2.13)
22
+ bundler (~> 1.0)
23
+ railties (= 3.2.13)
24
+ mysql2 (0.3.12b6)
25
25
 
26
- PLATFORMS
27
- ruby
26
+ PLATFORMS
27
+ ruby
28
28
  EOF
29
29
  runner.prepare('Gemfile.lock', content)
30
30
  gems = Prepares.gems
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Prepares
7
7
  describe HelperPrepare do
8
- let(:runner) { Core::Runner.new(prepares: HelperPrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
10
  context 'methods' do
11
- it 'should parse helper methods' do
11
+ it 'parses helper methods' do
12
12
  content = <<-EOF
13
13
  module PostsHelper
14
14
  def used; end
@@ -20,7 +20,7 @@ module RailsBestPractices
20
20
  expect(methods.get_methods('PostsHelper').map(&:method_name)).to eq(%w[used unused])
21
21
  end
22
22
 
23
- it 'should parse helpers' do
23
+ it 'parses helpers' do
24
24
  content = <<-EOF
25
25
  module PostsHelper
26
26
  end
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Prepares
7
7
  describe InitializerPrepare do
8
- let(:runner) { Core::Runner.new(prepares: InitializerPrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
10
  context 'initializers' do
11
- it 'should set include_forbidden_attributes_protection config' do
11
+ it 'sets include_forbidden_attributes_protection config' do
12
12
  content = <<-EOF
13
13
  class AR
14
14
  ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
@@ -19,7 +19,7 @@ module RailsBestPractices
19
19
  expect(configs['railsbp.include_forbidden_attributes_protection']).to eq('true')
20
20
  end
21
21
 
22
- it 'should not set include_forbidden_attributes_protection config' do
22
+ it 'does not set include_forbidden_attributes_protection config' do
23
23
  content = <<-EOF
24
24
  class AR
25
25
  end
@@ -5,9 +5,9 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Prepares
7
7
  describe MailerPrepare do
8
- let(:runner) { Core::Runner.new(prepares: MailerPrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
- it 'should parse mailer names' do
10
+ it 'parses mailer names' do
11
11
  content = <<-EOF
12
12
  class ProjectMailer < ActionMailer::Base
13
13
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Prepares
7
7
  describe ModelPrepare do
8
- let(:runner) { Core::Runner.new(prepares: ModelPrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
10
  context 'models' do
11
11
  it 'class_name with modules ::' do
@@ -32,7 +32,7 @@ module RailsBestPractices
32
32
  end
33
33
 
34
34
  context 'associations' do
35
- it 'should parse model associations' do
35
+ it 'parses model associations' do
36
36
  content = <<-EOF
37
37
  class Project < ActiveRecord::Base
38
38
  belongs_to :portfolio
@@ -43,14 +43,22 @@ module RailsBestPractices
43
43
  EOF
44
44
  runner.prepare('app/models/project.rb', content)
45
45
  model_associations = Prepares.model_associations
46
- expect(model_associations.get_association('Project', 'portfolio')).to eq('meta' => 'belongs_to', 'class_name' => 'Portfolio')
47
- expect(model_associations.get_association('Project', 'project_manager')).to eq('meta' => 'has_one', 'class_name' => 'ProjectManager')
48
- expect(model_associations.get_association('Project', 'milestones')).to eq('meta' => 'has_many', 'class_name' => 'Milestone')
49
- expect(model_associations.get_association('Project', 'categories')).to eq('meta' => 'has_and_belongs_to_many', 'class_name' => 'Category')
46
+ expect(model_associations.get_association('Project', 'portfolio')).to eq(
47
+ 'meta' => 'belongs_to', 'class_name' => 'Portfolio'
48
+ )
49
+ expect(model_associations.get_association('Project', 'project_manager')).to eq(
50
+ 'meta' => 'has_one', 'class_name' => 'ProjectManager'
51
+ )
52
+ expect(model_associations.get_association('Project', 'milestones')).to eq(
53
+ 'meta' => 'has_many', 'class_name' => 'Milestone'
54
+ )
55
+ expect(model_associations.get_association('Project', 'categories')).to eq(
56
+ 'meta' => 'has_and_belongs_to_many', 'class_name' => 'Category'
57
+ )
50
58
  end
51
59
 
52
60
  context 'with class_name option' do
53
- it 'should parse belongs_to' do
61
+ it 'parses belongs_to' do
54
62
  content = <<-EOF
55
63
  class Post < ActiveRecord::Base
56
64
  belongs_to :author, "class_name" => "Person"
@@ -58,10 +66,12 @@ module RailsBestPractices
58
66
  EOF
59
67
  runner.prepare('app/models/post.rb', content)
60
68
  model_associations = Prepares.model_associations
61
- expect(model_associations.get_association('Post', 'author')).to eq('meta' => 'belongs_to', 'class_name' => 'Person')
69
+ expect(model_associations.get_association('Post', 'author')).to eq(
70
+ 'meta' => 'belongs_to', 'class_name' => 'Person'
71
+ )
62
72
  end
63
73
 
64
- it 'should parse has_one' do
74
+ it 'parses has_one' do
65
75
  content = <<-EOF
66
76
  class Project < ActiveRecord::Base
67
77
  has_one :project_manager, "class_name" => "Person"
@@ -69,10 +79,12 @@ module RailsBestPractices
69
79
  EOF
70
80
  runner.prepare('app/models/post.rb', content)
71
81
  model_associations = Prepares.model_associations
72
- expect(model_associations.get_association('Project', 'project_manager')).to eq('meta' => 'has_one', 'class_name' => 'Person')
82
+ expect(model_associations.get_association('Project', 'project_manager')).to eq(
83
+ 'meta' => 'has_one', 'class_name' => 'Person'
84
+ )
73
85
  end
74
86
 
75
- it 'should parse has_many' do
87
+ it 'parses has_many' do
76
88
  content = <<-EOF
77
89
  class Project < ActiveRecord::Base
78
90
  has_many :people, "class_name" => "Person"
@@ -80,10 +92,12 @@ module RailsBestPractices
80
92
  EOF
81
93
  runner.prepare('app/models/project.rb', content)
82
94
  model_associations = Prepares.model_associations
83
- expect(model_associations.get_association('Project', 'people')).to eq('meta' => 'has_many', 'class_name' => 'Person')
95
+ expect(model_associations.get_association('Project', 'people')).to eq(
96
+ 'meta' => 'has_many', 'class_name' => 'Person'
97
+ )
84
98
  end
85
99
 
86
- it 'should parse has_and_belongs_to_many' do
100
+ it 'parses has_and_belongs_to_many' do
87
101
  content = <<-EOF
88
102
  class Citizen < ActiveRecord::Base
89
103
  has_and_belongs_to_many :nations, "class_name" => "Country"
@@ -91,11 +105,13 @@ module RailsBestPractices
91
105
  EOF
92
106
  runner.prepare('app/models/citizen.rb', content)
93
107
  model_associations = Prepares.model_associations
94
- expect(model_associations.get_association('Citizen', 'nations')).to eq('meta' => 'has_and_belongs_to_many', 'class_name' => 'Country')
108
+ expect(model_associations.get_association('Citizen', 'nations')).to eq(
109
+ 'meta' => 'has_and_belongs_to_many', 'class_name' => 'Country'
110
+ )
95
111
  end
96
112
 
97
113
  context 'namespace' do
98
- it 'should parse with namespace' do
114
+ it 'parses with namespace' do
99
115
  content = <<-EOF
100
116
  class Community < ActiveRecord::Base
101
117
  has_many :members
@@ -110,11 +126,15 @@ module RailsBestPractices
110
126
  runner.prepare('app/models/community/member.rb', content)
111
127
  runner.after_prepare
112
128
  model_associations = Prepares.model_associations
113
- expect(model_associations.get_association('Community', 'members')).to eq('meta' => 'has_many', 'class_name' => 'Community::Member')
114
- expect(model_associations.get_association('Community::Member', 'community')).to eq('meta' => 'belongs_to', 'class_name' => 'Community')
129
+ expect(model_associations.get_association('Community', 'members')).to eq(
130
+ 'meta' => 'has_many', 'class_name' => 'Community::Member'
131
+ )
132
+ expect(model_associations.get_association('Community::Member', 'community')).to eq(
133
+ 'meta' => 'belongs_to', 'class_name' => 'Community'
134
+ )
115
135
  end
116
136
 
117
- it 'should parse without namespace' do
137
+ it 'parses without namespace' do
118
138
  content = <<-EOF
119
139
  class Community::Member::Rating < ActiveRecord::Base
120
140
  belongs_to :member
@@ -129,14 +149,18 @@ module RailsBestPractices
129
149
  runner.prepare('app/models/community/member.rb', content)
130
150
  runner.after_prepare
131
151
  model_associations = Prepares.model_associations
132
- expect(model_associations.get_association('Community::Member::Rating', 'member')).to eq('meta' => 'belongs_to', 'class_name' => 'Community::Member')
133
- expect(model_associations.get_association('Community::Member', 'ratings')).to eq('meta' => 'has_many', 'class_name' => 'Community::Member::Rating')
152
+ expect(model_associations.get_association('Community::Member::Rating', 'member')).to eq(
153
+ 'meta' => 'belongs_to', 'class_name' => 'Community::Member'
154
+ )
155
+ expect(model_associations.get_association('Community::Member', 'ratings')).to eq(
156
+ 'meta' => 'has_many', 'class_name' => 'Community::Member::Rating'
157
+ )
134
158
  end
135
159
  end
136
160
  end
137
161
 
138
162
  context 'mongoid embeds' do
139
- it 'should parse embeds_many' do
163
+ it 'parses embeds_many' do
140
164
  content = <<-EOF
141
165
  class Person
142
166
  include Mongoid::Document
@@ -145,10 +169,12 @@ module RailsBestPractices
145
169
  EOF
146
170
  runner.prepare('app/models/person.rb', content)
147
171
  model_associations = Prepares.model_associations
148
- expect(model_associations.get_association('Person', 'addresses')).to eq('meta' => 'embeds_many', 'class_name' => 'Address')
172
+ expect(model_associations.get_association('Person', 'addresses')).to eq(
173
+ 'meta' => 'embeds_many', 'class_name' => 'Address'
174
+ )
149
175
  end
150
176
 
151
- it 'should parse embeds_one' do
177
+ it 'parses embeds_one' do
152
178
  content = <<-EOF
153
179
  class Lush
154
180
  include Mongoid::Document
@@ -157,10 +183,12 @@ module RailsBestPractices
157
183
  EOF
158
184
  runner.prepare('app/models/lush.rb', content)
159
185
  model_associations = Prepares.model_associations
160
- expect(model_associations.get_association('Lush', 'whiskey')).to eq('meta' => 'embeds_one', 'class_name' => 'Drink')
186
+ expect(model_associations.get_association('Lush', 'whiskey')).to eq(
187
+ 'meta' => 'embeds_one', 'class_name' => 'Drink'
188
+ )
161
189
  end
162
190
 
163
- it 'should parse embedded_in' do
191
+ it 'parses embedded_in' do
164
192
  content = <<-EOF
165
193
  class Drink
166
194
  include Mongoid::Document
@@ -169,12 +197,14 @@ module RailsBestPractices
169
197
  EOF
170
198
  runner.prepare('app/models/drink.rb', content)
171
199
  model_associations = Prepares.model_associations
172
- expect(model_associations.get_association('Drink', 'alcoholic')).to eq('meta' => 'embedded_in', 'class_name' => 'Lush')
200
+ expect(model_associations.get_association('Drink', 'alcoholic')).to eq(
201
+ 'meta' => 'embedded_in', 'class_name' => 'Lush'
202
+ )
173
203
  end
174
204
  end
175
205
 
176
206
  context 'mongomapper many/one' do
177
- it 'should parse one' do
207
+ it 'parses one' do
178
208
  content = <<-EOF
179
209
  class Employee
180
210
  include MongoMapper::Document
@@ -183,10 +213,12 @@ module RailsBestPractices
183
213
  EOF
184
214
  runner.prepare('app/models/employee.rb', content)
185
215
  model_associations = Prepares.model_associations
186
- expect(model_associations.get_association('Employee', 'desk')).to eq('meta' => 'one', 'class_name' => 'Desk')
216
+ expect(model_associations.get_association('Employee', 'desk')).to eq(
217
+ 'meta' => 'one', 'class_name' => 'Desk'
218
+ )
187
219
  end
188
220
 
189
- it 'should parse many' do
221
+ it 'parses many' do
190
222
  content = <<-EOF
191
223
  class Tree
192
224
  include MongoMapper::Document
@@ -201,7 +233,7 @@ module RailsBestPractices
201
233
  end
202
234
 
203
235
  context 'methods' do
204
- it 'should parse model methods' do
236
+ it 'parses model methods' do
205
237
  content = <<-EOF
206
238
  class Post < ActiveRecord::Base
207
239
  def save; end
@@ -213,7 +245,7 @@ module RailsBestPractices
213
245
  expect(methods.get_methods('Post').map(&:method_name)).to eq(%w[save find])
214
246
  end
215
247
 
216
- it 'should parse model methods with access control' do
248
+ it 'parses model methods with access control' do
217
249
  content = <<-EOF
218
250
  class Post < ActiveRecord::Base
219
251
  def save; end
@@ -232,7 +264,7 @@ module RailsBestPractices
232
264
  expect(methods.get_methods('Post', 'private').map(&:method_name)).to eq(['find_by_sql'])
233
265
  end
234
266
 
235
- it 'should parse model methods with module ::' do
267
+ it 'parses model methods with module ::' do
236
268
  content = <<-EOF
237
269
  class Admin::Blog::Post < ActiveRecord::Base
238
270
  def save; end
@@ -244,7 +276,7 @@ module RailsBestPractices
244
276
  expect(methods.get_methods('Admin::Blog::Post').map(&:method_name)).to eq(%w[save find])
245
277
  end
246
278
 
247
- it 'should parse model methods with module' do
279
+ it 'parses model methods with module' do
248
280
  content = <<-EOF
249
281
  module Admin
250
282
  module Blog
@@ -260,7 +292,7 @@ module RailsBestPractices
260
292
  expect(methods.get_methods('Admin::Blog::Post').map(&:method_name)).to eq(%w[save find])
261
293
  end
262
294
 
263
- it 'should not add methods from module' do
295
+ it 'does not add methods from module' do
264
296
  content = <<-EOF
265
297
  class Model < ActiveRecord::Base
266
298
  end
@@ -279,7 +311,7 @@ module RailsBestPractices
279
311
  end
280
312
 
281
313
  context 'scope' do
282
- it 'should treat named_scope as method' do
314
+ it 'treats named_scope as method' do
283
315
  content = <<-EOF
284
316
  class Post < ActiveRecord::Base
285
317
  named_scope :active, conditions: {active: true}
@@ -290,7 +322,7 @@ module RailsBestPractices
290
322
  expect(methods.get_methods('Post').map(&:method_name)).to eq(['active'])
291
323
  end
292
324
 
293
- it 'should treat scope as method' do
325
+ it 'treats scope as method' do
294
326
  content = <<-EOF
295
327
  class Post < ActiveRecord::Base
296
328
  scope :active, where(active: true)
@@ -303,7 +335,7 @@ module RailsBestPractices
303
335
  end
304
336
 
305
337
  context 'alias' do
306
- it 'should treat alias as method' do
338
+ it 'treats alias as method' do
307
339
  content = <<-EOF
308
340
  class Post < ActiveRecord::Base
309
341
  alias :new :old
@@ -314,7 +346,7 @@ module RailsBestPractices
314
346
  expect(methods.get_methods('Post').map(&:method_name)).to eq(['new'])
315
347
  end
316
348
 
317
- it 'should treat alias_method as method' do
349
+ it 'treats alias_method as method' do
318
350
  content = <<-EOF
319
351
  class Post < ActiveRecord::Base
320
352
  alias_method :new, :old
@@ -325,7 +357,7 @@ module RailsBestPractices
325
357
  expect(methods.get_methods('Post').map(&:method_name)).to eq(['new'])
326
358
  end
327
359
 
328
- it 'should treat alias_method_chain as method' do
360
+ it 'treats alias_method_chain as method' do
329
361
  content = <<-EOF
330
362
  class Post < ActiveRecord::Base
331
363
  alias_method_chain :method, :feature
@@ -338,7 +370,7 @@ module RailsBestPractices
338
370
  end
339
371
 
340
372
  context 'attributes' do
341
- it 'should parse mongoid field' do
373
+ it 'parses mongoid field' do
342
374
  content = <<-EOF
343
375
  class Post
344
376
  include Mongoid::Document
@@ -358,7 +390,7 @@ module RailsBestPractices
358
390
  expect(model_attributes.get_attribute_type('Post', 'active')).to eq('Boolean')
359
391
  end
360
392
 
361
- it 'should parse mongomapper field' do
393
+ it 'parses mongomapper field' do
362
394
  content = <<-EOF
363
395
  class Post
364
396
  include MongoMapper::Document
@@ -382,13 +414,17 @@ module RailsBestPractices
382
414
  end
383
415
 
384
416
  context 'no error' do
385
- it 'should raised for finder_sql option' do
417
+ it 'raiseds for finder_sql option' do
386
418
  content = <<-EOF
387
419
  class EventSubscription < ActiveRecord::Base
388
420
  has_many :event_notification_template, finder_sql: ?
389
421
  end
390
422
  EOF
391
- content = content.sub('?', '\'SELECT event_notification_templates.* from event_notification_templates where event_type_id=#{event_type_id} and delivery_method_id=#{delivery_method_id}\'')
423
+ content =
424
+ content.sub(
425
+ '?',
426
+ '\'SELECT event_notification_templates.* from event_notification_templates where event_type_id=#{event_type_id} and delivery_method_id=#{delivery_method_id}\''
427
+ )
392
428
  expect { runner.prepare('app/models/event_subscription.rb', content) }.not_to raise_error
393
429
  end
394
430
  end
@@ -5,10 +5,10 @@ require 'spec_helper'
5
5
  module RailsBestPractices
6
6
  module Prepares
7
7
  describe RoutePrepare do
8
- let(:runner) { Core::Runner.new(prepares: RoutePrepare.new) }
8
+ let(:runner) { Core::Runner.new(prepares: described_class.new) }
9
9
 
10
10
  context 'resources' do
11
- it 'should add resources route' do
11
+ it 'adds resources route' do
12
12
  content = <<-EOF
13
13
  RailsBestPracticesCom::Application.routes.draw do
14
14
  resources :posts
@@ -17,10 +17,20 @@ module RailsBestPractices
17
17
  runner.prepare('config/routes.rb', content)
18
18
  routes = Prepares.routes
19
19
  expect(routes.size).to eq(7)
20
- expect(routes.map(&:to_s)).to eq(['PostsController#index', 'PostsController#show', 'PostsController#new', 'PostsController#create', 'PostsController#edit', 'PostsController#update', 'PostsController#destroy'])
21
- end
22
-
23
- it 'should add multiple resources route' do
20
+ expect(routes.map(&:to_s)).to eq(
21
+ [
22
+ 'PostsController#index',
23
+ 'PostsController#show',
24
+ 'PostsController#new',
25
+ 'PostsController#create',
26
+ 'PostsController#edit',
27
+ 'PostsController#update',
28
+ 'PostsController#destroy'
29
+ ]
30
+ )
31
+ end
32
+
33
+ it 'adds multiple resources route' do
24
34
  content = <<-EOF
25
35
  RailsBestPracticesCom::Application.routes.draw do
26
36
  resources :posts, :users
@@ -31,7 +41,7 @@ module RailsBestPractices
31
41
  expect(routes.size).to eq(14)
32
42
  end
33
43
 
34
- it 'should add resources route with explict controller' do
44
+ it 'adds resources route with explict controller' do
35
45
  content = <<-EOF
36
46
  RailsBestPracticesCom::Application.routes.draw do
37
47
  resources :posts, controller: :blog_posts
@@ -40,10 +50,20 @@ module RailsBestPractices
40
50
  runner.prepare('config/routes.rb', content)
41
51
  routes = Prepares.routes
42
52
  expect(routes.size).to eq(7)
43
- expect(routes.map(&:to_s)).to eq(['BlogPostsController#index', 'BlogPostsController#show', 'BlogPostsController#new', 'BlogPostsController#create', 'BlogPostsController#edit', 'BlogPostsController#update', 'BlogPostsController#destroy'])
44
- end
45
-
46
- it 'should add resources route with only option' do
53
+ expect(routes.map(&:to_s)).to eq(
54
+ [
55
+ 'BlogPostsController#index',
56
+ 'BlogPostsController#show',
57
+ 'BlogPostsController#new',
58
+ 'BlogPostsController#create',
59
+ 'BlogPostsController#edit',
60
+ 'BlogPostsController#update',
61
+ 'BlogPostsController#destroy'
62
+ ]
63
+ )
64
+ end
65
+
66
+ it 'adds resources route with only option' do
47
67
  content = <<-EOF
48
68
  RailsBestPracticesCom::Application.routes.draw do
49
69
  resources :posts, only: [:index, :show, :new, :create]
@@ -52,10 +72,12 @@ module RailsBestPractices
52
72
  runner.prepare('config/routes.rb', content)
53
73
  routes = Prepares.routes
54
74
  expect(routes.size).to eq(4)
55
- expect(routes.map(&:to_s)).to eq(['PostsController#index', 'PostsController#show', 'PostsController#new', 'PostsController#create'])
75
+ expect(routes.map(&:to_s)).to eq(
76
+ ['PostsController#index', 'PostsController#show', 'PostsController#new', 'PostsController#create']
77
+ )
56
78
  end
57
79
 
58
- it 'should add resources route with except option' do
80
+ it 'adds resources route with except option' do
59
81
  content = <<-EOF
60
82
  RailsBestPracticesCom::Application.routes.draw do
61
83
  resources :posts, except: [:edit, :update, :destroy]
@@ -64,10 +86,12 @@ module RailsBestPractices
64
86
  runner.prepare('config/routes.rb', content)
65
87
  routes = Prepares.routes
66
88
  expect(routes.size).to eq(4)
67
- expect(routes.map(&:to_s)).to eq(['PostsController#index', 'PostsController#show', 'PostsController#new', 'PostsController#create'])
89
+ expect(routes.map(&:to_s)).to eq(
90
+ ['PostsController#index', 'PostsController#show', 'PostsController#new', 'PostsController#create']
91
+ )
68
92
  end
69
93
 
70
- it 'should not add resources routes with only: :none' do
94
+ it 'does not add resources routes with only: :none' do
71
95
  content = <<-EOF
72
96
  RailsBestPracticesCom::Application.routes.draw do
73
97
  resources :posts, only: :none
@@ -78,7 +102,7 @@ module RailsBestPractices
78
102
  expect(routes.size).to eq(0)
79
103
  end
80
104
 
81
- it 'should not add resources routes with except: :all' do
105
+ it 'does not add resources routes with except: :all' do
82
106
  content = <<-EOF
83
107
  RailsBestPracticesCom::Application.routes.draw do
84
108
  resources :posts, except: :all
@@ -89,7 +113,7 @@ module RailsBestPractices
89
113
  expect(routes.size).to eq(0)
90
114
  end
91
115
 
92
- it 'should add resources routes with members' do
116
+ it 'adds resources routes with members' do
93
117
  content = <<-EOF
94
118
  RailsBestPracticesCom::Application.routes.draw do
95
119
  namespace :admin do
@@ -104,14 +128,17 @@ module RailsBestPractices
104
128
  EOF
105
129
  runner.prepare('config/routes.rb', content)
106
130
  routes = Prepares.routes
107
- expect(routes.map(&:to_s)).to eq([
108
- 'Admin::PostsController#edit',
109
- 'Admin::PostsController#update',
110
- 'Admin::PostsController#link_to_post',
111
- 'Admin::PostsController#extra_update'])
131
+ expect(routes.map(&:to_s)).to eq(
132
+ [
133
+ 'Admin::PostsController#edit',
134
+ 'Admin::PostsController#update',
135
+ 'Admin::PostsController#link_to_post',
136
+ 'Admin::PostsController#extra_update'
137
+ ]
138
+ )
112
139
  end
113
140
 
114
- it 'should add resources routes with members inline' do
141
+ it 'adds resources routes with members inline' do
115
142
  content = <<-EOF
116
143
  RailsBestPracticesCom::Application.routes.draw do
117
144
  namespace :admin do
@@ -123,15 +150,18 @@ module RailsBestPractices
123
150
  EOF
124
151
  runner.prepare('config/routes.rb', content)
125
152
  routes = Prepares.routes
126
- expect(routes.map(&:to_s)).to eq([
127
- 'Admin::PostsController#edit',
128
- 'Admin::PostsController#update',
129
- 'Admin::PostsController#link_to_post',
130
- 'Admin::PostsController#extra_update',
131
- 'Admin::PostsController#retrieve'])
132
- end
133
-
134
- it 'should add connect route' do
153
+ expect(routes.map(&:to_s)).to eq(
154
+ [
155
+ 'Admin::PostsController#edit',
156
+ 'Admin::PostsController#update',
157
+ 'Admin::PostsController#link_to_post',
158
+ 'Admin::PostsController#extra_update',
159
+ 'Admin::PostsController#retrieve'
160
+ ]
161
+ )
162
+ end
163
+
164
+ it 'adds connect route' do
135
165
  content = <<-EOF
136
166
  ActionController::Routing::Routes.draw do |map|
137
167
  map.connect 'vote', controller: "votes", action: "create", method: :post
@@ -142,7 +172,7 @@ module RailsBestPractices
142
172
  expect(routes.map(&:to_s)).to eq(['VotesController#create'])
143
173
  end
144
174
 
145
- it 'should add named route' do
175
+ it 'adds named route' do
146
176
  content = <<-EOF
147
177
  ActionController::Routing::Routes.draw do |map|
148
178
  map.login '/player/login', controller: 'sessions', action: 'new', conditions: { method: :get }
@@ -155,7 +185,7 @@ module RailsBestPractices
155
185
  end
156
186
 
157
187
  context 'resource' do
158
- it 'should add resource route' do
188
+ it 'adds resource route' do
159
189
  content = <<-EOF
160
190
  RailsBestPracticesCom::Application.routes.draw do
161
191
  resource :posts
@@ -164,10 +194,19 @@ module RailsBestPractices
164
194
  runner.prepare('config/routes.rb', content)
165
195
  routes = Prepares.routes
166
196
  expect(routes.size).to eq(6)
167
- expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#new', 'PostsController#create', 'PostsController#edit', 'PostsController#update', 'PostsController#destroy'])
168
- end
169
-
170
- it 'should add multiple resource route' do
197
+ expect(routes.map(&:to_s)).to eq(
198
+ [
199
+ 'PostsController#show',
200
+ 'PostsController#new',
201
+ 'PostsController#create',
202
+ 'PostsController#edit',
203
+ 'PostsController#update',
204
+ 'PostsController#destroy'
205
+ ]
206
+ )
207
+ end
208
+
209
+ it 'adds multiple resource route' do
171
210
  content = <<-EOF
172
211
  RailsBestPracticesCom::Application.routes.draw do
173
212
  resource :posts, :users
@@ -178,7 +217,7 @@ module RailsBestPractices
178
217
  expect(routes.size).to eq(12)
179
218
  end
180
219
 
181
- it 'should add resource route with only option' do
220
+ it 'adds resource route with only option' do
182
221
  content = <<-EOF
183
222
  RailsBestPracticesCom::Application.routes.draw do
184
223
  resource :posts, only: [:show, :new, :create]
@@ -190,7 +229,7 @@ module RailsBestPractices
190
229
  expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#new', 'PostsController#create'])
191
230
  end
192
231
 
193
- it 'should add resource route with except option' do
232
+ it 'adds resource route with except option' do
194
233
  content = <<-EOF
195
234
  RailsBestPracticesCom::Application.routes.draw do
196
235
  resource :posts, except: [:edit, :update, :destroy]
@@ -202,7 +241,7 @@ module RailsBestPractices
202
241
  expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#new', 'PostsController#create'])
203
242
  end
204
243
 
205
- it 'should not add resource routes with only: :none' do
244
+ it 'does not add resource routes with only: :none' do
206
245
  content = <<-EOF
207
246
  RailsBestPracticesCom::Application.routes.draw do
208
247
  resource :posts, only: :none
@@ -213,7 +252,7 @@ module RailsBestPractices
213
252
  expect(routes.size).to eq(0)
214
253
  end
215
254
 
216
- it 'should not add resource routes with except: :all' do
255
+ it 'does not add resource routes with except: :all' do
217
256
  content = <<-EOF
218
257
  RailsBestPracticesCom::Application.routes.draw do
219
258
  resource :posts, except: :all
@@ -224,7 +263,7 @@ module RailsBestPractices
224
263
  expect(routes.size).to eq(0)
225
264
  end
226
265
 
227
- it 'should add resource routes with get/post/put/patch/delete routes' do
266
+ it 'adds resource routes with get/post/put/patch/delete routes' do
228
267
  content = <<-EOF
229
268
  RailsBestPracticesCom::Application.routes.draw do
230
269
  resources :posts, only: [:show] do
@@ -244,13 +283,25 @@ module RailsBestPractices
244
283
  runner.prepare('config/routes.rb', content)
245
284
  routes = Prepares.routes
246
285
  expect(routes.size).to eq(7)
247
- expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#list', 'PostsController#search', 'PostsController#available', 'PostsController#create', 'PostsController#update', 'PostsController#update'])
248
- end
249
-
250
- it 'should add custom resources routes with {}' do
286
+ expect(routes.map(&:to_s)).to eq(
287
+ [
288
+ 'PostsController#show',
289
+ 'PostsController#list',
290
+ 'PostsController#search',
291
+ 'PostsController#available',
292
+ 'PostsController#create',
293
+ 'PostsController#update',
294
+ 'PostsController#update'
295
+ ]
296
+ )
297
+ end
298
+
299
+ it 'adds custom resources routes with {}' do
251
300
  content = <<-EOF
252
301
  RailsBestPracticesCom::Application.routes.draw do
253
- resources :posts, only: [:show] { get :inactive, on: :collection }
302
+ resources :posts, only: [:show] do
303
+ get :inactive, on: :collection
304
+ end
254
305
  end
255
306
  EOF
256
307
  runner.prepare('config/routes.rb', content)
@@ -259,7 +310,7 @@ module RailsBestPractices
259
310
  expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#inactive'])
260
311
  end
261
312
 
262
- it 'should add resources routes with get %w() routes' do
313
+ it 'adds resources routes with get %w() routes' do
263
314
  content = <<-EOF
264
315
  RailsBestPracticesCom::Application.routes.draw do
265
316
  resources :posts, only: [:show] do
@@ -272,10 +323,12 @@ module RailsBestPractices
272
323
  runner.prepare('config/routes.rb', content)
273
324
  routes = Prepares.routes
274
325
  expect(routes.size).to eq(3)
275
- expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#latest', 'PostsController#popular'])
326
+ expect(routes.map(&:to_s)).to eq(
327
+ ['PostsController#show', 'PostsController#latest', 'PostsController#popular']
328
+ )
276
329
  end
277
330
 
278
- it 'should add route with nested routes' do
331
+ it 'adds route with nested routes' do
279
332
  content = <<-EOF
280
333
  RailsBestPracticesCom::Application.routes.draw do
281
334
  resources :posts
@@ -288,7 +341,7 @@ module RailsBestPractices
288
341
  expect(routes.size).to eq(14)
289
342
  end
290
343
 
291
- it 'should add route with namespace' do
344
+ it 'adds route with namespace' do
292
345
  content = <<-EOF
293
346
  RailsBestPracticesCom::Application.routes.draw do
294
347
  namespace :admin do
@@ -303,7 +356,7 @@ module RailsBestPractices
303
356
  expect(routes.map(&:to_s)).to eq(['Admin::Test::PostsController#index'])
304
357
  end
305
358
 
306
- it 'should add route with namespace, but without resources' do
359
+ it 'adds route with namespace, but without resources' do
307
360
  content = <<-EOF
308
361
  RailsBestPracticesCom::Appllication.routes.draw do
309
362
  namespace :something do
@@ -314,10 +367,12 @@ module RailsBestPractices
314
367
  EOF
315
368
  runner.prepare('config/routes.rb', content)
316
369
  routes = Prepares.routes
317
- expect(routes.map(&:to_s)).to eq(['SomethingController#route_one', 'SomethingController#route_two', 'SomethingController#custom_action'])
370
+ expect(routes.map(&:to_s)).to eq(
371
+ ['SomethingController#route_one', 'SomethingController#route_two', 'SomethingController#custom_action']
372
+ )
318
373
  end
319
374
 
320
- it 'should add route with scope' do
375
+ it 'adds route with scope' do
321
376
  content = <<-EOF
322
377
  RailsBestPracticesCom::Application.routes.draw do
323
378
  scope module: "admin" do
@@ -337,17 +392,19 @@ module RailsBestPractices
337
392
  EOF
338
393
  runner.prepare('config/routes.rb', content)
339
394
  routes = Prepares.routes
340
- expect(routes.map(&:to_s)).to eq([
341
- 'Admin::PostsController#index',
342
- 'Admin::DiscussionsController#index',
343
- 'CommentsController#index',
344
- 'UsersController#show',
345
- 'UsersController#preview'
346
- ])
395
+ expect(routes.map(&:to_s)).to eq(
396
+ [
397
+ 'Admin::PostsController#index',
398
+ 'Admin::DiscussionsController#index',
399
+ 'CommentsController#index',
400
+ 'UsersController#show',
401
+ 'UsersController#preview'
402
+ ]
403
+ )
347
404
  end
348
405
  end
349
406
 
350
- it 'should add route for direct get/post' do
407
+ it 'adds route for direct get/post' do
351
408
  content = <<-EOF
352
409
  RailsBestPracticesCom::Application.routes.draw do
353
410
  get 'posts/show'
@@ -360,10 +417,18 @@ module RailsBestPractices
360
417
  runner.prepare('config/routes.rb', content)
361
418
  routes = Prepares.routes
362
419
  expect(routes.size).to eq(5)
363
- expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#create', 'PostsController#update', 'PostsController#destroy', 'HighVoltage::PagesController#show'])
420
+ expect(routes.map(&:to_s)).to eq(
421
+ [
422
+ 'PostsController#show',
423
+ 'PostsController#create',
424
+ 'PostsController#update',
425
+ 'PostsController#destroy',
426
+ 'HighVoltage::PagesController#show'
427
+ ]
428
+ )
364
429
  end
365
430
 
366
- it 'should add routes for another get/post' do
431
+ it 'adds routes for another get/post' do
367
432
  content = <<-EOF
368
433
  RailsBestPracticesCom::Application.routes.draw
369
434
  get "/login", to: 'sessions#new', as: :login
@@ -375,7 +440,7 @@ module RailsBestPractices
375
440
  expect(routes.first.to_s).to eq('SessionsController#new')
376
441
  end
377
442
 
378
- it 'should add match route' do
443
+ it 'adds match route' do
379
444
  content = <<-EOF
380
445
  RailsBestPracticesCom::Application.routes.draw do
381
446
  match '/auth/:provider/callback' => 'authentications#create'
@@ -386,7 +451,7 @@ module RailsBestPractices
386
451
  expect(routes.map(&:to_s)).to eq(['AuthenticationsController#create'])
387
452
  end
388
453
 
389
- it 'should add match route with all actions' do
454
+ it 'adds match route with all actions' do
390
455
  content = <<-EOF
391
456
  RailsBestPracticesCom::Application.routes.draw do
392
457
  match 'internal/:action/*whatever', controller: "internal"
@@ -397,7 +462,7 @@ module RailsBestPractices
397
462
  expect(routes.map(&:to_s)).to eq(['InternalController#*'])
398
463
  end
399
464
 
400
- it 'should add root route' do
465
+ it 'adds root route' do
401
466
  content = <<-EOF
402
467
  RailsBestPracticesCom::Application.routes.draw do
403
468
  root to: 'home#index'
@@ -408,7 +473,7 @@ module RailsBestPractices
408
473
  expect(routes.map(&:to_s)).to eq(['HomeController#index'])
409
474
  end
410
475
 
411
- it 'should add root shortcut route' do
476
+ it 'adds root shortcut route' do
412
477
  content = <<-EOF
413
478
  RailsBestPracticesCom::Application.routes.draw do
414
479
  root 'home#index'
@@ -419,7 +484,7 @@ module RailsBestPractices
419
484
  expect(routes.map(&:to_s)).to eq(['HomeController#index'])
420
485
  end
421
486
 
422
- it 'should do nothing for default route' do
487
+ it 'does nothing for default route' do
423
488
  content = <<-EOF
424
489
  RailsBestPracticesCom::Application.routes.draw do
425
490
  match ':controller(/:action(/:id(.:format)))'
@@ -430,7 +495,7 @@ module RailsBestPractices
430
495
  expect(routes.size).to eq(0)
431
496
  end
432
497
 
433
- it 'should do nothing for redirect' do
498
+ it 'does nothing for redirect' do
434
499
  content = <<-EOF
435
500
  RailsBestPracticesCom::Application.routes.draw do
436
501
  match "/stories/:name" => redirect("/posts/%{name}")
@@ -442,7 +507,7 @@ module RailsBestPractices
442
507
  expect(routes.size).to eq(0)
443
508
  end
444
509
 
445
- it 'should parse customize route in nested resources' do
510
+ it 'parses customize route in nested resources' do
446
511
  content = <<-EOF
447
512
  RailsBestPracticesCom::Application.routes.draw do
448
513
  resources :posts do
@@ -456,7 +521,7 @@ module RailsBestPractices
456
521
  expect(routes.last.to_s).to eq('PostsController#stop')
457
522
  end
458
523
 
459
- it 'should parse custom route for resource with explicit to and different action name' do
524
+ it 'parses custom route for resource with explicit to and different action name' do
460
525
  content = <<-EOF
461
526
  RailsBestPracticesCom::Application.routes.draw do
462
527
  resources :posts do
@@ -469,7 +534,7 @@ module RailsBestPractices
469
534
  expect(routes.last.to_s).to eq('PostsController#stop')
470
535
  end
471
536
 
472
- it 'should parse custom route for resource with symbol action name' do
537
+ it 'parses custom route for resource with symbol action name' do
473
538
  content = <<-EOF
474
539
  RailsBestPracticesCom::Application.routes.draw do
475
540
  resources :posts do
@@ -482,7 +547,7 @@ module RailsBestPractices
482
547
  expect(routes.last.to_s).to eq('PostsController#stop')
483
548
  end
484
549
 
485
- it 'should not take former resources for direct get/post' do
550
+ it 'does not take former resources for direct get/post' do
486
551
  content = <<-EOF
487
552
  RailsBestPracticesCom::Application.routes.draw do
488
553
  resources :posts
@@ -494,7 +559,7 @@ module RailsBestPractices
494
559
  expect(routes.last.to_s).to eq('SprintsController#stop')
495
560
  end
496
561
 
497
- it 'should not parse wrong route' do
562
+ it 'does not parse wrong route' do
498
563
  content = <<-EOF
499
564
  RailsBestPracticesCom::Application.routes.draw do
500
565
  match ':controller/:action' => '#index', as: :auto_complete