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.
- data/.travis.yml +4 -1
- data/Gemfile +0 -3
- data/Gemfile.lock +10 -9
- data/README.md +2 -0
- data/lib/rails_best_practices/analyzer.rb +40 -21
- data/lib/rails_best_practices/core.rb +1 -0
- data/lib/rails_best_practices/core/check.rb +12 -0
- data/lib/rails_best_practices/core/configs.rb +7 -0
- data/lib/rails_best_practices/core/error.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +11 -5
- data/lib/rails_best_practices/core/runner.rb +6 -2
- data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
- data/lib/rails_best_practices/prepares.rb +5 -0
- data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
- data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -0
- data/spec/rails_best_practices/analyzer_spec.rb +52 -32
- data/spec/rails_best_practices/core/check_spec.rb +64 -45
- data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
- data/spec/rails_best_practices/core/configs_spec.rb +7 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
- data/spec/rails_best_practices/core/error_spec.rb +28 -22
- data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
- data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
- data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
- data/spec/rails_best_practices/core/methods_spec.rb +37 -35
- data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
- data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
- data/spec/rails_best_practices/core/models_spec.rb +4 -2
- data/spec/rails_best_practices/core/modules_spec.rb +21 -19
- data/spec/rails_best_practices/core/nil_spec.rb +23 -21
- data/spec/rails_best_practices/core/routes_spec.rb +21 -14
- data/spec/rails_best_practices/core/runner_spec.rb +17 -15
- data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
- data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
- data/spec/spec_helper.rb +11 -20
- metadata +42 -26
- data/.watchr.example +0 -65
@@ -1,649 +1,695 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
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
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
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
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
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
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
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
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
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
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
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
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
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
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
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
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
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
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
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
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
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
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
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
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
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
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
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
|
-
|
458
|
-
|
459
|
-
|
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
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
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
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
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
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
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
|
-
|
505
|
-
|
506
|
-
|
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
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
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
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
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
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
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
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
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
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
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
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
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
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
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
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
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
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
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
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
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
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
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
|