rails_best_practices 1.20.0 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +30 -26
  4. data/Guardfile +2 -0
  5. data/Rakefile +2 -0
  6. data/lib/rails_best_practices.rb +1 -2
  7. data/lib/rails_best_practices/analyzer.rb +56 -46
  8. data/lib/rails_best_practices/core/check.rb +39 -32
  9. data/lib/rails_best_practices/core/checks_loader.rb +8 -6
  10. data/lib/rails_best_practices/core/configs.rb +1 -2
  11. data/lib/rails_best_practices/core/controllers.rb +1 -2
  12. data/lib/rails_best_practices/core/error.rb +1 -1
  13. data/lib/rails_best_practices/core/helpers.rb +1 -2
  14. data/lib/rails_best_practices/core/mailers.rb +1 -2
  15. data/lib/rails_best_practices/core/methods.rb +21 -16
  16. data/lib/rails_best_practices/core/model_associations.rb +9 -4
  17. data/lib/rails_best_practices/core/models.rb +1 -2
  18. data/lib/rails_best_practices/core/modules.rb +1 -1
  19. data/lib/rails_best_practices/core/routes.rb +2 -2
  20. data/lib/rails_best_practices/core/runner.rb +29 -33
  21. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  22. data/lib/rails_best_practices/option_parser.rb +17 -6
  23. data/lib/rails_best_practices/prepares.rb +1 -1
  24. data/lib/rails_best_practices/prepares/controller_prepare.rb +15 -3
  25. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
  26. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  27. data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -2
  28. data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -0
  29. data/lib/rails_best_practices/prepares/model_prepare.rb +52 -12
  30. data/lib/rails_best_practices/prepares/route_prepare.rb +16 -10
  31. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +15 -13
  32. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +34 -29
  33. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +14 -5
  34. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +19 -8
  35. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +5 -5
  36. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +4 -4
  37. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +7 -8
  38. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +6 -6
  39. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +1 -1
  40. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +6 -7
  41. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +7 -8
  42. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +12 -10
  43. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  44. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +5 -5
  45. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +5 -2
  46. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +6 -3
  47. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -4
  48. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +29 -9
  49. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +3 -3
  50. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +17 -15
  51. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -2
  52. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -3
  53. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -1
  54. data/lib/rails_best_practices/reviews/use_model_association_review.rb +5 -5
  55. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +9 -8
  56. data/lib/rails_best_practices/reviews/use_observer_review.rb +9 -9
  57. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +26 -26
  58. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +8 -7
  59. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +17 -15
  60. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  61. data/lib/rails_best_practices/version.rb +1 -1
  62. data/rails_best_practices.gemspec +35 -36
  63. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  64. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  65. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  66. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  67. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  68. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  69. data/spec/rails_best_practices/core/error_spec.rb +21 -21
  70. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  71. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  72. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  73. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  74. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  75. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  76. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  77. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  78. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  79. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  80. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  82. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  83. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +11 -10
  84. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  85. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  86. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  87. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  88. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +2 -2
  89. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  90. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  91. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  92. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  93. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +138 -77
  94. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  95. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  96. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  97. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  98. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  99. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  100. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  101. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -9
  102. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  103. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  104. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +21 -14
  105. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  106. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  107. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +26 -16
  108. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  109. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  110. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  111. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  112. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  113. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  114. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  115. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -19
  116. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  117. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +44 -31
  118. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +17 -12
  119. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +46 -44
  120. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  121. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +16 -10
  122. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  123. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  124. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  125. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  126. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  127. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +21 -17
  128. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  129. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +9 -7
  130. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  131. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  132. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  133. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +10 -8
  134. metadata +7 -7
@@ -5,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,15 +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'
112
- ])
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
+ )
113
139
  end
114
140
 
115
- it 'should add resources routes with members inline' do
141
+ it 'adds resources routes with members inline' do
116
142
  content = <<-EOF
117
143
  RailsBestPracticesCom::Application.routes.draw do
118
144
  namespace :admin do
@@ -124,16 +150,18 @@ module RailsBestPractices
124
150
  EOF
125
151
  runner.prepare('config/routes.rb', content)
126
152
  routes = Prepares.routes
127
- expect(routes.map(&:to_s)).to eq([
128
- 'Admin::PostsController#edit',
129
- 'Admin::PostsController#update',
130
- 'Admin::PostsController#link_to_post',
131
- 'Admin::PostsController#extra_update',
132
- 'Admin::PostsController#retrieve'
133
- ])
134
- end
135
-
136
- 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
137
165
  content = <<-EOF
138
166
  ActionController::Routing::Routes.draw do |map|
139
167
  map.connect 'vote', controller: "votes", action: "create", method: :post
@@ -144,7 +172,7 @@ module RailsBestPractices
144
172
  expect(routes.map(&:to_s)).to eq(['VotesController#create'])
145
173
  end
146
174
 
147
- it 'should add named route' do
175
+ it 'adds named route' do
148
176
  content = <<-EOF
149
177
  ActionController::Routing::Routes.draw do |map|
150
178
  map.login '/player/login', controller: 'sessions', action: 'new', conditions: { method: :get }
@@ -157,7 +185,7 @@ module RailsBestPractices
157
185
  end
158
186
 
159
187
  context 'resource' do
160
- it 'should add resource route' do
188
+ it 'adds resource route' do
161
189
  content = <<-EOF
162
190
  RailsBestPracticesCom::Application.routes.draw do
163
191
  resource :posts
@@ -166,10 +194,19 @@ module RailsBestPractices
166
194
  runner.prepare('config/routes.rb', content)
167
195
  routes = Prepares.routes
168
196
  expect(routes.size).to eq(6)
169
- expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#new', 'PostsController#create', 'PostsController#edit', 'PostsController#update', 'PostsController#destroy'])
170
- end
171
-
172
- 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
173
210
  content = <<-EOF
174
211
  RailsBestPracticesCom::Application.routes.draw do
175
212
  resource :posts, :users
@@ -180,7 +217,7 @@ module RailsBestPractices
180
217
  expect(routes.size).to eq(12)
181
218
  end
182
219
 
183
- it 'should add resource route with only option' do
220
+ it 'adds resource route with only option' do
184
221
  content = <<-EOF
185
222
  RailsBestPracticesCom::Application.routes.draw do
186
223
  resource :posts, only: [:show, :new, :create]
@@ -192,7 +229,7 @@ module RailsBestPractices
192
229
  expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#new', 'PostsController#create'])
193
230
  end
194
231
 
195
- it 'should add resource route with except option' do
232
+ it 'adds resource route with except option' do
196
233
  content = <<-EOF
197
234
  RailsBestPracticesCom::Application.routes.draw do
198
235
  resource :posts, except: [:edit, :update, :destroy]
@@ -204,7 +241,7 @@ module RailsBestPractices
204
241
  expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#new', 'PostsController#create'])
205
242
  end
206
243
 
207
- it 'should not add resource routes with only: :none' do
244
+ it 'does not add resource routes with only: :none' do
208
245
  content = <<-EOF
209
246
  RailsBestPracticesCom::Application.routes.draw do
210
247
  resource :posts, only: :none
@@ -215,7 +252,7 @@ module RailsBestPractices
215
252
  expect(routes.size).to eq(0)
216
253
  end
217
254
 
218
- it 'should not add resource routes with except: :all' do
255
+ it 'does not add resource routes with except: :all' do
219
256
  content = <<-EOF
220
257
  RailsBestPracticesCom::Application.routes.draw do
221
258
  resource :posts, except: :all
@@ -226,7 +263,7 @@ module RailsBestPractices
226
263
  expect(routes.size).to eq(0)
227
264
  end
228
265
 
229
- 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
230
267
  content = <<-EOF
231
268
  RailsBestPracticesCom::Application.routes.draw do
232
269
  resources :posts, only: [:show] do
@@ -246,10 +283,20 @@ module RailsBestPractices
246
283
  runner.prepare('config/routes.rb', content)
247
284
  routes = Prepares.routes
248
285
  expect(routes.size).to eq(7)
249
- expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#list', 'PostsController#search', 'PostsController#available', 'PostsController#create', 'PostsController#update', 'PostsController#update'])
250
- end
251
-
252
- 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
253
300
  content = <<-EOF
254
301
  RailsBestPracticesCom::Application.routes.draw do
255
302
  resources :posts, only: [:show] do
@@ -263,7 +310,7 @@ module RailsBestPractices
263
310
  expect(routes.map(&:to_s)).to eq(['PostsController#show', 'PostsController#inactive'])
264
311
  end
265
312
 
266
- it 'should add resources routes with get %w() routes' do
313
+ it 'adds resources routes with get %w() routes' do
267
314
  content = <<-EOF
268
315
  RailsBestPracticesCom::Application.routes.draw do
269
316
  resources :posts, only: [:show] do
@@ -276,10 +323,12 @@ module RailsBestPractices
276
323
  runner.prepare('config/routes.rb', content)
277
324
  routes = Prepares.routes
278
325
  expect(routes.size).to eq(3)
279
- 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
+ )
280
329
  end
281
330
 
282
- it 'should add route with nested routes' do
331
+ it 'adds route with nested routes' do
283
332
  content = <<-EOF
284
333
  RailsBestPracticesCom::Application.routes.draw do
285
334
  resources :posts
@@ -292,7 +341,7 @@ module RailsBestPractices
292
341
  expect(routes.size).to eq(14)
293
342
  end
294
343
 
295
- it 'should add route with namespace' do
344
+ it 'adds route with namespace' do
296
345
  content = <<-EOF
297
346
  RailsBestPracticesCom::Application.routes.draw do
298
347
  namespace :admin do
@@ -307,7 +356,7 @@ module RailsBestPractices
307
356
  expect(routes.map(&:to_s)).to eq(['Admin::Test::PostsController#index'])
308
357
  end
309
358
 
310
- it 'should add route with namespace, but without resources' do
359
+ it 'adds route with namespace, but without resources' do
311
360
  content = <<-EOF
312
361
  RailsBestPracticesCom::Appllication.routes.draw do
313
362
  namespace :something do
@@ -318,10 +367,12 @@ module RailsBestPractices
318
367
  EOF
319
368
  runner.prepare('config/routes.rb', content)
320
369
  routes = Prepares.routes
321
- 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
+ )
322
373
  end
323
374
 
324
- it 'should add route with scope' do
375
+ it 'adds route with scope' do
325
376
  content = <<-EOF
326
377
  RailsBestPracticesCom::Application.routes.draw do
327
378
  scope module: "admin" do
@@ -341,17 +392,19 @@ module RailsBestPractices
341
392
  EOF
342
393
  runner.prepare('config/routes.rb', content)
343
394
  routes = Prepares.routes
344
- expect(routes.map(&:to_s)).to eq([
345
- 'Admin::PostsController#index',
346
- 'Admin::DiscussionsController#index',
347
- 'CommentsController#index',
348
- 'UsersController#show',
349
- 'UsersController#preview'
350
- ])
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
+ )
351
404
  end
352
405
  end
353
406
 
354
- it 'should add route for direct get/post' do
407
+ it 'adds route for direct get/post' do
355
408
  content = <<-EOF
356
409
  RailsBestPracticesCom::Application.routes.draw do
357
410
  get 'posts/show'
@@ -364,10 +417,18 @@ module RailsBestPractices
364
417
  runner.prepare('config/routes.rb', content)
365
418
  routes = Prepares.routes
366
419
  expect(routes.size).to eq(5)
367
- 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
+ )
368
429
  end
369
430
 
370
- it 'should add routes for another get/post' do
431
+ it 'adds routes for another get/post' do
371
432
  content = <<-EOF
372
433
  RailsBestPracticesCom::Application.routes.draw
373
434
  get "/login", to: 'sessions#new', as: :login
@@ -379,7 +440,7 @@ module RailsBestPractices
379
440
  expect(routes.first.to_s).to eq('SessionsController#new')
380
441
  end
381
442
 
382
- it 'should add match route' do
443
+ it 'adds match route' do
383
444
  content = <<-EOF
384
445
  RailsBestPracticesCom::Application.routes.draw do
385
446
  match '/auth/:provider/callback' => 'authentications#create'
@@ -390,7 +451,7 @@ module RailsBestPractices
390
451
  expect(routes.map(&:to_s)).to eq(['AuthenticationsController#create'])
391
452
  end
392
453
 
393
- it 'should add match route with all actions' do
454
+ it 'adds match route with all actions' do
394
455
  content = <<-EOF
395
456
  RailsBestPracticesCom::Application.routes.draw do
396
457
  match 'internal/:action/*whatever', controller: "internal"
@@ -401,7 +462,7 @@ module RailsBestPractices
401
462
  expect(routes.map(&:to_s)).to eq(['InternalController#*'])
402
463
  end
403
464
 
404
- it 'should add root route' do
465
+ it 'adds root route' do
405
466
  content = <<-EOF
406
467
  RailsBestPracticesCom::Application.routes.draw do
407
468
  root to: 'home#index'
@@ -412,7 +473,7 @@ module RailsBestPractices
412
473
  expect(routes.map(&:to_s)).to eq(['HomeController#index'])
413
474
  end
414
475
 
415
- it 'should add root shortcut route' do
476
+ it 'adds root shortcut route' do
416
477
  content = <<-EOF
417
478
  RailsBestPracticesCom::Application.routes.draw do
418
479
  root 'home#index'
@@ -423,7 +484,7 @@ module RailsBestPractices
423
484
  expect(routes.map(&:to_s)).to eq(['HomeController#index'])
424
485
  end
425
486
 
426
- it 'should do nothing for default route' do
487
+ it 'does nothing for default route' do
427
488
  content = <<-EOF
428
489
  RailsBestPracticesCom::Application.routes.draw do
429
490
  match ':controller(/:action(/:id(.:format)))'
@@ -434,7 +495,7 @@ module RailsBestPractices
434
495
  expect(routes.size).to eq(0)
435
496
  end
436
497
 
437
- it 'should do nothing for redirect' do
498
+ it 'does nothing for redirect' do
438
499
  content = <<-EOF
439
500
  RailsBestPracticesCom::Application.routes.draw do
440
501
  match "/stories/:name" => redirect("/posts/%{name}")
@@ -446,7 +507,7 @@ module RailsBestPractices
446
507
  expect(routes.size).to eq(0)
447
508
  end
448
509
 
449
- it 'should parse customize route in nested resources' do
510
+ it 'parses customize route in nested resources' do
450
511
  content = <<-EOF
451
512
  RailsBestPracticesCom::Application.routes.draw do
452
513
  resources :posts do
@@ -460,7 +521,7 @@ module RailsBestPractices
460
521
  expect(routes.last.to_s).to eq('PostsController#stop')
461
522
  end
462
523
 
463
- 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
464
525
  content = <<-EOF
465
526
  RailsBestPracticesCom::Application.routes.draw do
466
527
  resources :posts do
@@ -473,7 +534,7 @@ module RailsBestPractices
473
534
  expect(routes.last.to_s).to eq('PostsController#stop')
474
535
  end
475
536
 
476
- it 'should parse custom route for resource with symbol action name' do
537
+ it 'parses custom route for resource with symbol action name' do
477
538
  content = <<-EOF
478
539
  RailsBestPracticesCom::Application.routes.draw do
479
540
  resources :posts do
@@ -486,7 +547,7 @@ module RailsBestPractices
486
547
  expect(routes.last.to_s).to eq('PostsController#stop')
487
548
  end
488
549
 
489
- it 'should not take former resources for direct get/post' do
550
+ it 'does not take former resources for direct get/post' do
490
551
  content = <<-EOF
491
552
  RailsBestPracticesCom::Application.routes.draw do
492
553
  resources :posts
@@ -498,7 +559,7 @@ module RailsBestPractices
498
559
  expect(routes.last.to_s).to eq('SprintsController#stop')
499
560
  end
500
561
 
501
- it 'should not parse wrong route' do
562
+ it 'does not parse wrong route' do
502
563
  content = <<-EOF
503
564
  RailsBestPracticesCom::Application.routes.draw do
504
565
  match ':controller/:action' => '#index', as: :auto_complete