rails_best_practices 1.9.0 → 1.9.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 (81) hide show
  1. data/.travis.yml +4 -1
  2. data/Gemfile +0 -3
  3. data/Gemfile.lock +10 -9
  4. data/README.md +2 -0
  5. data/lib/rails_best_practices/analyzer.rb +40 -21
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +12 -0
  8. data/lib/rails_best_practices/core/configs.rb +7 -0
  9. data/lib/rails_best_practices/core/error.rb +2 -1
  10. data/lib/rails_best_practices/core/routes.rb +11 -5
  11. data/lib/rails_best_practices/core/runner.rb +6 -2
  12. data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
  13. data/lib/rails_best_practices/prepares.rb +5 -0
  14. data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
  15. data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
  16. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
  17. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
  18. data/lib/rails_best_practices/version.rb +1 -1
  19. data/rails_best_practices.gemspec +1 -0
  20. data/spec/rails_best_practices/analyzer_spec.rb +52 -32
  21. data/spec/rails_best_practices/core/check_spec.rb +64 -45
  22. data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
  23. data/spec/rails_best_practices/core/configs_spec.rb +7 -0
  24. data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
  25. data/spec/rails_best_practices/core/error_spec.rb +28 -22
  26. data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
  27. data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
  28. data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
  29. data/spec/rails_best_practices/core/methods_spec.rb +37 -35
  30. data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
  31. data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
  32. data/spec/rails_best_practices/core/models_spec.rb +4 -2
  33. data/spec/rails_best_practices/core/modules_spec.rb +21 -19
  34. data/spec/rails_best_practices/core/nil_spec.rb +23 -21
  35. data/spec/rails_best_practices/core/routes_spec.rb +21 -14
  36. data/spec/rails_best_practices/core/runner_spec.rb +17 -15
  37. data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
  38. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
  39. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
  40. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
  41. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
  42. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
  43. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
  44. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
  45. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
  46. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
  47. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
  48. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
  49. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
  50. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
  51. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
  52. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
  53. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
  54. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
  55. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
  56. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
  57. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
  58. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
  59. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
  60. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
  61. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
  62. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
  63. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
  64. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
  65. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
  66. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
  67. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
  68. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
  69. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
  70. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
  71. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
  72. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
  73. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
  74. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
  75. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
  76. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
  77. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
  78. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
  79. data/spec/spec_helper.rb +11 -20
  80. metadata +42 -26
  81. data/.watchr.example +0 -65
@@ -1,649 +1,695 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Prepares::RoutePrepare do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:prepares => RailsBestPractices::Prepares::RoutePrepare.new) }
5
-
6
- context "rails2" do
7
- context "resources" do
8
- it "should add resources route" do
9
- content =<<-EOF
10
- ActionController::Routing::Routes.draw do |map|
11
- map.resources :posts
12
- end
13
- EOF
14
- runner.prepare('config/routes.rb', content)
15
- routes = RailsBestPractices::Prepares.routes
16
- routes.size.should == 7
17
- routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
18
- end
3
+ module RailsBestPractices
4
+ module Prepares
5
+ describe RoutePrepare do
6
+ let(:runner) { Core::Runner.new(:prepares => RoutePrepare.new) }
7
+
8
+ context "rails2" do
9
+ context "resources" do
10
+ it "should add resources route" do
11
+ content =<<-EOF
12
+ ActionController::Routing::Routes.draw do |map|
13
+ map.resources :posts
14
+ end
15
+ EOF
16
+ runner.prepare('config/routes.rb', content)
17
+ routes = Prepares.routes
18
+ routes.size.should == 7
19
+ routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
20
+ end
19
21
 
20
- it "should add multiple resources route" do
21
- content =<<-EOF
22
- ActionController::Routing::Routes.draw do |map|
23
- map.resources :posts, :users
24
- end
25
- EOF
26
- runner.prepare('config/routes.rb', content)
27
- routes = RailsBestPractices::Prepares.routes
28
- routes.size.should == 14
29
- end
22
+ it "should add multiple resources route" do
23
+ content =<<-EOF
24
+ ActionController::Routing::Routes.draw do |map|
25
+ map.resources :posts, :users
26
+ end
27
+ EOF
28
+ runner.prepare('config/routes.rb', content)
29
+ routes = Prepares.routes
30
+ routes.size.should == 14
31
+ end
30
32
 
31
- it "should add resources route with explict controller" do
32
- content =<<-EOF
33
- ActionController::Routing::Routes.draw do |map|
34
- map.resources :posts, :controller => :blog_posts
35
- end
36
- EOF
37
- runner.prepare('config/routes.rb', content)
38
- routes = RailsBestPractices::Prepares.routes
39
- routes.size.should == 7
40
- routes.map(&:to_s).should == ["BlogPostsController#index", "BlogPostsController#show", "BlogPostsController#new", "BlogPostsController#create", "BlogPostsController#edit", "BlogPostsController#update", "BlogPostsController#destroy"]
41
- end
33
+ it "should add resources route with explict controller" do
34
+ content =<<-EOF
35
+ ActionController::Routing::Routes.draw do |map|
36
+ map.resources :posts, :controller => :blog_posts
37
+ end
38
+ EOF
39
+ runner.prepare('config/routes.rb', content)
40
+ routes = Prepares.routes
41
+ routes.size.should == 7
42
+ routes.map(&:to_s).should == ["BlogPostsController#index", "BlogPostsController#show", "BlogPostsController#new", "BlogPostsController#create", "BlogPostsController#edit", "BlogPostsController#update", "BlogPostsController#destroy"]
43
+ end
42
44
 
43
- it "should add resources route with only option" do
44
- content =<<-EOF
45
- ActionController::Routing::Routes.draw do |map|
46
- map.resources :posts, :only => [:index, :show, :new, :create]
47
- end
48
- EOF
49
- runner.prepare('config/routes.rb', content)
50
- routes = RailsBestPractices::Prepares.routes
51
- routes.size.should == 4
52
- routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
53
- end
45
+ it "should add resources route with only option" do
46
+ content =<<-EOF
47
+ ActionController::Routing::Routes.draw do |map|
48
+ map.resources :posts, :only => [:index, :show, :new, :create]
49
+ end
50
+ EOF
51
+ runner.prepare('config/routes.rb', content)
52
+ routes = Prepares.routes
53
+ routes.size.should == 4
54
+ routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
55
+ end
54
56
 
55
- it "should add resources route with except option" do
56
- content =<<-EOF
57
- ActionController::Routing::Routes.draw do |map|
58
- map.resources :posts, :except => [:edit, :update, :destroy]
59
- end
60
- EOF
61
- runner.prepare('config/routes.rb', content)
62
- routes = RailsBestPractices::Prepares.routes
63
- routes.size.should == 4
64
- routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
65
- end
57
+ it "should add resources route with except option" do
58
+ content =<<-EOF
59
+ ActionController::Routing::Routes.draw do |map|
60
+ map.resources :posts, :except => [:edit, :update, :destroy]
61
+ end
62
+ EOF
63
+ runner.prepare('config/routes.rb', content)
64
+ routes = Prepares.routes
65
+ routes.size.should == 4
66
+ routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
67
+ end
66
68
 
67
- it "should not add resources routes with :only => :none" do
68
- content =<<-EOF
69
- ActionController::Routing::Routes.draw do |map|
70
- map.resources :posts, :only => :none
71
- end
72
- EOF
73
- runner.prepare('config/routes.rb', content)
74
- routes = RailsBestPractices::Prepares.routes
75
- routes.size.should == 0
76
- end
69
+ it "should not add resources routes with :only => :none" do
70
+ content =<<-EOF
71
+ ActionController::Routing::Routes.draw do |map|
72
+ map.resources :posts, :only => :none
73
+ end
74
+ EOF
75
+ runner.prepare('config/routes.rb', content)
76
+ routes = Prepares.routes
77
+ routes.size.should == 0
78
+ end
77
79
 
78
- it "should not add resources routes with :except => :all" do
79
- content =<<-EOF
80
- ActionController::Routing::Routes.draw do |map|
81
- map.resources :posts, :except => :all
82
- end
83
- EOF
84
- runner.prepare('config/routes.rb', content)
85
- routes = RailsBestPractices::Prepares.routes
86
- routes.size.should == 0
87
- end
80
+ it "should not add resources routes with :except => :all" do
81
+ content =<<-EOF
82
+ ActionController::Routing::Routes.draw do |map|
83
+ map.resources :posts, :except => :all
84
+ end
85
+ EOF
86
+ runner.prepare('config/routes.rb', content)
87
+ routes = Prepares.routes
88
+ routes.size.should == 0
89
+ end
88
90
 
89
- it "should add resource routes with hash collection/member routes" do
90
- content =<<-EOF
91
- ActionController::Routing::Routes.draw do |map|
92
- map.resources :posts, :only => [:show], :collection => { :list => :get }, :member => { :create => :post, :update => :put, :destroy => :delete }
93
- end
94
- EOF
95
- runner.prepare('config/routes.rb', content)
96
- routes = RailsBestPractices::Prepares.routes
97
- routes.size.should == 5
98
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "PostsController#list"]
99
- end
91
+ it "should add resource routes with hash collection/member routes" do
92
+ content =<<-EOF
93
+ ActionController::Routing::Routes.draw do |map|
94
+ map.resources :posts, :only => [:show], :collection => { :list => :get }, :member => { :create => :post, :update => :put, :destroy => :delete }
95
+ end
96
+ EOF
97
+ runner.prepare('config/routes.rb', content)
98
+ routes = Prepares.routes
99
+ routes.size.should == 5
100
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "PostsController#list"]
101
+ end
100
102
 
101
- it "should add resource routes with array collection/member routes" do
102
- content =<<-EOF
103
- ActionController::Routing::Routes.draw do |map|
104
- map.resources :posts, :only => [:show], :collection => [:list], :member => [:create, :update, :destroy]
105
- end
106
- EOF
107
- runner.prepare('config/routes.rb', content)
108
- routes = RailsBestPractices::Prepares.routes
109
- routes.size.should == 5
110
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "PostsController#list"]
111
- end
103
+ it "should add resource routes with array collection/member routes" do
104
+ content =<<-EOF
105
+ ActionController::Routing::Routes.draw do |map|
106
+ map.resources :posts, :only => [:show], :collection => [:list], :member => [:create, :update, :destroy]
107
+ end
108
+ EOF
109
+ runner.prepare('config/routes.rb', content)
110
+ routes = Prepares.routes
111
+ routes.size.should == 5
112
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "PostsController#list"]
113
+ end
112
114
 
113
- it "should add route with nested routes" do
114
- content =<<-EOF
115
- ActionController::Routing::Routes.draw do |map|
116
- map.resources :posts do |post|
117
- post.resources :comments
115
+ it "should add route with nested routes" do
116
+ content =<<-EOF
117
+ ActionController::Routing::Routes.draw do |map|
118
+ map.resources :posts do |post|
119
+ post.resources :comments
120
+ end
121
+ end
122
+ EOF
123
+ runner.prepare('config/routes.rb', content)
124
+ routes = Prepares.routes
125
+ routes.size.should == 14
118
126
  end
119
- end
120
- EOF
121
- runner.prepare('config/routes.rb', content)
122
- routes = RailsBestPractices::Prepares.routes
123
- routes.size.should == 14
124
- end
125
127
 
126
- it "should add route with namespace" do
127
- content =<<-EOF
128
- ActionController::Routing::Routes.draw do |map|
129
- map.namespace :admin do |admin|
130
- admin.namespace :test do |test|
131
- test.resources :posts, :only => [:index]
128
+ it "should add route with namespace" do
129
+ content =<<-EOF
130
+ ActionController::Routing::Routes.draw do |map|
131
+ map.namespace :admin do |admin|
132
+ admin.namespace :test do |test|
133
+ test.resources :posts, :only => [:index]
134
+ end
135
+ end
132
136
  end
137
+ EOF
138
+ runner.prepare('config/routes.rb', content)
139
+ routes = Prepares.routes
140
+ routes.map(&:to_s).should == ["Admin::Test::PostsController#index"]
133
141
  end
134
142
  end
135
- EOF
136
- runner.prepare('config/routes.rb', content)
137
- routes = RailsBestPractices::Prepares.routes
138
- routes.map(&:to_s).should == ["Admin::Test::PostsController#index"]
139
- end
140
- end
141
143
 
142
- context "resource" do
143
- it "should add resource route" do
144
- content =<<-EOF
145
- ActionController::Routing::Routes.draw do |map|
146
- map.resource :posts
147
- end
148
- EOF
149
- runner.prepare('config/routes.rb', content)
150
- routes = RailsBestPractices::Prepares.routes
151
- routes.size.should == 6
152
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
153
- end
144
+ context "resource" do
145
+ it "should add resource route" do
146
+ content =<<-EOF
147
+ ActionController::Routing::Routes.draw do |map|
148
+ map.resource :posts
149
+ end
150
+ EOF
151
+ runner.prepare('config/routes.rb', content)
152
+ routes = Prepares.routes
153
+ routes.size.should == 6
154
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
155
+ end
154
156
 
155
- it "should add multiple resource route" do
156
- content =<<-EOF
157
- ActionController::Routing::Routes.draw do |map|
158
- map.resource :posts, :users
159
- end
160
- EOF
161
- runner.prepare('config/routes.rb', content)
162
- routes = RailsBestPractices::Prepares.routes
163
- routes.size.should == 12
164
- end
157
+ it "should add multiple resource route" do
158
+ content =<<-EOF
159
+ ActionController::Routing::Routes.draw do |map|
160
+ map.resource :posts, :users
161
+ end
162
+ EOF
163
+ runner.prepare('config/routes.rb', content)
164
+ routes = Prepares.routes
165
+ routes.size.should == 12
166
+ end
165
167
 
166
- it "should add resource route with only option" do
167
- content =<<-EOF
168
- ActionController::Routing::Routes.draw do |map|
169
- map.resource :posts, :only => [:show, :new, :create]
170
- end
171
- EOF
172
- runner.prepare('config/routes.rb', content)
173
- routes = RailsBestPractices::Prepares.routes
174
- routes.size.should == 3
175
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
176
- end
168
+ it "should add resource route with only option" do
169
+ content =<<-EOF
170
+ ActionController::Routing::Routes.draw do |map|
171
+ map.resource :posts, :only => [:show, :new, :create]
172
+ end
173
+ EOF
174
+ runner.prepare('config/routes.rb', content)
175
+ routes = Prepares.routes
176
+ routes.size.should == 3
177
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
178
+ end
177
179
 
178
- it "should add resource route with except option" do
179
- content =<<-EOF
180
- ActionController::Routing::Routes.draw do |map|
181
- map.resource :posts, :except => [:edit, :update, :destroy]
182
- end
183
- EOF
184
- runner.prepare('config/routes.rb', content)
185
- routes = RailsBestPractices::Prepares.routes
186
- routes.size.should == 3
187
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
188
- end
180
+ it "should add resource route with except option" do
181
+ content =<<-EOF
182
+ ActionController::Routing::Routes.draw do |map|
183
+ map.resource :posts, :except => [:edit, :update, :destroy]
184
+ end
185
+ EOF
186
+ runner.prepare('config/routes.rb', content)
187
+ routes = Prepares.routes
188
+ routes.size.should == 3
189
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
190
+ end
189
191
 
190
- it "should not add resource routes with :only => :none" do
191
- content =<<-EOF
192
- ActionController::Routing::Routes.draw do |map|
193
- map.resource :posts, :only => :none
194
- end
195
- EOF
196
- runner.prepare('config/routes.rb', content)
197
- routes = RailsBestPractices::Prepares.routes
198
- routes.size.should == 0
199
- end
192
+ it "should not add resource routes with :only => :none" do
193
+ content =<<-EOF
194
+ ActionController::Routing::Routes.draw do |map|
195
+ map.resource :posts, :only => :none
196
+ end
197
+ EOF
198
+ runner.prepare('config/routes.rb', content)
199
+ routes = Prepares.routes
200
+ routes.size.should == 0
201
+ end
200
202
 
201
- it "should not add resource routes with :except => :all" do
202
- content =<<-EOF
203
- ActionController::Routing::Routes.draw do |map|
204
- map.resource :posts, :except => :all
203
+ it "should not add resource routes with :except => :all" do
204
+ content =<<-EOF
205
+ ActionController::Routing::Routes.draw do |map|
206
+ map.resource :posts, :except => :all
207
+ end
208
+ EOF
209
+ runner.prepare('config/routes.rb', content)
210
+ routes = Prepares.routes
211
+ routes.size.should == 0
212
+ end
205
213
  end
206
- EOF
207
- runner.prepare('config/routes.rb', content)
208
- routes = RailsBestPractices::Prepares.routes
209
- routes.size.should == 0
210
- end
211
- end
212
214
 
213
- it "should add connect route" do
214
- content =<<-EOF
215
- ActionController::Routing::Routes.draw do |map|
216
- map.connect 'vote', :controller => "votes", :action => "create", :method => :post
217
- end
218
- EOF
219
- runner.prepare('config/routes.rb', content)
220
- routes = RailsBestPractices::Prepares.routes
221
- routes.map(&:to_s).should == ["VotesController#create"]
222
- end
223
-
224
- it "should add connect route with all actions" do
225
- content =<<-EOF
226
- ActionController::Routing::Routes.draw do |map|
227
- map.connect 'internal/:action/*whatever', :controller => "internal"
228
- end
229
- EOF
230
- runner.prepare('config/routes.rb', content)
231
- routes = RailsBestPractices::Prepares.routes
232
- routes.map(&:to_s).should == ["InternalController#*"]
233
- end
234
-
235
- it "should add named route" do
236
- content =<<-EOF
237
- ActionController::Routing::Routes.draw do |map|
238
- map.login '/player/login', :controller => 'sessions', :action => 'new', :conditions => { :method => :get }
239
- end
240
- EOF
241
- runner.prepare('config/routes.rb', content)
242
- routes = RailsBestPractices::Prepares.routes
243
- routes.map(&:to_s).should == ["SessionsController#new"]
244
- end
245
-
246
- it "should add named route with with_options" do
247
- content =<<-EOF
248
- ActionController::Routing::Routes.draw do |map|
249
- map.with_options(:controller => "admin_session") do |session|
250
- session.login '/login', :action => 'new', :method => :get
215
+ it "should add connect route" do
216
+ content =<<-EOF
217
+ ActionController::Routing::Routes.draw do |map|
218
+ map.connect 'vote', :controller => "votes", :action => "create", :method => :post
219
+ end
220
+ EOF
221
+ runner.prepare('config/routes.rb', content)
222
+ routes = Prepares.routes
223
+ routes.map(&:to_s).should == ["VotesController#create"]
251
224
  end
252
- end
253
- EOF
254
- runner.prepare('config/routes.rb', content)
255
- routes = RailsBestPractices::Prepares.routes
256
- routes.map(&:to_s).should == ["AdminSessionController#new"]
257
- end
258
-
259
- it "should not take former resources for direct get/post" do
260
- content =<<-EOF
261
- ActionController::Routing::Routes.draw do |map|
262
- map.resources :posts
263
- map.stop 'sprints/stop', :controller => 'sprints', :action => 'stop'
264
- end
265
- EOF
266
- runner.prepare('config/routes.rb', content)
267
- routes = RailsBestPractices::Prepares.routes
268
- routes.last.to_s.should == "SprintsController#stop"
269
- end
270
- end
271
225
 
272
- context "rails3" do
273
- context "resources" do
274
- it "should add resources route" do
275
- content =<<-EOF
276
- RailsBestPracticesCom::Application.routes.draw do
277
- resources :posts
226
+ it "should add connect route with all actions" do
227
+ content =<<-EOF
228
+ ActionController::Routing::Routes.draw do |map|
229
+ map.connect 'internal/:action/*whatever', :controller => "internal"
230
+ end
231
+ EOF
232
+ runner.prepare('config/routes.rb', content)
233
+ routes = Prepares.routes
234
+ routes.map(&:to_s).should == ["InternalController#*"]
278
235
  end
279
- EOF
280
- runner.prepare('config/routes.rb', content)
281
- routes = RailsBestPractices::Prepares.routes
282
- routes.size.should == 7
283
- routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
284
- end
285
236
 
286
- it "should add multiple resources route" do
287
- content =<<-EOF
288
- RailsBestPracticesCom::Application.routes.draw do
289
- resources :posts, :users
237
+ it "should add named route" do
238
+ content =<<-EOF
239
+ ActionController::Routing::Routes.draw do |map|
240
+ map.login '/player/login', :controller => 'sessions', :action => 'new', :conditions => { :method => :get }
241
+ end
242
+ EOF
243
+ runner.prepare('config/routes.rb', content)
244
+ routes = Prepares.routes
245
+ routes.map(&:to_s).should == ["SessionsController#new"]
290
246
  end
291
- EOF
292
- runner.prepare('config/routes.rb', content)
293
- routes = RailsBestPractices::Prepares.routes
294
- routes.size.should == 14
295
- end
296
247
 
297
- it "should add resources route with explict controller" do
298
- content =<<-EOF
299
- RailsBestPracticesCom::Application.routes.draw do
300
- resources :posts, :controller => :blog_posts
248
+ it "should add named route with with_options" do
249
+ content =<<-EOF
250
+ ActionController::Routing::Routes.draw do |map|
251
+ map.with_options(:controller => "admin_session") do |session|
252
+ session.login '/login', :action => 'new', :method => :get
253
+ end
254
+ end
255
+ EOF
256
+ runner.prepare('config/routes.rb', content)
257
+ routes = Prepares.routes
258
+ routes.map(&:to_s).should == ["AdminSessionController#new"]
301
259
  end
302
- EOF
303
- runner.prepare('config/routes.rb', content)
304
- routes = RailsBestPractices::Prepares.routes
305
- routes.size.should == 7
306
- routes.map(&:to_s).should == ["BlogPostsController#index", "BlogPostsController#show", "BlogPostsController#new", "BlogPostsController#create", "BlogPostsController#edit", "BlogPostsController#update", "BlogPostsController#destroy"]
307
- end
308
260
 
309
- it "should add resources route with only option" do
310
- content =<<-EOF
311
- RailsBestPracticesCom::Application.routes.draw do
312
- resources :posts, :only => [:index, :show, :new, :create]
261
+ it "should not take former resources for direct get/post" do
262
+ content =<<-EOF
263
+ ActionController::Routing::Routes.draw do |map|
264
+ map.resources :posts
265
+ map.stop 'sprints/stop', :controller => 'sprints', :action => 'stop'
266
+ end
267
+ EOF
268
+ runner.prepare('config/routes.rb', content)
269
+ routes = Prepares.routes
270
+ routes.last.to_s.should == "SprintsController#stop"
313
271
  end
314
- EOF
315
- runner.prepare('config/routes.rb', content)
316
- routes = RailsBestPractices::Prepares.routes
317
- routes.size.should == 4
318
- routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
319
272
  end
320
273
 
321
- it "should add resources route with except option" do
322
- content =<<-EOF
323
- RailsBestPracticesCom::Application.routes.draw do
324
- resources :posts, :except => [:edit, :update, :destroy]
325
- end
326
- EOF
327
- runner.prepare('config/routes.rb', content)
328
- routes = RailsBestPractices::Prepares.routes
329
- routes.size.should == 4
330
- routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
331
- end
274
+ context "rails3" do
275
+ context "resources" do
276
+ it "should add resources route" do
277
+ content =<<-EOF
278
+ RailsBestPracticesCom::Application.routes.draw do
279
+ resources :posts
280
+ end
281
+ EOF
282
+ runner.prepare('config/routes.rb', content)
283
+ routes = Prepares.routes
284
+ routes.size.should == 7
285
+ routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
286
+ end
332
287
 
333
- it "should not add resources routes with :only => :none" do
334
- content =<<-EOF
335
- RailsBestPracticesCom::Application.routes.draw do
336
- resources :posts, :only => :none
337
- end
338
- EOF
339
- runner.prepare('config/routes.rb', content)
340
- routes = RailsBestPractices::Prepares.routes
341
- routes.size.should == 0
342
- end
288
+ it "should add multiple resources route" do
289
+ content =<<-EOF
290
+ RailsBestPracticesCom::Application.routes.draw do
291
+ resources :posts, :users
292
+ end
293
+ EOF
294
+ runner.prepare('config/routes.rb', content)
295
+ routes = Prepares.routes
296
+ routes.size.should == 14
297
+ end
343
298
 
344
- it "should not add resources routes with :except => :all" do
345
- content =<<-EOF
346
- RailsBestPracticesCom::Application.routes.draw do
347
- resources :posts, :except => :all
348
- end
349
- EOF
350
- runner.prepare('config/routes.rb', content)
351
- routes = RailsBestPractices::Prepares.routes
352
- routes.size.should == 0
353
- end
299
+ it "should add resources route with explict controller" do
300
+ content =<<-EOF
301
+ RailsBestPracticesCom::Application.routes.draw do
302
+ resources :posts, :controller => :blog_posts
303
+ end
304
+ EOF
305
+ runner.prepare('config/routes.rb', content)
306
+ routes = Prepares.routes
307
+ routes.size.should == 7
308
+ routes.map(&:to_s).should == ["BlogPostsController#index", "BlogPostsController#show", "BlogPostsController#new", "BlogPostsController#create", "BlogPostsController#edit", "BlogPostsController#update", "BlogPostsController#destroy"]
309
+ end
354
310
 
355
- it "should add connect route" do
356
- content =<<-EOF
357
- ActionController::Routing::Routes.draw do |map|
358
- map.connect 'vote', :controller => "votes", :action => "create", :method => :post
359
- end
360
- EOF
361
- runner.prepare('config/routes.rb', content)
362
- routes = RailsBestPractices::Prepares.routes
363
- routes.map(&:to_s).should == ["VotesController#create"]
364
- end
311
+ it "should add resources route with only option" do
312
+ content =<<-EOF
313
+ RailsBestPracticesCom::Application.routes.draw do
314
+ resources :posts, :only => [:index, :show, :new, :create]
315
+ end
316
+ EOF
317
+ runner.prepare('config/routes.rb', content)
318
+ routes = Prepares.routes
319
+ routes.size.should == 4
320
+ routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
321
+ end
365
322
 
366
- it "should add named route" do
367
- content =<<-EOF
368
- ActionController::Routing::Routes.draw do |map|
369
- map.login '/player/login', :controller => 'sessions', :action => 'new', :conditions => { :method => :get }
370
- end
371
- EOF
372
- runner.prepare('config/routes.rb', content)
373
- routes = RailsBestPractices::Prepares.routes
374
- routes.map(&:to_s).should == ["SessionsController#new"]
375
- end
376
- end
323
+ it "should add resources route with except option" do
324
+ content =<<-EOF
325
+ RailsBestPracticesCom::Application.routes.draw do
326
+ resources :posts, :except => [:edit, :update, :destroy]
327
+ end
328
+ EOF
329
+ runner.prepare('config/routes.rb', content)
330
+ routes = Prepares.routes
331
+ routes.size.should == 4
332
+ routes.map(&:to_s).should == ["PostsController#index", "PostsController#show", "PostsController#new", "PostsController#create"]
333
+ end
377
334
 
378
- context "resource" do
379
- it "should add resource route" do
380
- content =<<-EOF
381
- RailsBestPracticesCom::Application.routes.draw do
382
- resource :posts
383
- end
384
- EOF
385
- runner.prepare('config/routes.rb', content)
386
- routes = RailsBestPractices::Prepares.routes
387
- routes.size.should == 6
388
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
389
- end
335
+ it "should not add resources routes with :only => :none" do
336
+ content =<<-EOF
337
+ RailsBestPracticesCom::Application.routes.draw do
338
+ resources :posts, :only => :none
339
+ end
340
+ EOF
341
+ runner.prepare('config/routes.rb', content)
342
+ routes = Prepares.routes
343
+ routes.size.should == 0
344
+ end
390
345
 
391
- it "should add multiple resource route" do
392
- content =<<-EOF
393
- RailsBestPracticesCom::Application.routes.draw do
394
- resource :posts, :users
395
- end
396
- EOF
397
- runner.prepare('config/routes.rb', content)
398
- routes = RailsBestPractices::Prepares.routes
399
- routes.size.should == 12
400
- end
346
+ it "should not add resources routes with :except => :all" do
347
+ content =<<-EOF
348
+ RailsBestPracticesCom::Application.routes.draw do
349
+ resources :posts, :except => :all
350
+ end
351
+ EOF
352
+ runner.prepare('config/routes.rb', content)
353
+ routes = Prepares.routes
354
+ routes.size.should == 0
355
+ end
401
356
 
402
- it "should add resource route with only option" do
403
- content =<<-EOF
404
- RailsBestPracticesCom::Application.routes.draw do
405
- resource :posts, :only => [:show, :new, :create]
406
- end
407
- EOF
408
- runner.prepare('config/routes.rb', content)
409
- routes = RailsBestPractices::Prepares.routes
410
- routes.size.should == 3
411
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
412
- end
357
+ it "should add connect route" do
358
+ content =<<-EOF
359
+ ActionController::Routing::Routes.draw do |map|
360
+ map.connect 'vote', :controller => "votes", :action => "create", :method => :post
361
+ end
362
+ EOF
363
+ runner.prepare('config/routes.rb', content)
364
+ routes = Prepares.routes
365
+ routes.map(&:to_s).should == ["VotesController#create"]
366
+ end
413
367
 
414
- it "should add resource route with except option" do
415
- content =<<-EOF
416
- RailsBestPracticesCom::Application.routes.draw do
417
- resource :posts, :except => [:edit, :update, :destroy]
368
+ it "should add named route" do
369
+ content =<<-EOF
370
+ ActionController::Routing::Routes.draw do |map|
371
+ map.login '/player/login', :controller => 'sessions', :action => 'new', :conditions => { :method => :get }
372
+ end
373
+ EOF
374
+ runner.prepare('config/routes.rb', content)
375
+ routes = Prepares.routes
376
+ routes.map(&:to_s).should == ["SessionsController#new"]
377
+ end
418
378
  end
419
- EOF
420
- runner.prepare('config/routes.rb', content)
421
- routes = RailsBestPractices::Prepares.routes
422
- routes.size.should == 3
423
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
424
- end
425
379
 
426
- it "should not add resource routes with :only => :none" do
427
- content =<<-EOF
428
- RailsBestPracticesCom::Application.routes.draw do
429
- resource :posts, :only => :none
430
- end
431
- EOF
432
- runner.prepare('config/routes.rb', content)
433
- routes = RailsBestPractices::Prepares.routes
434
- routes.size.should == 0
435
- end
380
+ context "resource" do
381
+ it "should add resource route" do
382
+ content =<<-EOF
383
+ RailsBestPracticesCom::Application.routes.draw do
384
+ resource :posts
385
+ end
386
+ EOF
387
+ runner.prepare('config/routes.rb', content)
388
+ routes = Prepares.routes
389
+ routes.size.should == 6
390
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create", "PostsController#edit", "PostsController#update", "PostsController#destroy"]
391
+ end
436
392
 
437
- it "should not add resource routes with :except => :all" do
438
- content =<<-EOF
439
- RailsBestPracticesCom::Application.routes.draw do
440
- resource :posts, :except => :all
441
- end
442
- EOF
443
- runner.prepare('config/routes.rb', content)
444
- routes = RailsBestPractices::Prepares.routes
445
- routes.size.should == 0
446
- end
393
+ it "should add multiple resource route" do
394
+ content =<<-EOF
395
+ RailsBestPracticesCom::Application.routes.draw do
396
+ resource :posts, :users
397
+ end
398
+ EOF
399
+ runner.prepare('config/routes.rb', content)
400
+ routes = Prepares.routes
401
+ routes.size.should == 12
402
+ end
447
403
 
448
- it "should add resource routes with get/post/put/delete routes" do
449
- content =<<-EOF
450
- RailsBestPracticesCom::Application.routes.draw do
451
- resources :posts, :only => [:show] do
452
- get :list, :on => :collection
453
- collection do
454
- get :search
455
- match :available
404
+ it "should add resource route with only option" do
405
+ content =<<-EOF
406
+ RailsBestPracticesCom::Application.routes.draw do
407
+ resource :posts, :only => [:show, :new, :create]
456
408
  end
457
- post :create, :on => :member
458
- member do
459
- put :update
409
+ EOF
410
+ runner.prepare('config/routes.rb', content)
411
+ routes = Prepares.routes
412
+ routes.size.should == 3
413
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
414
+ end
415
+
416
+ it "should add resource route with except option" do
417
+ content =<<-EOF
418
+ RailsBestPracticesCom::Application.routes.draw do
419
+ resource :posts, :except => [:edit, :update, :destroy]
460
420
  end
421
+ EOF
422
+ runner.prepare('config/routes.rb', content)
423
+ routes = Prepares.routes
424
+ routes.size.should == 3
425
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#new", "PostsController#create"]
461
426
  end
462
- end
463
- EOF
464
- runner.prepare('config/routes.rb', content)
465
- routes = RailsBestPractices::Prepares.routes
466
- routes.size.should == 6
467
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#list", "PostsController#search", "PostsController#available", "PostsController#create", "PostsController#update"]
468
- end
469
427
 
470
- it "should add route with nested routes" do
471
- content =<<-EOF
472
- RailsBestPracticesCom::Application.routes.draw do
473
- resources :posts
474
- resources :comments
428
+ it "should not add resource routes with :only => :none" do
429
+ content =<<-EOF
430
+ RailsBestPracticesCom::Application.routes.draw do
431
+ resource :posts, :only => :none
432
+ end
433
+ EOF
434
+ runner.prepare('config/routes.rb', content)
435
+ routes = Prepares.routes
436
+ routes.size.should == 0
475
437
  end
476
- end
477
- EOF
478
- runner.prepare('config/routes.rb', content)
479
- routes = RailsBestPractices::Prepares.routes
480
- routes.size.should == 14
481
- end
482
438
 
483
- it "should add route with namespace" do
484
- content =<<-EOF
485
- RailsBestPracticesCom::Application.routes.draw do
486
- namespace :admin do
487
- namespace :test do
488
- resources :posts, :only => [:index]
439
+ it "should not add resource routes with :except => :all" do
440
+ content =<<-EOF
441
+ RailsBestPracticesCom::Application.routes.draw do
442
+ resource :posts, :except => :all
489
443
  end
444
+ EOF
445
+ runner.prepare('config/routes.rb', content)
446
+ routes = Prepares.routes
447
+ routes.size.should == 0
490
448
  end
491
- end
492
- EOF
493
- runner.prepare('config/routes.rb', content)
494
- routes = RailsBestPractices::Prepares.routes
495
- routes.map(&:to_s).should == ["Admin::Test::PostsController#index"]
496
- end
497
449
 
498
- it "should add route with scope" do
499
- content =<<-EOF
500
- RailsBestPracticesCom::Application.routes.draw do
501
- scope :module => "admin" do
502
- resources :posts, :only => [:index]
450
+ it "should add resource routes with get/post/put/delete routes" do
451
+ content =<<-EOF
452
+ RailsBestPracticesCom::Application.routes.draw do
453
+ resources :posts, :only => [:show] do
454
+ get :list, :on => :collection
455
+ collection do
456
+ get :search
457
+ match :available
458
+ end
459
+ post :create, :on => :member
460
+ member do
461
+ put :update
462
+ end
463
+ end
503
464
  end
504
- resources :discussions, :only => [:index], :module => "admin"
505
- scope "/admin" do
506
- resources :comments, :only => [:index]
465
+ EOF
466
+ runner.prepare('config/routes.rb', content)
467
+ routes = Prepares.routes
468
+ routes.size.should == 6
469
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#list", "PostsController#search", "PostsController#available", "PostsController#create", "PostsController#update"]
470
+ end
471
+
472
+ it "should add custom resources routes with {}" do
473
+ content =<<-EOF
474
+ RailsBestPracticesCom::Application.routes.draw do
475
+ resources :posts, :only => [:show] { get :inactive, :on => :collection }
507
476
  end
508
- scope "/:username", controller: :users do
509
- get '/' => :show
510
- scope 'topic' do
511
- get 'preview', :as => 'preview_user', :action => 'preview'
477
+ EOF
478
+ runner.prepare('config/routes.rb', content)
479
+ routes = Prepares.routes
480
+ routes.size.should == 2
481
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#inactive"]
482
+ end
483
+
484
+ it "should add resources routes with get %w() routes" do
485
+ content =<<-EOF
486
+ RailsBestPracticesCom::Application.routes.draw do
487
+ resources :posts, :only => [:show] do
488
+ collection do
489
+ get *%w(latest popular)
490
+ end
512
491
  end
513
492
  end
493
+ EOF
494
+ runner.prepare('config/routes.rb', content)
495
+ routes = Prepares.routes
496
+ routes.size.should == 3
497
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#latest", "PostsController#popular"]
514
498
  end
515
- EOF
516
- runner.prepare('config/routes.rb', content)
517
- routes = RailsBestPractices::Prepares.routes
518
- routes.map(&:to_s).should == [
519
- "Admin::PostsController#index",
520
- "Admin::DiscussionsController#index",
521
- "CommentsController#index",
522
- "UsersController#show",
523
- "UsersController#preview"
524
- ]
525
- end
526
- end
527
499
 
528
- it "should add route for direct get/post" do
529
- content =<<-EOF
530
- RailsBestPracticesCom::Application.routes.draw do
531
- get 'posts/show'
532
- post '/posts' => 'posts#create'
533
- put '/posts/:id' => 'posts#update'
534
- delete '/post/:id' => 'posts#destroy'
535
- get '/agb' => 'high_voltage/pages#show', :id => 'agb'
536
- end
537
- EOF
538
- runner.prepare('config/routes.rb', content)
539
- routes = RailsBestPractices::Prepares.routes
540
- routes.size.should == 5
541
- routes.map(&:to_s).should == ["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "HighVoltage::PagesController#show"]
542
- end
500
+ it "should add route with nested routes" do
501
+ content =<<-EOF
502
+ RailsBestPracticesCom::Application.routes.draw do
503
+ resources :posts
504
+ resources :comments
505
+ end
506
+ end
507
+ EOF
508
+ runner.prepare('config/routes.rb', content)
509
+ routes = Prepares.routes
510
+ routes.size.should == 14
511
+ end
543
512
 
544
- it "should add routes for another get/post" do
545
- content =<<-EOF
546
- RailsBestPracticesCom::Application.routes.draw
547
- get "/login", to: 'sessions#new', as: :login
548
- end
549
- EOF
550
- runner.prepare('config/routes.rb', content)
551
- routes = RailsBestPractices::Prepares.routes
552
- routes.size.should == 1
553
- routes.first.to_s.should == "SessionsController#new"
554
- end
513
+ it "should add route with namespace" do
514
+ content =<<-EOF
515
+ RailsBestPracticesCom::Application.routes.draw do
516
+ namespace :admin do
517
+ namespace :test do
518
+ resources :posts, :only => [:index]
519
+ end
520
+ end
521
+ end
522
+ EOF
523
+ runner.prepare('config/routes.rb', content)
524
+ routes = Prepares.routes
525
+ routes.map(&:to_s).should == ["Admin::Test::PostsController#index"]
526
+ end
555
527
 
556
- it "should add match route" do
557
- content =<<-EOF
558
- RailsBestPracticesCom::Application.routes.draw do
559
- match '/auth/:provider/callback' => 'authentications#create'
560
- end
561
- EOF
562
- runner.prepare('config/routes.rb', content)
563
- routes = RailsBestPractices::Prepares.routes
564
- routes.map(&:to_s).should == ["AuthenticationsController#create"]
565
- end
528
+ it "should add route with namespace, but without resources" do
529
+ content =<<-EOF
530
+ RailsBestPracticesCom::Appllication.routes.draw do
531
+ namespace :something do
532
+ get *%w(route_one route_two)
533
+ get :route_three, :action => "custom_action"
534
+ end
535
+ end
536
+ EOF
537
+ runner.prepare('config/routes.rb', content)
538
+ routes = Prepares.routes
539
+ routes.map(&:to_s).should == ["SomethingController#route_one", "SomethingController#route_two", "SomethingController#custom_action"]
540
+ end
566
541
 
567
- it "should add match route with all actions" do
568
- content =<<-EOF
569
- RailsBestPracticesCom::Application.routes.draw do
570
- match 'internal/:action/*whatever', :controller => "internal"
571
- end
572
- EOF
573
- runner.prepare('config/routes.rb', content)
574
- routes = RailsBestPractices::Prepares.routes
575
- routes.map(&:to_s).should == ["InternalController#*"]
576
- end
542
+ it "should add route with scope" do
543
+ content =<<-EOF
544
+ RailsBestPracticesCom::Application.routes.draw do
545
+ scope :module => "admin" do
546
+ resources :posts, :only => [:index]
547
+ end
548
+ resources :discussions, :only => [:index], :module => "admin"
549
+ scope "/admin" do
550
+ resources :comments, :only => [:index]
551
+ end
552
+ scope "/:username", controller: :users do
553
+ get '/' => :show
554
+ scope 'topic' do
555
+ get 'preview', :as => 'preview_user', :action => 'preview'
556
+ end
557
+ end
558
+ end
559
+ EOF
560
+ runner.prepare('config/routes.rb', content)
561
+ routes = Prepares.routes
562
+ routes.map(&:to_s).should == [
563
+ "Admin::PostsController#index",
564
+ "Admin::DiscussionsController#index",
565
+ "CommentsController#index",
566
+ "UsersController#show",
567
+ "UsersController#preview"
568
+ ]
569
+ end
570
+ end
577
571
 
578
- it "should add root route" do
579
- content =<<-EOF
580
- RailsBestPracticesCom::Application.routes.draw do
581
- root :to => 'home#index'
582
- end
583
- EOF
584
- runner.prepare('config/routes.rb', content)
585
- routes = RailsBestPractices::Prepares.routes
586
- routes.map(&:to_s).should == ["HomeController#index"]
587
- end
572
+ it "should add route for direct get/post" do
573
+ content =<<-EOF
574
+ RailsBestPracticesCom::Application.routes.draw do
575
+ get 'posts/show'
576
+ post '/posts' => 'posts#create'
577
+ put '/posts/:id' => 'posts#update'
578
+ delete '/post/:id' => 'posts#destroy'
579
+ get '/agb' => 'high_voltage/pages#show', :id => 'agb'
580
+ end
581
+ EOF
582
+ runner.prepare('config/routes.rb', content)
583
+ routes = Prepares.routes
584
+ routes.size.should == 5
585
+ routes.map(&:to_s).should == ["PostsController#show", "PostsController#create", "PostsController#update", "PostsController#destroy", "HighVoltage::PagesController#show"]
586
+ end
588
587
 
589
- it "should do nothing for default route" do
590
- content =<<-EOF
591
- RailsBestPracticesCom::Application.routes.draw do
592
- match ':controller(/:action(/:id(.:format)))'
593
- end
594
- EOF
595
- runner.prepare('config/routes.rb', content)
596
- routes = RailsBestPractices::Prepares.routes
597
- routes.size.should == 0
598
- end
588
+ it "should add routes for another get/post" do
589
+ content =<<-EOF
590
+ RailsBestPracticesCom::Application.routes.draw
591
+ get "/login", to: 'sessions#new', as: :login
592
+ end
593
+ EOF
594
+ runner.prepare('config/routes.rb', content)
595
+ routes = Prepares.routes
596
+ routes.size.should == 1
597
+ routes.first.to_s.should == "SessionsController#new"
598
+ end
599
599
 
600
- it "should do nothing for redirect" do
601
- content =<<-EOF
602
- RailsBestPracticesCom::Application.routes.draw do
603
- match "/stories/:name" => redirect("/posts/%{name}")
604
- match "/stories" => redirect {|p, req| "/posts/\#{req.subdomain}" }
605
- end
606
- EOF
607
- runner.prepare('config/routes.rb', content)
608
- routes = RailsBestPractices::Prepares.routes
609
- routes.size.should == 0
610
- end
600
+ it "should add match route" do
601
+ content =<<-EOF
602
+ RailsBestPracticesCom::Application.routes.draw do
603
+ match '/auth/:provider/callback' => 'authentications#create'
604
+ end
605
+ EOF
606
+ runner.prepare('config/routes.rb', content)
607
+ routes = Prepares.routes
608
+ routes.map(&:to_s).should == ["AuthenticationsController#create"]
609
+ end
611
610
 
612
- it "should parse customize route in nested resources" do
613
- content =<<-EOF
614
- RailsBestPracticesCom::Application.routes.draw do
615
- resources :posts do
616
- resources :comments
617
- post :stop
611
+ it "should add match route with all actions" do
612
+ content =<<-EOF
613
+ RailsBestPracticesCom::Application.routes.draw do
614
+ match 'internal/:action/*whatever', :controller => "internal"
615
+ end
616
+ EOF
617
+ runner.prepare('config/routes.rb', content)
618
+ routes = Prepares.routes
619
+ routes.map(&:to_s).should == ["InternalController#*"]
618
620
  end
619
- end
620
- EOF
621
- runner.prepare('config/routes.rb', content)
622
- routes = RailsBestPractices::Prepares.routes
623
- routes.last.to_s.should == "PostsController#stop"
624
- end
625
621
 
626
- it "should not take former resources for direct get/post" do
627
- content =<<-EOF
628
- RailsBestPracticesCom::Application.routes.draw do
629
- resources :posts
630
- post "sprints/stop"
631
- end
632
- EOF
633
- runner.prepare('config/routes.rb', content)
634
- routes = RailsBestPractices::Prepares.routes
635
- routes.last.to_s.should == "SprintsController#stop"
636
- end
622
+ it "should add root route" do
623
+ content =<<-EOF
624
+ RailsBestPracticesCom::Application.routes.draw do
625
+ root :to => 'home#index'
626
+ end
627
+ EOF
628
+ runner.prepare('config/routes.rb', content)
629
+ routes = Prepares.routes
630
+ routes.map(&:to_s).should == ["HomeController#index"]
631
+ end
632
+
633
+ it "should do nothing for default route" do
634
+ content =<<-EOF
635
+ RailsBestPracticesCom::Application.routes.draw do
636
+ match ':controller(/:action(/:id(.:format)))'
637
+ end
638
+ EOF
639
+ runner.prepare('config/routes.rb', content)
640
+ routes = Prepares.routes
641
+ routes.size.should == 0
642
+ end
643
+
644
+ it "should do nothing for redirect" do
645
+ content =<<-EOF
646
+ RailsBestPracticesCom::Application.routes.draw do
647
+ match "/stories/:name" => redirect("/posts/%{name}")
648
+ match "/stories" => redirect {|p, req| "/posts/\#{req.subdomain}" }
649
+ end
650
+ EOF
651
+ runner.prepare('config/routes.rb', content)
652
+ routes = Prepares.routes
653
+ routes.size.should == 0
654
+ end
637
655
 
638
- it "should not parse wrong route" do
639
- content =<<-EOF
640
- RailsBestPracticesCom::Application.routes.draw do
641
- match ':controller/:action' => '#index', :as => :auto_complete
656
+ it "should parse customize route in nested resources" do
657
+ content =<<-EOF
658
+ RailsBestPracticesCom::Application.routes.draw do
659
+ resources :posts do
660
+ resources :comments
661
+ post :stop
662
+ end
663
+ end
664
+ EOF
665
+ runner.prepare('config/routes.rb', content)
666
+ routes = Prepares.routes
667
+ routes.last.to_s.should == "PostsController#stop"
668
+ end
669
+
670
+ it "should not take former resources for direct get/post" do
671
+ content =<<-EOF
672
+ RailsBestPracticesCom::Application.routes.draw do
673
+ resources :posts
674
+ post "sprints/stop"
675
+ end
676
+ EOF
677
+ runner.prepare('config/routes.rb', content)
678
+ routes = Prepares.routes
679
+ routes.last.to_s.should == "SprintsController#stop"
680
+ end
681
+
682
+ it "should not parse wrong route" do
683
+ content =<<-EOF
684
+ RailsBestPracticesCom::Application.routes.draw do
685
+ match ':controller/:action' => '#index', :as => :auto_complete
686
+ end
687
+ EOF
688
+ runner.prepare('config/routes.rb', content)
689
+ routes = Prepares.routes
690
+ routes.size.should == 0
691
+ end
642
692
  end
643
- EOF
644
- runner.prepare('config/routes.rb', content)
645
- routes = RailsBestPractices::Prepares.routes
646
- routes.size.should == 0
647
693
  end
648
694
  end
649
695
  end