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
@@ -30,17 +30,17 @@ module Utopia::ExceptionHandlerSpec
30
30
  describe Utopia::ExceptionHandler do
31
31
  include Rack::Test::Methods
32
32
 
33
- let(:app) {Rack::Builder.parse_file(File.expand_path('../exception_handler_spec.ru', __FILE__)).first}
33
+ let(:app) {Rack::Builder.parse_file(File.expand_path('exception_handler_spec.ru', __dir__)).first}
34
34
 
35
35
  it "should successfully call the controller method" do
36
- get "/controller/blow?fatal=true"
36
+ get "/blow?fatal=true"
37
37
 
38
38
  expect(last_response.status).to be == 400
39
39
  expect(last_response.body).to be_include 'Fatal Error'
40
40
  end
41
41
 
42
42
  it "should fail with a 500 error" do
43
- get "/controller/blow"
43
+ get "/blow"
44
44
 
45
45
  expect(last_response.status).to be == 500
46
46
  expect(last_response.body).to be_include 'Error Will Robertson'
@@ -1,6 +1,6 @@
1
1
 
2
- use Utopia::ExceptionHandler, '/controller/exception'
2
+ use Utopia::ExceptionHandler, '/exception'
3
3
 
4
- use Utopia::Controller, root: File.expand_path('../pages', __FILE__)
4
+ use Utopia::Controller, root: File.expand_path('exception_handler_spec', __dir__)
5
5
 
6
6
  run lambda {|env| [404, {}, []]}
@@ -0,0 +1,15 @@
1
+
2
+ class TharSheBlows < StandardError
3
+ end
4
+
5
+ on 'blow' do
6
+ raise TharSheBlows.new("Arrrh!")
7
+ end
8
+
9
+ on 'exception' do |request|
10
+ if request['fatal']
11
+ raise TharSheBlows.new("Yarrh!")
12
+ else
13
+ success! :content => 'Error Will Robertson', :type => 'text/plain'
14
+ end
15
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ # Copyright, 2015, 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/path/matcher'
24
+
25
+ module Utopia::Path::MatcherSpec
26
+ describe Utopia::Path::Matcher do
27
+ it "should match strings" do
28
+ path = Utopia::Path['users/20/edit']
29
+ matcher = Utopia::Path::Matcher[users: 'users']
30
+
31
+ match_data = matcher.match(path)
32
+ expect(match_data).to_not be nil
33
+
34
+ expect(match_data.post_match).to be == Utopia::Path['20/edit']
35
+ end
36
+
37
+ it "shouldn't match strings" do
38
+ path = Utopia::Path['users/20/edit']
39
+ matcher = Utopia::Path::Matcher[accounts: 'accounts']
40
+
41
+ match_data = matcher.match(path)
42
+ expect(match_data).to be nil
43
+ end
44
+
45
+ it "shouldn't match integer" do
46
+ path = Utopia::Path['users/20/edit']
47
+ matcher = Utopia::Path::Matcher[id: Integer]
48
+
49
+ match_data = matcher.match(path)
50
+ expect(match_data).to be nil
51
+ end
52
+
53
+ it "should match regexps" do
54
+ path = Utopia::Path['users/20/edit']
55
+ matcher = Utopia::Path::Matcher[users: 'users', id: Integer, action: String]
56
+
57
+ match_data = matcher.match(path)
58
+ expect(match_data).to_not be_falsey
59
+
60
+ expect(match_data[:users]).to be == 'users'
61
+ expect(match_data[:id]).to be == 20
62
+ expect(match_data[:action]).to be == 'edit'
63
+ end
64
+ end
65
+ end
@@ -22,18 +22,6 @@ require 'utopia/extensions/date'
22
22
  require 'utopia/extensions/rack'
23
23
 
24
24
  module Utopia::RackSpec
25
- describe Rack::Request do
26
- it "should construct the url" do
27
- request = Rack::Request.new(
28
- 'rack.url_scheme' => 'http',
29
- 'HTTP_HOST' => 'localhost',
30
- 'SERVER_PORT' => 80
31
- )
32
-
33
- expect(request.url_with_path("/foo/bar")).to be == "http://localhost/foo/bar"
34
- end
35
- end
36
-
37
25
  describe Rack::Response do
38
26
  it "should specify not to cache content" do
39
27
  response = Rack::Response.new
data/utopia.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "trenni", "~> 1.4.1"
26
26
  spec.add_dependency "mime-types", "~> 2.0"
27
27
 
28
- spec.add_dependency "rack", "~> 1.5"
28
+ spec.add_dependency "rack", "~> 1.6"
29
29
  spec.add_dependency "rack-cache", "~> 1.2.0"
30
30
 
31
31
  spec.add_dependency "mail", "~> 2.6.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
47
+ version: '1.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.5'
54
+ version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack-cache
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +148,7 @@ extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
150
  - ".gitignore"
151
+ - ".rspec"
151
152
  - ".simplecov"
152
153
  - ".travis.yml"
153
154
  - Gemfile
@@ -164,6 +165,7 @@ files:
164
165
  - lib/utopia/controller.rb
165
166
  - lib/utopia/controller/action.rb
166
167
  - lib/utopia/controller/base.rb
168
+ - lib/utopia/controller/rewrite.rb
167
169
  - lib/utopia/controller/variables.rb
168
170
  - lib/utopia/exception_handler.rb
169
171
  - lib/utopia/extensions/array.rb
@@ -174,6 +176,7 @@ files:
174
176
  - lib/utopia/mail_exceptions.rb
175
177
  - lib/utopia/middleware.rb
176
178
  - lib/utopia/path.rb
179
+ - lib/utopia/path/matcher.rb
177
180
  - lib/utopia/redirector.rb
178
181
  - lib/utopia/session.rb
179
182
  - lib/utopia/session/encrypted_cookie.rb
@@ -229,10 +232,17 @@ files:
229
232
  - spec/utopia/content/processor_spec.rb
230
233
  - spec/utopia/content_spec.rb
231
234
  - spec/utopia/content_spec.ru
232
- - spec/utopia/controller_spec.rb
233
- - spec/utopia/controller_spec.ru
235
+ - spec/utopia/controller/action_spec.rb
236
+ - spec/utopia/controller/middleware_spec.rb
237
+ - spec/utopia/controller/middleware_spec.ru
238
+ - spec/utopia/controller/middleware_spec/controller/controller.rb
239
+ - spec/utopia/controller/middleware_spec/controller/index.xnode
240
+ - spec/utopia/controller/middleware_spec/controller/nested/controller.rb
241
+ - spec/utopia/controller/rewrite_spec.rb
242
+ - spec/utopia/controller/sequence_spec.rb
234
243
  - spec/utopia/exception_handler_spec.rb
235
244
  - spec/utopia/exception_handler_spec.ru
245
+ - spec/utopia/exception_handler_spec/controller.rb
236
246
  - spec/utopia/extensions_spec.rb
237
247
  - spec/utopia/localization_spec.rb
238
248
  - spec/utopia/localization_spec.ru
@@ -241,15 +251,13 @@ files:
241
251
  - spec/utopia/pages/content/_show-value.xnode
242
252
  - spec/utopia/pages/content/links.yaml
243
253
  - spec/utopia/pages/content/test-partial.xnode
244
- - spec/utopia/pages/controller/controller.rb
245
- - spec/utopia/pages/controller/index.xnode
246
- - spec/utopia/pages/controller/nested/controller.rb
247
254
  - spec/utopia/pages/index.xnode
248
255
  - spec/utopia/pages/localized.de.txt
249
256
  - spec/utopia/pages/localized.en.txt
250
257
  - spec/utopia/pages/localized.jp.txt
251
258
  - spec/utopia/pages/node/index.xnode
252
259
  - spec/utopia/pages/test.txt
260
+ - spec/utopia/path/matcher_spec.rb
253
261
  - spec/utopia/path_spec.rb
254
262
  - spec/utopia/rack_spec.rb
255
263
  - spec/utopia/session_spec.rb
@@ -308,10 +316,17 @@ test_files:
308
316
  - spec/utopia/content/processor_spec.rb
309
317
  - spec/utopia/content_spec.rb
310
318
  - spec/utopia/content_spec.ru
311
- - spec/utopia/controller_spec.rb
312
- - spec/utopia/controller_spec.ru
319
+ - spec/utopia/controller/action_spec.rb
320
+ - spec/utopia/controller/middleware_spec.rb
321
+ - spec/utopia/controller/middleware_spec.ru
322
+ - spec/utopia/controller/middleware_spec/controller/controller.rb
323
+ - spec/utopia/controller/middleware_spec/controller/index.xnode
324
+ - spec/utopia/controller/middleware_spec/controller/nested/controller.rb
325
+ - spec/utopia/controller/rewrite_spec.rb
326
+ - spec/utopia/controller/sequence_spec.rb
313
327
  - spec/utopia/exception_handler_spec.rb
314
328
  - spec/utopia/exception_handler_spec.ru
329
+ - spec/utopia/exception_handler_spec/controller.rb
315
330
  - spec/utopia/extensions_spec.rb
316
331
  - spec/utopia/localization_spec.rb
317
332
  - spec/utopia/localization_spec.ru
@@ -320,15 +335,13 @@ test_files:
320
335
  - spec/utopia/pages/content/_show-value.xnode
321
336
  - spec/utopia/pages/content/links.yaml
322
337
  - spec/utopia/pages/content/test-partial.xnode
323
- - spec/utopia/pages/controller/controller.rb
324
- - spec/utopia/pages/controller/index.xnode
325
- - spec/utopia/pages/controller/nested/controller.rb
326
338
  - spec/utopia/pages/index.xnode
327
339
  - spec/utopia/pages/localized.de.txt
328
340
  - spec/utopia/pages/localized.en.txt
329
341
  - spec/utopia/pages/localized.jp.txt
330
342
  - spec/utopia/pages/node/index.xnode
331
343
  - spec/utopia/pages/test.txt
344
+ - spec/utopia/path/matcher_spec.rb
332
345
  - spec/utopia/path_spec.rb
333
346
  - spec/utopia/rack_spec.rb
334
347
  - spec/utopia/session_spec.rb
@@ -1,4 +0,0 @@
1
-
2
- use Utopia::Controller, root: File.expand_path('../pages', __FILE__)
3
-
4
- run lambda {|env| [404, {}, []]}
@@ -1,43 +0,0 @@
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 'rewrite' do
23
- rewrite! 'index'
24
- end
25
-
26
- on 'index' do
27
- success! content: 'Hello World'
28
- end
29
-
30
- class TharSheBlows < StandardError
31
- end
32
-
33
- on 'blow' do
34
- raise TharSheBlows.new("Arrrh!")
35
- end
36
-
37
- on 'exception' do |request|
38
- if request['fatal']
39
- raise TharSheBlows.new("Yarrh!")
40
- else
41
- success! :content => 'Error Will Robertson', :type => 'text/plain'
42
- end
43
- end