waves 0.8.2 → 0.9.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 (166) hide show
  1. data/bin/waves +4 -3
  2. data/doc/VERSION +1 -1
  3. data/lib/waves.rb +52 -40
  4. data/lib/{caches → waves/caches}/file.rb +3 -1
  5. data/lib/waves/caches/memcached.rb +56 -0
  6. data/lib/{caches → waves/caches}/simple.rb +6 -7
  7. data/lib/{caches → waves/caches}/synchronized.rb +15 -1
  8. data/lib/{commands → waves/commands}/console.rb +4 -4
  9. data/lib/{commands → waves/commands}/generate.rb +6 -5
  10. data/lib/{commands → waves/commands}/help.rb +0 -0
  11. data/lib/{commands → waves/commands}/server.rb +1 -1
  12. data/lib/{dispatchers → waves/dispatchers}/base.rb +17 -31
  13. data/lib/waves/dispatchers/default.rb +19 -0
  14. data/lib/{ext → waves/ext}/float.rb +0 -0
  15. data/lib/{ext → waves/ext}/hash.rb +0 -0
  16. data/lib/{ext → waves/ext}/integer.rb +16 -1
  17. data/lib/{ext → waves/ext}/kernel.rb +3 -7
  18. data/lib/{ext → waves/ext}/module.rb +3 -3
  19. data/lib/{ext → waves/ext}/object.rb +2 -0
  20. data/lib/waves/ext/string.rb +73 -0
  21. data/lib/{ext → waves/ext}/symbol.rb +0 -1
  22. data/lib/{ext → waves/ext}/tempfile.rb +0 -0
  23. data/lib/waves/ext/time.rb +5 -0
  24. data/lib/{foundations → waves/foundations}/classic.rb +9 -21
  25. data/lib/{foundations → waves/foundations}/compact.rb +15 -20
  26. data/lib/waves/foundations/rest.rb +311 -0
  27. data/lib/waves/helpers/basic.rb +13 -0
  28. data/lib/{helpers → waves/helpers}/doc_type.rb +3 -0
  29. data/lib/waves/helpers/form.rb +94 -0
  30. data/lib/waves/helpers/formatting.rb +14 -0
  31. data/lib/waves/layers/mvc.rb +65 -0
  32. data/lib/{layers → waves/layers}/mvc/controllers.rb +0 -0
  33. data/lib/{layers → waves/layers}/mvc/extensions.rb +23 -11
  34. data/lib/{layers → waves/layers}/orm/migration.rb +0 -0
  35. data/lib/{layers → waves/layers}/orm/providers/active_record.rb +2 -5
  36. data/lib/{layers → waves/layers}/orm/providers/active_record/migrations/empty.rb.erb +0 -0
  37. data/lib/{layers → waves/layers}/orm/providers/active_record/tasks/generate.rb +1 -1
  38. data/lib/{layers → waves/layers}/orm/providers/active_record/tasks/schema.rb +1 -1
  39. data/lib/{layers → waves/layers}/orm/providers/data_mapper.rb +0 -0
  40. data/lib/{layers → waves/layers}/orm/providers/filebase.rb +0 -0
  41. data/lib/{layers → waves/layers}/orm/providers/sequel.rb +28 -29
  42. data/lib/{layers → waves/layers}/orm/providers/sequel/migrations/empty.rb.erb +0 -0
  43. data/lib/{layers → waves/layers}/orm/providers/sequel/tasks/generate.rb +1 -1
  44. data/lib/{layers → waves/layers}/orm/providers/sequel/tasks/schema.rb +2 -0
  45. data/lib/waves/layers/rack/rack_cache.rb +32 -0
  46. data/lib/waves/layers/renderers/erubis.rb +52 -0
  47. data/lib/waves/layers/renderers/haml.rb +67 -0
  48. data/lib/waves/layers/renderers/markaby.rb +41 -0
  49. data/lib/waves/layers/text/inflect/english.rb +42 -0
  50. data/lib/waves/matchers/accept.rb +47 -0
  51. data/lib/waves/matchers/ext.rb +27 -0
  52. data/lib/waves/matchers/path.rb +72 -0
  53. data/lib/waves/matchers/query.rb +43 -0
  54. data/lib/waves/matchers/request.rb +86 -0
  55. data/lib/waves/matchers/requested.rb +31 -0
  56. data/lib/{matchers → waves/matchers}/resource.rb +8 -1
  57. data/lib/waves/matchers/traits.rb +30 -0
  58. data/lib/waves/matchers/uri.rb +69 -0
  59. data/lib/waves/media/mime_types.rb +542 -0
  60. data/lib/waves/renderers/mixin.rb +9 -0
  61. data/lib/waves/request/accept.rb +92 -0
  62. data/lib/{runtime → waves/request}/request.rb +77 -61
  63. data/lib/waves/resources/file_mixin.rb +11 -0
  64. data/lib/{resources → waves/resources}/mixin.rb +42 -44
  65. data/lib/waves/resources/paths.rb +132 -0
  66. data/lib/waves/response/client_errors.rb +10 -0
  67. data/lib/waves/response/packaged.rb +19 -0
  68. data/lib/waves/response/redirects.rb +35 -0
  69. data/lib/{runtime → waves/response}/response.rb +29 -11
  70. data/lib/{runtime → waves/response}/response_mixin.rb +30 -17
  71. data/lib/waves/runtime/applications.rb +18 -0
  72. data/lib/{runtime → waves/runtime}/configuration.rb +31 -25
  73. data/lib/waves/runtime/console.rb +24 -0
  74. data/lib/{runtime → waves/runtime}/logger.rb +3 -3
  75. data/lib/{runtime → waves/runtime}/mocks.rb +2 -2
  76. data/lib/waves/runtime/rackup.rb +37 -0
  77. data/lib/waves/runtime/runtime.rb +48 -0
  78. data/lib/waves/runtime/server.rb +33 -0
  79. data/lib/{servers → waves/servers}/base.rb +0 -0
  80. data/lib/{servers → waves/servers}/mongrel.rb +0 -0
  81. data/lib/{servers → waves/servers}/webrick.rb +0 -0
  82. data/lib/{tasks → waves/tasks}/gem.rb +0 -0
  83. data/lib/{tasks → waves/tasks}/generate.rb +0 -0
  84. data/lib/waves/views/cassy.rb +173 -0
  85. data/lib/{views → waves/views}/errors.rb +8 -7
  86. data/lib/waves/views/mixin.rb +23 -0
  87. data/lib/waves/views/templated.rb +40 -0
  88. data/samples/basic/basic_startup.rb +70 -0
  89. data/samples/basic/config.ru +9 -0
  90. data/samples/blog/configurations/development.rb +17 -16
  91. data/samples/blog/configurations/production.rb +0 -11
  92. data/samples/blog/resources/entry.rb +3 -3
  93. data/samples/blog/resources/map.rb +10 -3
  94. data/samples/blog/startup.rb +4 -3
  95. data/templates/classic/Rakefile +28 -29
  96. data/templates/classic/configurations/default.rb.erb +8 -3
  97. data/templates/classic/configurations/development.rb.erb +1 -20
  98. data/templates/classic/configurations/production.rb.erb +2 -16
  99. data/templates/classic/public/images/favicon.ico +0 -0
  100. data/templates/classic/resources/server.rb.erb +9 -0
  101. data/templates/classic/startup.rb.erb +3 -3
  102. data/templates/classic/views/css.rb.erb +14 -0
  103. data/templates/classic/views/default.rb.erb +17 -0
  104. data/templates/classic/views/errors.rb.erb +10 -0
  105. data/templates/classic/views/pages.rb.erb +14 -0
  106. data/templates/compact/startup.rb.erb +8 -3
  107. data/test/ext/object.rb +55 -0
  108. data/test/ext/shortcuts.rb +73 -0
  109. data/test/helpers.rb +17 -0
  110. data/test/match/accept.rb +78 -0
  111. data/test/match/ext.rb +156 -0
  112. data/test/match/methods.rb +22 -0
  113. data/test/match/params.rb +33 -0
  114. data/test/match/path.rb +106 -0
  115. data/test/match/query.rb +60 -0
  116. data/test/match/request.rb +91 -0
  117. data/test/match/requested.rb +149 -0
  118. data/test/match/uri.rb +136 -0
  119. data/test/process/request.rb +75 -0
  120. data/test/process/resource.rb +53 -0
  121. data/test/resources/path.rb +166 -0
  122. data/test/runtime/configurations.rb +19 -0
  123. data/test/runtime/request.rb +63 -0
  124. data/test/runtime/response.rb +85 -0
  125. data/test/views/views.rb +40 -0
  126. metadata +243 -157
  127. data/lib/caches/memcached.rb +0 -40
  128. data/lib/dispatchers/default.rb +0 -25
  129. data/lib/ext/string.rb +0 -20
  130. data/lib/helpers/basic.rb +0 -11
  131. data/lib/helpers/extended.rb +0 -21
  132. data/lib/helpers/form.rb +0 -42
  133. data/lib/helpers/formatting.rb +0 -30
  134. data/lib/helpers/layouts.rb +0 -37
  135. data/lib/helpers/model.rb +0 -37
  136. data/lib/helpers/view.rb +0 -22
  137. data/lib/layers/inflect/english.rb +0 -67
  138. data/lib/layers/mvc.rb +0 -54
  139. data/lib/layers/renderers/erubis.rb +0 -60
  140. data/lib/layers/renderers/haml.rb +0 -47
  141. data/lib/layers/renderers/markaby.rb +0 -29
  142. data/lib/matchers/accept.rb +0 -21
  143. data/lib/matchers/base.rb +0 -30
  144. data/lib/matchers/content_type.rb +0 -17
  145. data/lib/matchers/path.rb +0 -67
  146. data/lib/matchers/query.rb +0 -21
  147. data/lib/matchers/request.rb +0 -27
  148. data/lib/matchers/traits.rb +0 -19
  149. data/lib/matchers/uri.rb +0 -20
  150. data/lib/renderers/mixin.rb +0 -36
  151. data/lib/resources/paths.rb +0 -34
  152. data/lib/runtime/console.rb +0 -23
  153. data/lib/runtime/mime_types.rb +0 -536
  154. data/lib/runtime/monitor.rb +0 -32
  155. data/lib/runtime/runtime.rb +0 -67
  156. data/lib/runtime/server.rb +0 -20
  157. data/lib/runtime/session.rb +0 -27
  158. data/lib/runtime/worker.rb +0 -86
  159. data/lib/views/mixin.rb +0 -62
  160. data/samples/blog/blog.db +0 -0
  161. data/samples/blog/log/waves.production +0 -3
  162. data/templates/classic/resources/map.rb.erb +0 -8
  163. data/templates/classic/templates/errors/not_found_404.mab +0 -7
  164. data/templates/classic/templates/errors/server_error_500.mab +0 -7
  165. data/templates/classic/templates/layouts/default.mab +0 -14
  166. data/templates/classic/tmp/sessions/.gitignore +0 -0
@@ -0,0 +1,91 @@
1
+ require "#{File.dirname(__FILE__)}/../../test/helpers.rb"
2
+ require "test/helpers.rb"
3
+
4
+ require "waves/foundations/compact"
5
+ require "waves/matchers/request"
6
+
7
+ describe "Top-level request matcher" do
8
+ before do
9
+ Test = Module.new { include Waves::Foundations::Compact }
10
+ Waves << Test
11
+ end
12
+
13
+ after do
14
+ Waves.applications.clear
15
+ Object.instance_eval { remove_const(:Test) if const_defined?(:Test) }
16
+ end
17
+
18
+ # @todo Change these to mocks to ensure we really are dealing
19
+ # with a non-constructed URI matcher.
20
+
21
+ feature "matches any URI, returning {}, if URI matcher omitted" do
22
+ m = Waves::Matchers::Request.new :path => nil,
23
+ :host => nil,
24
+ :port => nil,
25
+ :scheme => nil
26
+
27
+ request = Waves::Request.new env("http://example.com/moo",
28
+ :method => "GET",
29
+ "HTTP_ACCEPT" => "text/html")
30
+ m.call(request).should == {}
31
+
32
+ request = Waves::Request.new env("http://example2.com/moo",
33
+ :method => "GET",
34
+ "HTTP_ACCEPT" => "text/html")
35
+ m.call(request).should == {}
36
+
37
+ request = Waves::Request.new env("http://example2.com:8008/moo",
38
+ :method => "GET",
39
+ "HTTP_ACCEPT" => "text/html")
40
+ m.call(request).should == {}
41
+ end
42
+
43
+ feature "omits Accept constraints if none given" do
44
+ Waves::Matchers::Request.new({}).constraints.has_key?(:accept).should == false
45
+ end
46
+
47
+ feature "omits Ext constraints if none given" do
48
+ Waves::Matchers::Request.new({}).constraints.has_key?(:ext).should == false
49
+ Waves::Matchers::Request.new({}).constraints.has_key?(:extension).should == false
50
+ end
51
+
52
+ feature "omits Query constraints if none given" do
53
+ Waves::Matchers::Request.new({}).constraints.has_key?(:query).should == false
54
+ end
55
+
56
+ feature "omits Traits constraints if none given" do
57
+ Waves::Matchers::Request.new({}).constraints.has_key?(:traits).should == false
58
+ end
59
+
60
+ feature "returns captured values when matched" do
61
+ m = Waves::Matchers::Request.new :path => [:something],
62
+ :host => nil,
63
+ :port => nil,
64
+ :scheme => nil
65
+
66
+ request = Waves::Request.new env("http://example.com/moo",
67
+ :method => "GET",
68
+ "HTTP_ACCEPT" => "text/html")
69
+
70
+ res = m.call request
71
+ res.kind_of?(Hash).should == true
72
+ res.size.should == 1
73
+ res.has_key?(:something).should == true
74
+ end
75
+
76
+ feature "sets the captured trait to return value when matched" do
77
+ m = Waves::Matchers::Request.new :path => [:something],
78
+ :host => nil,
79
+ :port => nil,
80
+ :scheme => nil
81
+
82
+ request = Waves::Request.new env("http://example.com/moo",
83
+ :method => "GET",
84
+ "HTTP_ACCEPT" => "text/html")
85
+
86
+ res = m.call request
87
+ request.traits.waves.captured.something.should == res[:something]
88
+ end
89
+
90
+ end
91
+
@@ -0,0 +1,149 @@
1
+ require "#{File.dirname(__FILE__)}/../../test/helpers.rb"
2
+ require 'test/helpers.rb'
3
+
4
+ require 'waves/foundations/compact'
5
+ require "waves/runtime/mime_types"
6
+
7
+ describe "Requested header matching" do
8
+ before do
9
+ Test = Module.new { include Waves::Foundations::Compact }
10
+ Waves << Test
11
+ end
12
+
13
+ after do
14
+ Waves.applications.clear
15
+ Object.instance_eval { remove_const(:Test) if const_defined?(:Test) }
16
+ end
17
+
18
+ feature "matches correct MIME given as a file extension" do
19
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/javascript") { }
20
+
21
+ resp = get "/foo.js"
22
+ resp.status.should == 200
23
+ end
24
+
25
+ feature "matches correct MIME given in the Requested header" do
26
+ Test::Resources::Map.on(:get,
27
+ ["foo"],
28
+ :requested => "text/javascript") { }
29
+
30
+ resp = get "/foo", "HTTP_ACCEPT" => "text/javascript"
31
+ resp.status.should == 200
32
+ end
33
+
34
+ feature "allows both a file extension and Requested" do
35
+ Test::Resources::Map.on(:get,
36
+ ["foo"],
37
+ :requested => "text/javascript") { }
38
+
39
+ resp = get "/foo.js", "HTTP_ACCEPT" => "text/javascript"
40
+ resp.status.should == 200
41
+ end
42
+
43
+ feature "prefers a present file extension over any Requested" do
44
+ # note that the order matters here: LIFO, just as tho we were using #define_method
45
+ Test::Resources::Map.on(:get, ["foo"], :requested => "image/png") { "png" }
46
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/javascript") { "js" }
47
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/x-fortran") { "fortran" }
48
+
49
+ resp = get "/foo.f90", "HTTP_ACCEPT" => "text/javascript"
50
+ resp.status.should == 200
51
+ resp.body.should == "fortran"
52
+
53
+ resp = get "/foo.f90", "HTTP_ACCEPT" => "image/png"
54
+ resp.status.should == 200
55
+ resp.body.should == "fortran"
56
+ end
57
+
58
+
59
+ feature "does not match for absent extension by default" do
60
+ Test::Resources::Map.on(:get,
61
+ ["foo"],
62
+ :requested => "text/html") {
63
+ "undefined"
64
+ }
65
+
66
+ resp = get "/foo", {"HTTP_ACCEPT" => "text/javascript"}
67
+ resp.status.should == 404
68
+ end
69
+
70
+ feature "matches single type Strings or Symbols against general MIME types" do
71
+ Test::Resources::Map.on(:get, ["foo"], :requested => "image") { }
72
+ Test::Resources::Map.on(:get, ["bar"], :requested => :image) { }
73
+
74
+ resp = get "/foo", "HTTP_ACCEPT" => "image/png"
75
+ resp.status.should == 200
76
+
77
+ resp = get "/bar", "HTTP_ACCEPT" => "image/png"
78
+ resp.status.should == 200
79
+ end
80
+
81
+ feature "matches single type Strings or Symbols against MIME subtypes" do
82
+ Test::Resources::Map.on(:get, ["foo"], :requested => "png") { }
83
+ Test::Resources::Map.on(:get, ["bar"], :requested => :png) { }
84
+
85
+ resp = get "/foo", "HTTP_ACCEPT" => "image/png"
86
+ resp.status.should == 200
87
+
88
+ resp = get "/bar", "HTTP_ACCEPT" => "image/png"
89
+ resp.status.should == 200
90
+ end
91
+
92
+ feature "matches type/* form MIME specifiers against general MIME types (but superfluous)" do
93
+ Test::Resources::Map.on(:get, ["foo"], :requested => "image/*") { }
94
+
95
+ resp = get "/foo", "HTTP_ACCEPT" => "image/png"
96
+ resp.status.should == 200
97
+
98
+ resp = get "/foo", "HTTP_ACCEPT" => "image/jpeg"
99
+ resp.status.should == 200
100
+ end
101
+
102
+ feature "does not match <type>/* form MIME specifiers against MIME subtypes" do
103
+ Test::Resources::Map.on(:get, ["foo"], :requested => "png/*") { }
104
+
105
+ resp = get "/foo", "HTTP_ACCEPT" => "image/png"
106
+ resp.status.should == 404
107
+ end
108
+
109
+ feature "requested */* matches anything" do
110
+ Test::Resources::Map.on(:get, ["foo"], :requested => "*/*") { }
111
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/*") { }
112
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/plain") { }
113
+
114
+ resp = get "/foo", "HTTP_ACCEPT" => "text/javascript"
115
+ resp.status.should == 200
116
+ end
117
+
118
+ feature "requested * matches anything" do
119
+ Test::Resources::Map.on(:get, ["foo"], :requested => "*") { }
120
+ Test::Resources::Map.on(:get, ["foo"], :requested => "*/*") { }
121
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/*") { }
122
+ Test::Resources::Map.on(:get, ["foo"], :requested => "text/plain") { }
123
+
124
+ resp = get "/foo", "HTTP_ACCEPT" => "text/javascript"
125
+ resp.status.should == 200
126
+ end
127
+
128
+ feature "allows multiple MIMEs to be accepted for one representation" do
129
+ Test::Resources::Map.on(:get,
130
+ ["foo"],
131
+ :requested => ["text/javascript",
132
+ :application,
133
+ "text/fortran",
134
+ :png]) { }
135
+
136
+ resp = get "/foo", "HTTP_ACCEPT" => "text/javascript"
137
+ resp.status.should == 200
138
+
139
+ resp = get "/foo", "HTTP_ACCEPT" => "text/fortran"
140
+ resp.status.should == 200
141
+
142
+ resp = get "/foo", "HTTP_ACCEPT" => "image/png"
143
+ resp.status.should == 200
144
+
145
+ resp = get "/foo", "HTTP_ACCEPT" => "application/xhtml+xml"
146
+ resp.status.should == 200
147
+ end
148
+
149
+ end
data/test/match/uri.rb ADDED
@@ -0,0 +1,136 @@
1
+ require "#{File.dirname(__FILE__)}/../../test/helpers.rb"
2
+ require "test/helpers.rb"
3
+
4
+ require "waves/foundations/compact"
5
+ require "waves/matchers/URI"
6
+
7
+ describe "URI matcher without specified path" do
8
+ before do
9
+ Test = Module.new { include Waves::Foundations::Compact }
10
+ Waves << Test
11
+ end
12
+
13
+ after do
14
+ Waves.applications.clear
15
+ Object.instance_eval { remove_const(:Test) if const_defined?(:Test) }
16
+ end
17
+
18
+ feature "always matches and returns {} if no host/port/scheme given either" do
19
+ m = Waves::Matchers::URI.new :path => nil,
20
+ :host => nil,
21
+ :port => nil,
22
+ :scheme => nil
23
+
24
+ request = Waves::Request.new env("http://example.com/moo",
25
+ :method => "GET",
26
+ "HTTP_ACCEPT" => "text/html")
27
+
28
+ m.call(request).should == {}
29
+ end
30
+
31
+ feature "matches returning {} when all of given host/port/scheme match" do
32
+ m = Waves::Matchers::URI.new :path => nil,
33
+ :host => "example.com",
34
+ :port => nil,
35
+ :scheme => nil
36
+
37
+ n = Waves::Matchers::URI.new :path => nil,
38
+ :host => nil,
39
+ :port => nil,
40
+ :scheme => "http"
41
+
42
+ o = Waves::Matchers::URI.new :path => nil,
43
+ :host => nil,
44
+ :port => nil,
45
+ :scheme => "http"
46
+
47
+ q = Waves::Matchers::URI.new :path => nil,
48
+ :host => "example.com",
49
+ :port => 80,
50
+ :scheme => "http"
51
+
52
+ request = Waves::Request.new env("http://example.com/moo",
53
+ :method => "GET",
54
+ "HTTP_ACCEPT" => "text/html")
55
+
56
+ m.call(request).should == {}
57
+ n.call(request).should == {}
58
+ o.call(request).should == {}
59
+ q.call(request).should == {}
60
+ end
61
+
62
+ feature "returns falseish if either host, port or scheme fail to match when given" do
63
+ m = Waves::Matchers::URI.new :path => nil,
64
+ :host => "example.com",
65
+ :port => nil,
66
+ :scheme => nil
67
+
68
+ n = Waves::Matchers::URI.new :path => nil,
69
+ :host => nil,
70
+ :port => nil,
71
+ :scheme => "https"
72
+
73
+ o = Waves::Matchers::URI.new :path => nil,
74
+ :host => nil,
75
+ :port => 8080,
76
+ :scheme => nil
77
+
78
+ request = Waves::Request.new env("http://example2.com/moo",
79
+ :method => "GET",
80
+ "HTTP_ACCEPT" => "text/html")
81
+
82
+ (!!m.call(request)).should == false
83
+ (!!n.call(request)).should == false
84
+ (!!o.call(request)).should == false
85
+ end
86
+ end
87
+
88
+ describe "URI matcher with path specified" do
89
+ before do
90
+ Test = Module.new { include Waves::Foundations::Compact }
91
+ Waves << Test
92
+ end
93
+
94
+ after do
95
+ Waves.applications.clear
96
+ Object.instance_eval { remove_const(:Test) if const_defined?(:Test) }
97
+ end
98
+
99
+ feature "returns path captures if path and any present host/port/scheme match" do
100
+ m = Waves::Matchers::URI.new :path => [:aminal],
101
+ :host => "example.com",
102
+ :port => nil,
103
+ :scheme => "http"
104
+
105
+ request = Waves::Request.new env("http://example.com/moo",
106
+ :method => "GET",
107
+ "HTTP_ACCEPT" => "text/html")
108
+
109
+ m.call(request).should == {:aminal => "moo"}
110
+ end
111
+
112
+ feature "returns falseish if path matches but a present host/port/scheme does not" do
113
+ m = Waves::Matchers::URI.new :path => [:aminal],
114
+ :host => "example2.com",
115
+ :port => nil,
116
+ :scheme => nil
117
+
118
+ n = Waves::Matchers::URI.new :path => [:aminal],
119
+ :host => nil,
120
+ :port => 8008,
121
+ :scheme => nil
122
+
123
+ o = Waves::Matchers::URI.new :path => [:aminal],
124
+ :host => nil,
125
+ :port => nil,
126
+ :scheme => "https"
127
+
128
+ request = Waves::Request.new env("http://example.com/moo",
129
+ :method => "GET",
130
+ "HTTP_ACCEPT" => "text/html")
131
+
132
+ (!!m.call(request)).should == false
133
+ (!!n.call(request)).should == false
134
+ (!!o.call(request)).should == false
135
+ end
136
+ end
@@ -0,0 +1,75 @@
1
+ require 'test/helpers.rb'
2
+ require 'waves/foundations/compact'
3
+
4
+ describe "Request Object" do
5
+ before do
6
+ Test = Module.new { include Waves::Foundations::Compact }
7
+ Waves << Test
8
+ end
9
+
10
+ after do
11
+ Waves.applications.clear
12
+ Object.instance_eval { remove_const( :Test ) if const_defined?( :Test ) }
13
+ end
14
+
15
+ feature "Access the request method, scheme, url, host, port, path, referer, and query" do
16
+ r = Waves::Request.new( env( 'http://localhost/', :method => 'GET' ) )
17
+ { :scheme => 'http', :url => 'http://localhost/', :method => :get,
18
+ :path => '/', :host => 'localhost', :domain => 'localhost',
19
+ :query => {}, :params => {}, :port => 80, :referer => '/' }.
20
+ each { |k,v| r.send( k ).should == v }
21
+ end
22
+
23
+ feature "Access the request method as a boolean" do
24
+ Waves::Request.new( env( '/', :method => 'GET' ) ).get.should == true
25
+ end
26
+
27
+ feature "Access HTTP headers as accessor methods" do
28
+ Waves::Request.new( env( '/', :method => 'GET',
29
+ 'HTTP_CACHE_CONTROL' => 'no-cache' ) ).
30
+ cache_control.should == 'no-cache'
31
+ end
32
+
33
+ feature "Access accept headers as Waves::Request::Accept objects" do
34
+ Waves::Request.new( env( '/', :method => 'GET',
35
+ 'HTTP_ACCEPT_LANGUAGE' => 'en/us' ) ).
36
+ accept_language.class.should == Waves::Accept
37
+ end
38
+
39
+ feature "Access custom headers as methods" do
40
+ Waves::Request.new( env( '/', :method => 'GET',
41
+ 'X_CUSTOM_HEADER' => 'foo' ) )[ :x_custom_header ].should == 'foo'
42
+ end
43
+
44
+ feature "Initiate redirect using #redirect" do
45
+ lambda {
46
+ Waves::Request.new( env( '/', :method => 'GET' ) ).redirect('/')
47
+ }.should.raise( Waves::Redirects::Found )
48
+ end
49
+
50
+ feature "Raise NotFound using #not_found" do
51
+ lambda {
52
+ Waves::Request.new( env( '/', :method => 'GET' ) ).not_found
53
+ }.should.raise( Waves::Response::ClientErrors::NotFound )
54
+ end
55
+
56
+ feature "Access to content_type, media_type, and content_length" do
57
+ r = Waves::Request.new( env( '/', :method => 'GET',
58
+ 'CONTENT_TYPE' => 'text/plain;charset=utf-8', 'CONTENT_LENGTH' => 0 ) )
59
+ r.content_type.should == 'text/plain;charset=utf-8'
60
+ r.media_type.should == 'text/plain'
61
+ r.content_length.should == 0
62
+ end
63
+
64
+ feature "Read / write traits to the request" do
65
+ r = Waves::Request.new( env( '/', :method => 'GET' ))
66
+ r.traits[:foo] = 'bar'
67
+ r.traits.foo.should == 'bar'
68
+ end
69
+
70
+ feature "The Rack request is frozen and cannot be modified" do
71
+ r = Waves::Request.new( env( '/', :method => 'GET' ))
72
+ lambda { r.rack_request.instance_eval { @env = {} } }.should.raise( TypeError )
73
+ end
74
+
75
+ end