js-routes 1.0.1 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ describe JsRoutes, "#default_serializer" do
2
+
3
+ before(:each) do
4
+ evaljs(JsRoutes.generate({}))
5
+ end
6
+
7
+ it "should provide this method" do
8
+ expect(evaljs("Routes.default_serializer({a: 1, b: [2,3], c: {d: 4, e: 5}, f: ''})")).to eq(
9
+ "a=1&b%5B%5D=2&b%5B%5D=3&c%5Bd%5D=4&c%5Be%5D=5&f="
10
+ )
11
+ end
12
+
13
+ end
@@ -9,6 +9,18 @@ describe JsRoutes do
9
9
 
10
10
  describe "generated js" do
11
11
  subject { JsRoutes.generate }
12
+
13
+ it "should set the default serializer when none is configured" do
14
+ is_expected.to match(%r(custom_serializer: null,\s+serialize: function\(object\) {\s+if \(\(this\.custom_serializer != null\) && this.get_object_type\(this\.custom_serializer\) === \"function\"\) {\s+return this\.custom_serializer\(object\);\s+} else {\s+return this\.default_serializer\(object\);\s+}\s+},))
15
+ end
16
+
17
+ it "should include a comment in the header" do
18
+ app_class = "App"
19
+
20
+ is_expected.to include("File generated by js-routes #{JsRoutes::VERSION}")
21
+ is_expected.to include("Based on Rails routes of #{app_class}")
22
+ end
23
+
12
24
  it "should call route function for each route" do
13
25
  is_expected.to include("inboxes_path: Utils.route(")
14
26
  end
@@ -13,6 +13,30 @@ describe JsRoutes, "options" do
13
13
  let(:_options) { {} }
14
14
  let(:_warnings) { true }
15
15
 
16
+ context "when serializer is specified" do
17
+ # define custom serializer
18
+ # this is a nonsense serializer, which always returns foo=bar
19
+ # for all inputs
20
+ let(:_presetup){ %q(function myCustomSerializer(object, prefix) { return "foo=bar"; }) }
21
+ let(:_options) { {:serializer => "myCustomSerializer"} }
22
+
23
+ it "should set configurable serializer" do
24
+ # expect the nonsense serializer above to have appened foo=bar
25
+ # to the end of the path
26
+ expect(evaljs(%q(Routes.inboxes_path()))).to eql("/inboxes?foo=bar")
27
+ end
28
+ end
29
+
30
+ context "when serializer is specified, but not function" do
31
+ let(:_presetup){ %q(var myCustomSerializer = 1) }
32
+ let(:_options) { {:serializer => "myCustomSerializer"} }
33
+
34
+ it "should set configurable serializer" do
35
+ # expect to use default
36
+ expect(evaljs(%q(Routes.inboxes_path({a: 1})))).to eql("/inboxes?a=1")
37
+ end
38
+ end
39
+
16
40
  context "when exclude is specified" do
17
41
 
18
42
  let(:_options) { {:exclude => /^admin_/} }
@@ -114,15 +138,18 @@ describe JsRoutes, "options" do
114
138
  expect(evaljs("Routes.inbox_path(1, {format: null})")).to eq(routes.inbox_path(1))
115
139
  end
116
140
 
117
- it "shouldn't include the format when {:format => false} is specified" do
118
- expect(evaljs("Routes.no_format_path()")).to eq(routes.no_format_path)
119
- end
120
141
 
121
142
  it "shouldn't require the format" do
143
+ pending if Rails.version < "4.0"
122
144
  expect(evaljs("Routes.json_only_path()")).to eq(routes.json_only_path(:format => 'json'))
123
145
  end
124
146
  end
125
147
 
148
+ it "shouldn't include the format when {:format => false} is specified" do
149
+ expect(evaljs("Routes.no_format_path()")).to eq(routes.no_format_path())
150
+ expect(evaljs("Routes.no_format_path({format: 'json'})")).to eq(routes.no_format_path(format: 'json'))
151
+ end
152
+
126
153
  describe "when namespace option is specified" do
127
154
  let(:_options) { {:namespace => "PHM"} }
128
155
  it "should use this namespace for routing" do
@@ -159,16 +186,24 @@ describe JsRoutes, "options" do
159
186
 
160
187
  describe "default_url_options" do
161
188
  context "with optional route parts" do
162
- let(:_options) { {:default_url_options => {:optional_id => "12", :format => "json"}}}
163
- it "should use this opions to fill optional parameters" do
164
- expect(evaljs("Routes.things_path()")).to eq(routes.things_path(:optional_id => 12, :format => "json"))
189
+ context "provided" do
190
+ let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
191
+ it "should use this opions to fill optional parameters" do
192
+ expect(evaljs("Routes.things_path()")).to eq(routes.things_path(:optional_id => 12, :format => "json"))
193
+ end
194
+ end
195
+
196
+ context "not provided" do
197
+ let(:_options) { { :default_url_options => { :format => "json" } } }
198
+ it "breaks" do
199
+ expect(evaljs("Routes.foo_all_path()")).to eq(routes.foo_all_path(:format => "json"))
200
+ end
165
201
  end
166
202
  end
167
203
 
168
204
  context "with required route parts" do
169
205
  let(:_options) { {:default_url_options => {:inbox_id => "12"}} }
170
206
  it "should use this opions to fill optional parameters" do
171
- pending
172
207
  expect(evaljs("Routes.inbox_messages_path()")).to eq(routes.inbox_messages_path(:inbox_id => 12))
173
208
  end
174
209
  end
@@ -284,19 +319,13 @@ describe JsRoutes, "options" do
284
319
  end
285
320
 
286
321
  context "when configuring with default_url_options" do
287
- context "when default host is not specified" do
288
- it "raises an error" do
289
- expect { JsRoutes.generate({ :url_links => true }) }.to raise_error RuntimeError
290
- end
291
- end
292
-
293
322
  context "when only host option is specified" do
294
323
  let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com"} } }
295
-
324
+
296
325
  it "uses the specified host, defaults protocol to http, defaults port to 80 (leaving it blank)" do
297
326
  expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com#{routes.inbox_path(1)}")
298
327
  end
299
-
328
+
300
329
  it "does not override protocol when specified in route" do
301
330
  expect(evaljs("Routes.new_session_url()")).to eq("https://example.com#{routes.new_session_path}")
302
331
  end
@@ -316,7 +345,7 @@ describe JsRoutes, "options" do
316
345
  it "uses the specified protocol and host, defaults port to 80 (leaving it blank)" do
317
346
  expect(evaljs("Routes.inbox_url(1)")).to eq("ftp://example.com#{routes.inbox_path(1)}")
318
347
  end
319
-
348
+
320
349
  it "does not override protocol when specified in route" do
321
350
  expect(evaljs("Routes.new_session_url()")).to eq("https://example.com#{routes.new_session_path}")
322
351
  end
@@ -340,11 +369,11 @@ describe JsRoutes, "options" do
340
369
  it "does not override protocol when specified in route" do
341
370
  expect(evaljs("Routes.new_session_url()")).to eq("https://example.com:3000#{routes.new_session_path}")
342
371
  end
343
-
372
+
344
373
  it "does not override host, protocol, or port when host is specified in route" do
345
- expect(evaljs("Routes.sso_url()")).to eq(routes.sso_url)
374
+ expect(evaljs("Routes.sso_url()")).to eq("http://sso.example.com:3000" + routes.sso_path)
346
375
  end
347
-
376
+
348
377
  it "does not override port when specified in route" do
349
378
  expect(evaljs("Routes.portals_url()")).to eq("http://example.com:8080#{routes.portals_path}")
350
379
  end
@@ -380,6 +409,47 @@ describe JsRoutes, "options" do
380
409
  end
381
410
  end
382
411
  end
412
+
413
+ context 'when window.location is present' do
414
+ let(:current_protocol) { 'http:' } # window.location.protocol includes the colon character
415
+ let(:current_hostname) { 'current.example.com' }
416
+ let(:current_port){ '' } # an empty string means port 80
417
+ let(:current_host) do
418
+ host = "#{current_hostname}"
419
+ host += ":#{current_port}" unless current_port == ''
420
+ host
421
+ end
422
+
423
+ before do
424
+ jscontext.eval("window = {'location': {'protocol': '#{current_protocol}', 'hostname': '#{current_hostname}', 'port': '#{current_port}', 'host': '#{current_host}'}}")
425
+ end
426
+
427
+ context "without specifying a default host" do
428
+ let(:_options) { { :url_links => true } }
429
+
430
+ it "uses the current host" do
431
+ expect(evaljs("Routes.inbox_path")).not_to be_nil
432
+ expect(evaljs("Routes.inbox_url")).not_to be_nil
433
+ expect(evaljs("Routes.inbox_url(1)")).to eq("http://current.example.com#{routes.inbox_path(1)}")
434
+ expect(evaljs("Routes.inbox_url(1, { test_key: \"test_val\" })")).to eq("http://current.example.com#{routes.inbox_path(1, :test_key => "test_val")}")
435
+ expect(evaljs("Routes.new_session_url()")).to eq("https://current.example.com#{routes.new_session_path}")
436
+ expect(evaljs("Routes.sso_url()")).to eq("http://sso.example.com#{routes.sso_path}")
437
+
438
+ end
439
+
440
+ it "uses host option as an argument" do
441
+ expect(evaljs("Routes.portals_url({host: 'another.com'})")).to eq(routes.portals_url(host: 'another.com'))
442
+ end
443
+
444
+ it "uses port option as an argument" do
445
+ expect(evaljs("Routes.portals_url({host: 'localhost', port: 8080})")).to eq(routes.portals_url(host: 'localhost', port: 8080))
446
+ end
447
+
448
+ it "uses protocol option as an argument" do
449
+ expect(evaljs("Routes.portals_url({host: 'localhost', protocol: 'https'})")).to eq(routes.portals_url(protocol: 'https', host: 'localhost'))
450
+ end
451
+ end
452
+ end
383
453
  end
384
454
 
385
455
  describe "when the compact mode is enabled" do
@@ -397,7 +467,7 @@ describe JsRoutes, "options" do
397
467
  example.run
398
468
  end
399
469
  end
400
-
470
+
401
471
  let(:_options) { { :compact => true, :url_links => "http://localhost" } }
402
472
  it "should not strip urls" do
403
473
  expect(evaljs("Routes.inbox(1)")).to eq(routes.inbox_path(1))
@@ -54,11 +54,43 @@ describe JsRoutes, "compatibility with Rails" do
54
54
  expect(evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})")).to eq(routes.inbox_path(1, :expanded => true, :anchor => "hello"))
55
55
  end
56
56
 
57
+ it "should use irregular ActiveSupport pluralizations" do
58
+ expect(evaljs("Routes.budgies_path()")).to eq(routes.budgies_path)
59
+ expect(evaljs("Routes.budgie_path(1)")).to eq(routes.budgie_path(1))
60
+ expect(evaljs("Routes.budgy_path")).to eq(nil)
61
+ expect(evaljs("Routes.budgie_descendents_path(1)")).to eq(routes.budgie_descendents_path(1))
62
+ end
63
+
64
+ describe "when route has defaults" do
65
+ it "should support route default format" do
66
+ expect(evaljs("Routes.api_purchases_path()")).to eq(routes.api_purchases_path)
67
+ end
68
+
69
+ it 'should support route default subdomain' do
70
+ # root inside namespace is broken
71
+ # https://github.com/rails/rails/pull/23235
72
+ pending if Rails.version == '5.0.0'
73
+ expect(evaljs("Routes.backend_root_path()")).to eq(routes.backend_root_path)
74
+ end
75
+
76
+ it "should support default format override" do
77
+ expect(evaljs("Routes.api_purchases_path({format: 'xml'})")).to eq(routes.api_purchases_path(format: 'xml'))
78
+ end
79
+
80
+ it "doesn't apply defaults to path" do
81
+ expect(evaljs("Routes.with_defaults_path()")).to eq(routes.with_defaults_path)
82
+ end
83
+ end
84
+
57
85
  context "with rails engines" do
58
86
  it "should support simple route" do
59
87
  expect(evaljs("Routes.blog_app_posts_path()")).to eq(blog_routes.posts_path())
60
88
  end
61
89
 
90
+ it "should support root route" do
91
+ expect(evaljs("Routes.blog_app_path()")).to eq(routes.blog_app_path())
92
+ end
93
+
62
94
  it "should support route with parameters" do
63
95
  expect(evaljs("Routes.blog_app_post_path(1)")).to eq(blog_routes.post_path(1))
64
96
  end
@@ -74,6 +106,10 @@ describe JsRoutes, "compatibility with Rails" do
74
106
  expect(evaljs("Routes.json_only_path({format: 'json'})")).to eq(routes.json_only_path(:format => 'json'))
75
107
  end
76
108
 
109
+ it "should serialize object with empty string value" do
110
+ expect(evaljs("Routes.inboxes_path({a: '', b: 1})")).to eq(routes.inboxes_path(:a => '', :b => 1))
111
+ end
112
+
77
113
  it "should support utf-8 route" do
78
114
  expect(evaljs("Routes.hello_path()")).to eq(routes.hello_path)
79
115
  end
@@ -141,48 +177,8 @@ describe JsRoutes, "compatibility with Rails" do
141
177
  expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(routes.search_path(:q => 'hello'))
142
178
  end
143
179
 
144
- it "should ignore null parameters" do
145
- pending
146
- expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(routes.inboxes_path(:hello => {world: nil}))
147
- end
148
- end
149
-
150
- context "when jQuery is present" do
151
- before do
152
- evaljs("window.jQuery = {};")
153
- jscontext[:parameterizeFunc] = lambda {|object| _value.to_param}
154
- evaljs("window.jQuery.param = parameterizeFunc")
155
- end
156
-
157
- shared_examples_for "serialization" do
158
- it "should support serialization of objects" do
159
- expect(evaljs("window.jQuery.param(#{_value.to_json})")).to eq(_value.to_param)
160
- expect(evaljs("Routes.inboxes_path(#{_value.to_json})")).to eq(routes.inboxes_path(_value))
161
- expect(evaljs("Routes.inbox_path(1, #{_value.to_json})")).to eq(routes.inbox_path(1, _value))
162
- end
163
- end
164
- context "when parameters is a hash" do
165
- let(:_value) do
166
- {:a => {:b => 'c'}, :q => [1,2]}
167
- end
168
- it_should_behave_like 'serialization'
169
- end
170
- context "when parameters is null" do
171
- let(:_value) do
172
- {:hello => {world: nil}}
173
- end
174
- it_should_behave_like 'serialization'
175
- end
176
- context "when parameters is null" do
177
- let(:_value) do
178
- nil
179
- end
180
-
181
- before do
182
- pending("This test is invalid for nil/null and jruby #{JRUBY_VERSION}") if defined?(JRUBY_VERSION) && '1.7.13' == JRUBY_VERSION
183
- end
184
-
185
- it_should_behave_like 'serialization'
180
+ it "should support nested object null parameters" do
181
+ expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(routes.inboxes_path(:hello => {:world => nil}))
186
182
  end
187
183
  end
188
184
 
@@ -204,17 +200,11 @@ describe JsRoutes, "compatibility with Rails" do
204
200
  expect(evaljs("Routes.thing_path(null, 5)")).to eq(routes.thing_path(nil, 5))
205
201
  end
206
202
 
207
- # Fail for rails 4.2. Reason: https://github.com/rails/rails/issues/12178
208
203
  it "should treat undefined as non-given optional part" do
209
- # TODO: remove me after release of rails 4.2.1 (change Appraisals to "~> 4.2.1")
210
- pending("This test is invalid for rails 4.2. Reason: https://github.com/rails/rails/issues/12178") if [4, 2, 0] == [Rails::VERSION::MAJOR, Rails::VERSION::MINOR, Rails::VERSION::TINY]
211
204
  expect(evaljs("Routes.thing_path(5, {optional_id: undefined})")).to eq(routes.thing_path(5, :optional_id => nil))
212
205
  end
213
206
 
214
- # Fail for rails 4.2. Reason: https://github.com/rails/rails/issues/12178
215
207
  it "should treat null as non-given optional part" do
216
- # TODO: remove me after release of rails 4.2.1 (change Appraisals to "~> 4.2.1")
217
- pending("This test is invalid for rails 4.2. Reason: https://github.com/rails/rails/issues/12178") if [4, 2, 0] == [Rails::VERSION::MAJOR, Rails::VERSION::MINOR, Rails::VERSION::TINY]
218
208
  expect(evaljs("Routes.thing_path(5, {optional_id: null})")).to eq(routes.thing_path(5, :optional_id => nil))
219
209
  end
220
210
  end
@@ -224,6 +214,11 @@ describe JsRoutes, "compatibility with Rails" do
224
214
  expect(evaljs("Routes.things_path({optional_id: 5})")).to eq(routes.things_path(:optional_id => 5))
225
215
  end
226
216
 
217
+ context "on nested optional parts" do
218
+ it "should include everything that is not optional" do
219
+ expect(evaljs("Routes.classic_path({controller: 'classic', action: 'edit'})")).to eq(routes.classic_path(controller: :classic, action: :edit))
220
+ end
221
+ end
227
222
  end
228
223
  end
229
224
 
@@ -321,7 +316,7 @@ describe JsRoutes, "compatibility with Rails" do
321
316
  end
322
317
  end
323
318
 
324
- context "when params" do
319
+ describe "required_params" do
325
320
  it "should show inbox spec" do
326
321
  expect(evaljs("Routes.inbox_path.required_params").to_a).to eq(["id"])
327
322
  end
@@ -330,4 +325,6 @@ describe JsRoutes, "compatibility with Rails" do
330
325
  expect(evaljs("Routes.inbox_message_path.required_params").to_a).to eq(["inbox_id", "id"])
331
326
  end
332
327
  end
328
+
329
+
333
330
  end
@@ -55,19 +55,13 @@ describe "after Rails initialization" do
55
55
  FileUtils.rm_f(TEST_ASSET_PATH)
56
56
  end
57
57
 
58
- it "should have registered a preprocessor" do
59
- pps = Rails.application.assets.preprocessors
60
- js_pps = pps['application/javascript']
61
- klass = sprockets_v3? ? 'LegacyProcProcessor' : 'Processor'
62
- expect(js_pps.map(&:to_s)).to include("Sprockets::#{klass} (js-routes_dependent_on_routes)")
63
- end
64
-
65
58
  context "the preprocessor" do
66
59
  before(:each) do
60
+ path = Rails.root.join('config','routes.rb').to_s
67
61
  if sprockets_v3?
68
- expect_any_instance_of(Sprockets::Context).to receive(:depend_on).with(Rails.root.join('config','routes.rb').to_s)
62
+ expect_any_instance_of(Sprockets::Context).to receive(:depend_on).with(path)
69
63
  else
70
- expect(ctx).to receive(:depend_on).with(Rails.root.join('config','routes.rb').to_s)
64
+ expect(ctx).to receive(:depend_on).with(path)
71
65
  end
72
66
  end
73
67
  let!(:ctx) do
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ $:.unshift(File.dirname(__FILE__))
5
5
  require 'rspec'
6
6
  require 'rails/all'
7
7
  require 'js-routes'
8
- require "active_support/core_ext/hash/slice"
8
+ require 'active_support/core_ext/hash/slice'
9
9
  require 'coffee-script'
10
10
  # fix ends_with? error for rails 3.2
11
11
  require 'active_support/core_ext/string/starts_ends_with' if 3 == Rails::VERSION::MAJOR
@@ -14,7 +14,7 @@ if defined?(JRUBY_VERSION)
14
14
  require 'rhino'
15
15
  JS_LIB_CLASS = Rhino
16
16
  else
17
- require "v8"
17
+ require 'v8'
18
18
  JS_LIB_CLASS = V8
19
19
  end
20
20
 
@@ -42,6 +42,10 @@ def blog_routes
42
42
  BlogEngine::Engine.routes.url_helpers
43
43
  end
44
44
 
45
+ ActiveSupport::Inflector.inflections do |inflect|
46
+ inflect.irregular "budgie", "budgies"
47
+ end
48
+
45
49
 
46
50
  module BlogEngine
47
51
  class Engine < Rails::Engine
@@ -66,59 +70,6 @@ class App < Rails::Application
66
70
  config.root = File.expand_path('../dummy', __FILE__)
67
71
  end
68
72
 
69
- def draw_routes
70
-
71
- BlogEngine::Engine.routes.draw do
72
- root to: "application#index"
73
- resources :posts
74
- end
75
- App.routes.draw do
76
-
77
- get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
78
-
79
- resources :inboxes do
80
- resources :messages do
81
- resources :attachments
82
- end
83
- end
84
-
85
- root :to => "inboxes#index"
86
-
87
- namespace :admin do
88
- resources :users
89
- end
90
-
91
- scope "/returns/:return" do
92
- resources :objects
93
- end
94
- resources :returns
95
-
96
- scope "(/optional/:optional_id)" do
97
- resources :things
98
- end
99
-
100
- get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
101
-
102
- get 'books/*section/:title' => 'books#show', :as => :book
103
- get 'books/:title/*section' => 'books#show', :as => :book_title
104
-
105
- mount BlogEngine::Engine => "/blog", :as => :blog_app
106
-
107
- get '/no_format' => "foo#foo", :format => false, :as => :no_format
108
-
109
- get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
110
-
111
- get '/привет' => "foo#foo", :as => :hello
112
- get '(/o/:organization)/search/:q' => "foo#foo", as: :search
113
-
114
- resources :sessions, :only => [:new, :create, :destroy], :protocol => 'https'
115
-
116
- get '/' => 'sso#login', host: 'sso.example.com', as: :sso
117
-
118
- resources :portals, :port => 8080
119
- end
120
-
121
- end
122
73
 
123
74
  # prevent warning
124
75
  Rails.configuration.active_support.deprecation = :log
@@ -135,7 +86,9 @@ RSpec.configure do |config|
135
86
  config.before(:all) do
136
87
  # compile all js files begin
137
88
  Dir["#{File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))}/**/*.coffee"].each do |coffee|
138
- File.open(coffee.gsub(/\.coffee$/, ""), 'w') {|f| f.write(CoffeeScript.compile(File.read(coffee))) }
89
+ File.open(coffee.gsub(/\.coffee$/, ""), 'w') do |f|
90
+ f.write(CoffeeScript.compile(File.read(coffee)).lstrip)
91
+ end
139
92
  end
140
93
  # compile all js files end
141
94
  draw_routes
@@ -143,6 +96,27 @@ RSpec.configure do |config|
143
96
 
144
97
  config.before :each do
145
98
  evaljs("var window = this;", true)
146
- jscontext[:log] = lambda {|context, value| puts value.inspect}
99
+
100
+ def inspectify(value)
101
+ case value
102
+ when V8::Array
103
+ value.map do |v|
104
+ inspectify(v)
105
+ end
106
+ when V8::Object
107
+ require 'byebug'; byebug
108
+ value.to_h.map do |k,v|
109
+ [k, inspectify(v)]
110
+ end.to_h
111
+ when String, nil, Fixnum, FalseClass, TrueClass
112
+ value
113
+ else
114
+ raise "wtf #{value.class}?"
115
+ end
116
+
117
+ end
118
+ jscontext[:log] = lambda do |context, value|
119
+ puts inspectify(value).to_json
120
+ end
147
121
  end
148
122
  end
@@ -0,0 +1,71 @@
1
+ def draw_routes
2
+
3
+ BlogEngine::Engine.routes.draw do
4
+ root to: "application#index"
5
+ resources :posts
6
+ end
7
+ App.routes.draw do
8
+
9
+ get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
10
+
11
+ resources :inboxes do
12
+ resources :messages do
13
+ resources :attachments
14
+ end
15
+ end
16
+
17
+ root :to => "inboxes#index"
18
+
19
+ namespace :admin do
20
+ resources :users
21
+ end
22
+
23
+ scope "/returns/:return" do
24
+ resources :objects
25
+ end
26
+ resources :returns
27
+
28
+ scope "(/optional/:optional_id)" do
29
+ resources :things
30
+ end
31
+
32
+ get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
33
+
34
+ get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
35
+ get '/other_optional(/*optional_id)' => 'foo#foo', :as => :foo_all
36
+
37
+ get 'books/*section/:title' => 'books#show', :as => :book
38
+ get 'books/:title/*section' => 'books#show', :as => :book_title
39
+
40
+ mount BlogEngine::Engine => "/blog", :as => :blog_app
41
+
42
+ get '/no_format' => "foo#foo", :format => false, :as => :no_format
43
+
44
+ get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
45
+
46
+ get '/привет' => "foo#foo", :as => :hello
47
+ get '(/o/:organization)/search/:q' => "foo#foo", as: :search
48
+
49
+ resources :sessions, :only => [:new, :create, :destroy], :protocol => 'https'
50
+
51
+ get '/' => 'sso#login', host: 'sso.example.com', as: :sso
52
+
53
+ resources :portals, :port => 8080
54
+
55
+ get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: :true
56
+
57
+ namespace :api, format: true, defaults: {format: 'json'} do
58
+ get "/purchases" => "purchases#index"
59
+ end
60
+
61
+ resources :budgies do
62
+ get "descendents"
63
+ end
64
+
65
+ namespace :backend, path: '', constraints: {subdomain: 'backend'} do
66
+ root to: 'backend#index'
67
+ end
68
+
69
+ end
70
+
71
+ end