utopia 1.0.11 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/bin/utopia +1 -1
- data/lib/utopia/content.rb +10 -12
- data/lib/utopia/content/link.rb +8 -11
- data/lib/utopia/content/links.rb +1 -1
- data/lib/utopia/content/node.rb +8 -7
- data/lib/utopia/controller.rb +40 -39
- data/lib/utopia/controller/action.rb +14 -12
- data/lib/utopia/controller/base.rb +31 -32
- data/lib/utopia/controller/rewrite.rb +104 -0
- data/lib/utopia/exception_handler.rb +1 -1
- data/lib/utopia/extensions/rack.rb +21 -21
- data/lib/utopia/http.rb +14 -9
- data/lib/utopia/localization.rb +1 -1
- data/lib/utopia/middleware.rb +3 -0
- data/lib/utopia/path.rb +81 -25
- data/lib/utopia/path/matcher.rb +94 -0
- data/lib/utopia/redirector.rb +4 -4
- data/lib/utopia/session/encrypted_cookie.rb +1 -1
- data/lib/utopia/static.rb +1 -1
- data/lib/utopia/tags/node.rb +1 -1
- data/lib/utopia/version.rb +1 -1
- data/setup/site/config.ru +1 -1
- data/spec/utopia/content/link_spec.rb +8 -8
- data/spec/utopia/content/node_spec.rb +1 -1
- data/spec/utopia/content_spec.rb +3 -3
- data/spec/utopia/content_spec.ru +1 -1
- data/spec/utopia/controller/action_spec.rb +61 -0
- data/spec/utopia/controller/middleware_spec.rb +71 -0
- data/spec/utopia/controller/middleware_spec.ru +4 -0
- data/spec/utopia/controller/middleware_spec/controller/controller.rb +24 -0
- data/spec/utopia/{pages → controller/middleware_spec}/controller/index.xnode +0 -0
- data/spec/utopia/{pages → controller/middleware_spec}/controller/nested/controller.rb +0 -0
- data/spec/utopia/controller/rewrite_spec.rb +66 -0
- data/spec/utopia/{controller_spec.rb → controller/sequence_spec.rb} +11 -84
- data/spec/utopia/exception_handler_spec.rb +3 -3
- data/spec/utopia/exception_handler_spec.ru +2 -2
- data/spec/utopia/exception_handler_spec/controller.rb +15 -0
- data/spec/utopia/path/matcher_spec.rb +65 -0
- data/spec/utopia/rack_spec.rb +0 -12
- data/utopia.gemspec +1 -1
- metadata +27 -14
- data/spec/utopia/controller_spec.ru +0 -4
- data/spec/utopia/pages/controller/controller.rb +0 -43
data/lib/utopia/redirector.rb
CHANGED
@@ -37,14 +37,14 @@ module Utopia
|
|
37
37
|
|
38
38
|
class Redirector
|
39
39
|
# This redirects directories to the directory + 'index'
|
40
|
-
DIRECTORY_INDEX = [/^(.*)\/$/, lambda{|prefix| [307, {
|
40
|
+
DIRECTORY_INDEX = [/^(.*)\/$/, lambda{|prefix| [307, {HTTP::LOCATION => "#{prefix}index"}, []]}]
|
41
41
|
|
42
42
|
# Redirects a whole source tree to a destination tree, given by the roots.
|
43
43
|
def self.moved(source_root, destination_root)
|
44
44
|
return [
|
45
45
|
/^#{Regexp.escape(source_root)}(.*)$/,
|
46
46
|
lambda do |match|
|
47
|
-
[301, {
|
47
|
+
[301, {HTTP::LOCATION => (destination_root + match[1]).to_s}, []]
|
48
48
|
end
|
49
49
|
]
|
50
50
|
end
|
@@ -88,7 +88,7 @@ module Utopia
|
|
88
88
|
|
89
89
|
public
|
90
90
|
|
91
|
-
def initialize(app, options
|
91
|
+
def initialize(app, **options)
|
92
92
|
@app = app
|
93
93
|
|
94
94
|
@strings = options[:strings] || {}
|
@@ -112,7 +112,7 @@ module Utopia
|
|
112
112
|
if uri.respond_to? :call
|
113
113
|
return uri.call(match_data)
|
114
114
|
else
|
115
|
-
return [301, {
|
115
|
+
return [301, {HTTP::LOCATION => uri.to_s}, []]
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -28,7 +28,7 @@ module Utopia
|
|
28
28
|
module Session
|
29
29
|
# Stores all session data client side using a private symmetric encrpytion key.
|
30
30
|
class EncryptedCookie
|
31
|
-
def initialize(app, options
|
31
|
+
def initialize(app, **options)
|
32
32
|
@app = app
|
33
33
|
@cookie_name = options.delete(:cookie_name) || (RACK_SESSION + ".encrypted")
|
34
34
|
|
data/lib/utopia/static.rb
CHANGED
data/lib/utopia/tags/node.rb
CHANGED
data/lib/utopia/version.rb
CHANGED
data/setup/site/config.ru
CHANGED
@@ -8,7 +8,7 @@ Encoding.default_internal = Encoding::UTF_8
|
|
8
8
|
RACK_ENV = ENV.fetch('RACK_ENV', :development).to_sym unless defined?(RACK_ENV)
|
9
9
|
|
10
10
|
# Allow loading library code from lib directory:
|
11
|
-
$LOAD_PATH << File.expand_path("
|
11
|
+
$LOAD_PATH << File.expand_path("lib", __dir__)
|
12
12
|
|
13
13
|
require 'utopia'
|
14
14
|
require 'rack/cache'
|
@@ -24,21 +24,21 @@ require 'utopia/content/link'
|
|
24
24
|
|
25
25
|
module Utopia::Content::LinkSpec
|
26
26
|
describe Utopia::Content::Link.new(:file, "/foo/bar/baz") do
|
27
|
-
it "should
|
27
|
+
it "should be valid file link" do
|
28
28
|
expect(subject.name).to be == "baz"
|
29
29
|
expect(subject.path).to be == Utopia::Path.create("/foo/bar/baz")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe Utopia::Content::Link.new(:directory, "/foo/bar/index") do
|
34
|
-
it "should
|
34
|
+
it "should be valid directory link" do
|
35
35
|
expect(subject.name).to be == "bar"
|
36
36
|
expect(subject.path).to be == Utopia::Path.create("/foo/bar/index")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe Utopia::Content::Link.new(:virtual, "bob") do
|
41
|
-
it "should
|
41
|
+
it "should be valid virtual link" do
|
42
42
|
expect(subject.name).to be == "bob"
|
43
43
|
expect(subject.path).to be == nil
|
44
44
|
end
|
@@ -46,7 +46,7 @@ module Utopia::Content::LinkSpec
|
|
46
46
|
|
47
47
|
describe Utopia::Content::Links do
|
48
48
|
it "should give a list of links" do
|
49
|
-
links = Utopia::Content::Links.index(File.expand_path("
|
49
|
+
links = Utopia::Content::Links.index(File.expand_path("links", __dir__), Utopia::Path.create("/"))
|
50
50
|
|
51
51
|
expect(links.size).to be == 3
|
52
52
|
|
@@ -69,13 +69,13 @@ module Utopia::Content::LinkSpec
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should filter links by name" do
|
72
|
-
links = Utopia::Content::Links.index(File.expand_path("
|
72
|
+
links = Utopia::Content::Links.index(File.expand_path("links", __dir__), Utopia::Path.create("/"), name: /foo/)
|
73
73
|
|
74
74
|
expect(links.size).to be == 1
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should select localized links" do
|
78
|
-
root = File.expand_path("
|
78
|
+
root = File.expand_path("links", __dir__)
|
79
79
|
|
80
80
|
# Select both test links
|
81
81
|
links = Utopia::Content::Links.index(root, Utopia::Path.create("/foo"))
|
@@ -86,7 +86,7 @@ module Utopia::Content::LinkSpec
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should read correct link order for en" do
|
89
|
-
root = File.expand_path("
|
89
|
+
root = File.expand_path("localized", __dir__)
|
90
90
|
|
91
91
|
# Select both test links
|
92
92
|
links = Utopia::Content::Links.index(root, Utopia::Path.create("/"), variant: 'en')
|
@@ -95,7 +95,7 @@ module Utopia::Content::LinkSpec
|
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should read correct link order for zh" do
|
98
|
-
root = File.expand_path("
|
98
|
+
root = File.expand_path("localized", __dir__)
|
99
99
|
|
100
100
|
# Select both test links
|
101
101
|
links = Utopia::Content::Links.index(root, Utopia::Path.create("/"), variant: 'zh')
|
@@ -22,7 +22,7 @@ require 'utopia/content'
|
|
22
22
|
|
23
23
|
module Utopia::ContentSpec
|
24
24
|
describe Utopia::Content::Node do
|
25
|
-
let(:root) {File.expand_path("
|
25
|
+
let(:root) {File.expand_path("node", __dir__)}
|
26
26
|
let(:content) {Utopia::Content.new(lambda{}, root: root)}
|
27
27
|
|
28
28
|
it "should list siblings in correct order" do
|
data/spec/utopia/content_spec.rb
CHANGED
@@ -25,12 +25,12 @@ module Utopia::ContentSpec
|
|
25
25
|
describe Utopia::Content do
|
26
26
|
include Rack::Test::Methods
|
27
27
|
|
28
|
-
let(:app) {Rack::Builder.parse_file(File.expand_path('
|
28
|
+
let(:app) {Rack::Builder.parse_file(File.expand_path('content_spec.ru', __dir__)).first}
|
29
29
|
|
30
30
|
it "should get a local path" do
|
31
31
|
get '/node/index'
|
32
32
|
|
33
|
-
expect(last_response.body).to be == File.expand_path('
|
33
|
+
expect(last_response.body).to be == File.expand_path('pages/node', __dir__)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should successfully redirect to the index page" do
|
@@ -66,7 +66,7 @@ module Utopia::ContentSpec
|
|
66
66
|
end
|
67
67
|
|
68
68
|
describe Utopia::Content do
|
69
|
-
let(:root) {File.expand_path("
|
69
|
+
let(:root) {File.expand_path("pages", __dir__)}
|
70
70
|
let(:content) {Utopia::Content.new(lambda{}, root: root, cache_templates: true)}
|
71
71
|
|
72
72
|
it "should parse file and expand variables" do
|
data/spec/utopia/content_spec.ru
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'utopia/controller'
|
24
|
+
|
25
|
+
module Utopia::Controller::ActionSpec
|
26
|
+
describe Utopia::Controller::Action do
|
27
|
+
it "should resolve callbacks" do
|
28
|
+
actions = Utopia::Controller::Action.new
|
29
|
+
|
30
|
+
specific_action = actions.define(['a', 'b', 'c']) {puts 'specific_action'}
|
31
|
+
indirect_action = actions.define(['**']) {puts 'indirect_action'}
|
32
|
+
indirect_named_action = actions.define(['**', 'r']) {puts 'indirect_named_action'}
|
33
|
+
|
34
|
+
expect(specific_action).to_not be == indirect_action
|
35
|
+
expect(indirect_action).to_not be == indirect_named_action
|
36
|
+
|
37
|
+
expect(actions.select(['a', 'b', 'c'])).to be == [indirect_action, specific_action]
|
38
|
+
expect(actions.select(['q'])).to be == [indirect_action]
|
39
|
+
|
40
|
+
expect(actions.select(['q', 'r'])).to be == [indirect_action, indirect_named_action]
|
41
|
+
expect(actions.select(['q', 'r', 's'])).to be == [indirect_action]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be greedy matching" do
|
45
|
+
actions = Utopia::Controller::Action.new
|
46
|
+
|
47
|
+
greedy_action = actions.define(['**', 'r']) {puts 'greedy_action'}
|
48
|
+
|
49
|
+
expect(actions.select(['g', 'r'])).to be_include greedy_action
|
50
|
+
expect(actions.select(['r'])).to be_include greedy_action
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should match patterns" do
|
54
|
+
actions = Utopia::Controller::Action.new
|
55
|
+
|
56
|
+
variable_action = actions.define(['*', 'summary', '*']) {puts 'variable_action'}
|
57
|
+
|
58
|
+
expect(actions.select(['10', 'summary', '20'])).to be_include variable_action
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'rack/mock'
|
24
|
+
require 'rack/test'
|
25
|
+
require 'utopia/controller'
|
26
|
+
|
27
|
+
module Utopia::Controller::MiddlewareSpec
|
28
|
+
describe Utopia::Controller do
|
29
|
+
include Rack::Test::Methods
|
30
|
+
|
31
|
+
let(:app) {Rack::Builder.parse_file(File.expand_path('../middleware_spec.ru', __FILE__)).first}
|
32
|
+
|
33
|
+
it "should successfully call the controller method" do
|
34
|
+
get "/controller/hello-world"
|
35
|
+
|
36
|
+
expect(last_response.status).to be == 200
|
37
|
+
expect(last_response.body).to be == 'Hello World'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should successfully call the recursive controller method" do
|
41
|
+
get "/controller/recursive/hello-world"
|
42
|
+
|
43
|
+
expect(last_response.status).to be == 200
|
44
|
+
expect(last_response.body).to be == 'Hello World'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should successfully call the controller method" do
|
48
|
+
get "/controller/flat"
|
49
|
+
|
50
|
+
expect(last_response.status).to be == 200
|
51
|
+
expect(last_response.body).to be == 'flat'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should successfully call the recursive controller method" do
|
55
|
+
get "/controller/recursive/flat"
|
56
|
+
|
57
|
+
expect(last_response.status).to be == 404
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should perform ignore the request" do
|
61
|
+
get '/controller/ignore'
|
62
|
+
expect(last_response.status).to be == 404
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should redirect the request" do
|
66
|
+
get '/controller/redirect'
|
67
|
+
expect(last_response.status).to be == 302
|
68
|
+
expect(last_response.headers['Location']).to be == 'bar'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
on 'flat' do
|
3
|
+
success! content: "flat"
|
4
|
+
end
|
5
|
+
|
6
|
+
on '**/hello-world' do
|
7
|
+
success! content: @hello_world
|
8
|
+
end
|
9
|
+
|
10
|
+
on '**' do
|
11
|
+
@hello_world = "Hello World"
|
12
|
+
end
|
13
|
+
|
14
|
+
on 'ignore' do
|
15
|
+
ignore!
|
16
|
+
end
|
17
|
+
|
18
|
+
on 'redirect' do
|
19
|
+
redirect! 'bar'
|
20
|
+
end
|
21
|
+
|
22
|
+
on 'index' do
|
23
|
+
success! content: 'Hello World'
|
24
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'rack/mock'
|
24
|
+
|
25
|
+
require 'utopia/controller'
|
26
|
+
|
27
|
+
module Utopia::Controller::RewriteSpec
|
28
|
+
describe Utopia::Controller do
|
29
|
+
class TestController < Utopia::Controller::Base
|
30
|
+
prepend Utopia::Controller::Rewrite
|
31
|
+
|
32
|
+
on 'edit' do |request, path|
|
33
|
+
@edit = true
|
34
|
+
end
|
35
|
+
|
36
|
+
attr :edit
|
37
|
+
|
38
|
+
rewrite.extract_prefix user_id: Integer, summary: 'summary', order_id: Integer
|
39
|
+
|
40
|
+
attr :user_id
|
41
|
+
attr :order_id
|
42
|
+
|
43
|
+
def self.uri_path
|
44
|
+
Utopia::Path['/']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:controller) {TestController.new}
|
49
|
+
|
50
|
+
def mock_request(*args)
|
51
|
+
request = Rack::Request.new(Rack::MockRequest.env_for(*args))
|
52
|
+
return request, Utopia::Path[request.path_info]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should match path prefix and extract parameters" do
|
56
|
+
request, path, variables = mock_request("/10/summary/20/edit")
|
57
|
+
relative_path = path - controller.class.uri_path
|
58
|
+
|
59
|
+
controller.process!(request, relative_path)
|
60
|
+
|
61
|
+
expect(controller.user_id).to be == 10
|
62
|
+
expect(controller.order_id).to be == 20
|
63
|
+
expect(controller.edit).to be true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -24,35 +24,7 @@ require 'rack/mock'
|
|
24
24
|
require 'rack/test'
|
25
25
|
require 'utopia/controller'
|
26
26
|
|
27
|
-
module Utopia::
|
28
|
-
describe Utopia::Controller::Action do
|
29
|
-
it "should resolve callbacks" do
|
30
|
-
actions = Utopia::Controller::Action.new
|
31
|
-
|
32
|
-
specific_action = actions.define(['a', 'b', 'c']) {puts 'specific_action'}
|
33
|
-
indirect_action = actions.define(['**']) {puts 'indirect_action'}
|
34
|
-
indirect_named_action = actions.define(['**', 'r']) {puts 'indirect_named_action'}
|
35
|
-
|
36
|
-
expect(specific_action).to_not be == indirect_action
|
37
|
-
expect(indirect_action).to_not be == indirect_named_action
|
38
|
-
|
39
|
-
expect(actions.select(['a', 'b', 'c'])).to be == [indirect_action, specific_action]
|
40
|
-
expect(actions.select(['q'])).to be == [indirect_action]
|
41
|
-
|
42
|
-
expect(actions.select(['q', 'r'])).to be == [indirect_action, indirect_named_action]
|
43
|
-
expect(actions.select(['q', 'r', 's'])).to be == [indirect_action]
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should be greedy matching" do
|
47
|
-
actions = Utopia::Controller::Action.new
|
48
|
-
|
49
|
-
greedy_action = actions.define(['**', 'r']) {puts 'greedy_action'}
|
50
|
-
|
51
|
-
expect(actions.select(['g', 'r'])).to be_include greedy_action
|
52
|
-
expect(actions.select(['r'])).to be_include greedy_action
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
27
|
+
module Utopia::Controller::SequenceSpec
|
56
28
|
class TestController < Utopia::Controller::Base
|
57
29
|
on 'success' do
|
58
30
|
success!
|
@@ -105,62 +77,13 @@ module Utopia::ControllerSpec
|
|
105
77
|
end
|
106
78
|
end
|
107
79
|
|
108
|
-
describe Utopia::Controller do
|
109
|
-
include Rack::Test::Methods
|
110
|
-
|
111
|
-
let(:app) {Rack::Builder.parse_file(File.expand_path('../controller_spec.ru', __FILE__)).first}
|
112
|
-
|
113
|
-
it "should successfully call the controller method" do
|
114
|
-
get "/controller/hello-world"
|
115
|
-
|
116
|
-
expect(last_response.status).to be == 200
|
117
|
-
expect(last_response.body).to be == 'Hello World'
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should successfully call the recursive controller method" do
|
121
|
-
get "/controller/recursive/hello-world"
|
122
|
-
|
123
|
-
expect(last_response.status).to be == 200
|
124
|
-
expect(last_response.body).to be == 'Hello World'
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should successfully call the controller method" do
|
128
|
-
get "/controller/flat"
|
129
|
-
|
130
|
-
expect(last_response.status).to be == 200
|
131
|
-
expect(last_response.body).to be == 'flat'
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should successfully call the recursive controller method" do
|
135
|
-
get "/controller/recursive/flat"
|
136
|
-
|
137
|
-
expect(last_response.status).to be == 404
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should perform ignore the request" do
|
141
|
-
get '/controller/ignore'
|
142
|
-
expect(last_response.status).to be == 404
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should redirect the request" do
|
146
|
-
get '/controller/redirect'
|
147
|
-
expect(last_response.status).to be == 302
|
148
|
-
expect(last_response.headers['Location']).to be == 'bar'
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should rewrite the request" do
|
152
|
-
get '/controller/rewrite'
|
153
|
-
expect(last_response.status).to be == 200
|
154
|
-
expect(last_response.body).to be == 'Hello World'
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
80
|
describe Utopia::Controller do
|
159
81
|
let(:variables) {Utopia::Controller::Variables.new}
|
160
82
|
|
161
83
|
it "should call controller methods" do
|
162
|
-
request = Rack::Request.new(
|
84
|
+
request = Rack::Request.new(Utopia::VARIABLES_KEY => variables)
|
163
85
|
controller = TestController.new
|
86
|
+
variables << controller
|
164
87
|
|
165
88
|
result = controller.process!(request, Utopia::Path["/success"])
|
166
89
|
expect(result).to be == [200, {}, []]
|
@@ -173,32 +96,36 @@ module Utopia::ControllerSpec
|
|
173
96
|
end
|
174
97
|
|
175
98
|
it "should call direct controller methods" do
|
176
|
-
request = Rack::Request.new(
|
99
|
+
request = Rack::Request.new(Utopia::VARIABLES_KEY => variables)
|
177
100
|
controller = TestIndirectController.new
|
101
|
+
variables << controller
|
178
102
|
|
179
103
|
controller.process!(request, Utopia::Path["/user/update"])
|
180
104
|
expect(variables['sequence']).to be == 'EA'
|
181
105
|
end
|
182
106
|
|
183
107
|
it "should call indirect controller methods" do
|
184
|
-
request = Rack::Request.new(
|
108
|
+
request = Rack::Request.new(Utopia::VARIABLES_KEY => variables)
|
185
109
|
controller = TestIndirectController.new
|
110
|
+
variables << controller
|
186
111
|
|
187
112
|
result = controller.process!(request, Utopia::Path["/foo/comment/post"])
|
188
113
|
expect(variables['sequence']).to be == 'EB'
|
189
114
|
end
|
190
115
|
|
191
116
|
it "should call multiple indirect controller methods in order" do
|
192
|
-
request = Rack::Request.new(
|
117
|
+
request = Rack::Request.new(Utopia::VARIABLES_KEY => variables)
|
193
118
|
controller = TestIndirectController.new
|
119
|
+
variables << controller
|
194
120
|
|
195
121
|
result = controller.process!(request, Utopia::Path["/comment/delete"])
|
196
122
|
expect(variables['sequence']).to be == 'EDC'
|
197
123
|
end
|
198
124
|
|
199
125
|
it "should match single patterns" do
|
200
|
-
request = Rack::Request.new(
|
126
|
+
request = Rack::Request.new(Utopia::VARIABLES_KEY => variables)
|
201
127
|
controller = TestIndirectController.new
|
128
|
+
variables << controller
|
202
129
|
|
203
130
|
result = controller.process!(request, Utopia::Path["/foo"])
|
204
131
|
expect(variables['sequence']).to be == 'EF'
|