utopia 1.0.11 → 1.1.0

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.travis.yml +1 -0
  4. data/bin/utopia +1 -1
  5. data/lib/utopia/content.rb +10 -12
  6. data/lib/utopia/content/link.rb +8 -11
  7. data/lib/utopia/content/links.rb +1 -1
  8. data/lib/utopia/content/node.rb +8 -7
  9. data/lib/utopia/controller.rb +40 -39
  10. data/lib/utopia/controller/action.rb +14 -12
  11. data/lib/utopia/controller/base.rb +31 -32
  12. data/lib/utopia/controller/rewrite.rb +104 -0
  13. data/lib/utopia/exception_handler.rb +1 -1
  14. data/lib/utopia/extensions/rack.rb +21 -21
  15. data/lib/utopia/http.rb +14 -9
  16. data/lib/utopia/localization.rb +1 -1
  17. data/lib/utopia/middleware.rb +3 -0
  18. data/lib/utopia/path.rb +81 -25
  19. data/lib/utopia/path/matcher.rb +94 -0
  20. data/lib/utopia/redirector.rb +4 -4
  21. data/lib/utopia/session/encrypted_cookie.rb +1 -1
  22. data/lib/utopia/static.rb +1 -1
  23. data/lib/utopia/tags/node.rb +1 -1
  24. data/lib/utopia/version.rb +1 -1
  25. data/setup/site/config.ru +1 -1
  26. data/spec/utopia/content/link_spec.rb +8 -8
  27. data/spec/utopia/content/node_spec.rb +1 -1
  28. data/spec/utopia/content_spec.rb +3 -3
  29. data/spec/utopia/content_spec.ru +1 -1
  30. data/spec/utopia/controller/action_spec.rb +61 -0
  31. data/spec/utopia/controller/middleware_spec.rb +71 -0
  32. data/spec/utopia/controller/middleware_spec.ru +4 -0
  33. data/spec/utopia/controller/middleware_spec/controller/controller.rb +24 -0
  34. data/spec/utopia/{pages → controller/middleware_spec}/controller/index.xnode +0 -0
  35. data/spec/utopia/{pages → controller/middleware_spec}/controller/nested/controller.rb +0 -0
  36. data/spec/utopia/controller/rewrite_spec.rb +66 -0
  37. data/spec/utopia/{controller_spec.rb → controller/sequence_spec.rb} +11 -84
  38. data/spec/utopia/exception_handler_spec.rb +3 -3
  39. data/spec/utopia/exception_handler_spec.ru +2 -2
  40. data/spec/utopia/exception_handler_spec/controller.rb +15 -0
  41. data/spec/utopia/path/matcher_spec.rb +65 -0
  42. data/spec/utopia/rack_spec.rb +0 -12
  43. data/utopia.gemspec +1 -1
  44. metadata +27 -14
  45. data/spec/utopia/controller_spec.ru +0 -4
  46. data/spec/utopia/pages/controller/controller.rb +0 -43
@@ -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, {"Location" => "#{prefix}index"}, []]}]
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, {"Location" => (destination_root + match[1]).to_s}, []]
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, {"Location" => uri.to_s}, []]
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
@@ -194,7 +194,7 @@ module Utopia
194
194
 
195
195
  public
196
196
 
197
- def initialize(app, options = {})
197
+ def initialize(app, **options)
198
198
  @app = app
199
199
  @root = options[:root] || Utopia::default_root
200
200
 
@@ -22,7 +22,7 @@ module Utopia
22
22
  module Tags
23
23
  class Node
24
24
  def self.call(transaction, state)
25
- path = Utopia::Path.create(state[:path])
25
+ path = Path[state[:path]]
26
26
 
27
27
  node = transaction.lookup_node(path)
28
28
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Utopia
22
- VERSION = "1.0.11"
22
+ VERSION = "1.1.0"
23
23
  end
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("../lib", __FILE__)
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 link should have full path" do
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 link should have full path" do
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 link should have full path" do
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("../links", __FILE__), Utopia::Path.create("/"))
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("../links", __FILE__), Utopia::Path.create("/"), name: /foo/)
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("../links", __FILE__)
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("../localized", __FILE__)
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("../localized", __FILE__)
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("../node", __FILE__)}
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
@@ -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('../content_spec.ru', __FILE__)).first}
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('../pages/node', __FILE__)
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("../pages", __FILE__)}
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
@@ -2,7 +2,7 @@
2
2
  require 'utopia/tags/deferred'
3
3
 
4
4
  use Utopia::Content,
5
- root: File.expand_path('../pages', __FILE__),
5
+ root: File.expand_path('pages', __dir__),
6
6
  tags: {
7
7
  'deferred' => Utopia::Tags::Deferred
8
8
  }
@@ -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,4 @@
1
+
2
+ use Utopia::Controller, root: File.expand_path('middleware_spec', __dir__)
3
+
4
+ run lambda {|env| [404, {}, []]}
@@ -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
@@ -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::ControllerSpec
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("utopia.controller" => variables)
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("utopia.controller" => variables)
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("utopia.controller" => variables)
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("utopia.controller" => variables)
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("utopia.controller" => variables)
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'