arrow 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/ChangeLog +1590 -0
  2. data/LICENSE +28 -0
  3. data/README +75 -0
  4. data/Rakefile +366 -0
  5. data/Rakefile.local +63 -0
  6. data/data/arrow/applets/TEMPLATE.rb.tpl +53 -0
  7. data/data/arrow/applets/args.rb +50 -0
  8. data/data/arrow/applets/config.rb +55 -0
  9. data/data/arrow/applets/error.rb +63 -0
  10. data/data/arrow/applets/files.rb +46 -0
  11. data/data/arrow/applets/inspect.rb +46 -0
  12. data/data/arrow/applets/nosuchapplet.rb +31 -0
  13. data/data/arrow/applets/status.rb +92 -0
  14. data/data/arrow/applets/test.rb +133 -0
  15. data/data/arrow/applets/tutorial/counter.rb +96 -0
  16. data/data/arrow/applets/tutorial/dingus.rb +67 -0
  17. data/data/arrow/applets/tutorial/hello.rb +34 -0
  18. data/data/arrow/applets/tutorial/hello2.rb +73 -0
  19. data/data/arrow/applets/tutorial/imgtext.rb +90 -0
  20. data/data/arrow/applets/tutorial/imgtext2.rb +286 -0
  21. data/data/arrow/applets/tutorial/index.rb +36 -0
  22. data/data/arrow/applets/tutorial/logo.rb +98 -0
  23. data/data/arrow/applets/tutorial/memcache.rb +61 -0
  24. data/data/arrow/applets/tutorial/missing.rb +37 -0
  25. data/data/arrow/applets/tutorial/protected.rb +100 -0
  26. data/data/arrow/applets/tutorial/redirector.rb +52 -0
  27. data/data/arrow/applets/tutorial/rndimages.rb +159 -0
  28. data/data/arrow/applets/tutorial/sharenotes.rb +83 -0
  29. data/data/arrow/applets/tutorial/subclassed-hello.rb +32 -0
  30. data/data/arrow/applets/tutorial/superhello.rb +72 -0
  31. data/data/arrow/applets/tutorial/timeclock.rb +78 -0
  32. data/data/arrow/applets/view-applet.rb +123 -0
  33. data/data/arrow/applets/view-template.rb +85 -0
  34. data/data/arrow/applets/wiki.rb +274 -0
  35. data/data/arrow/templates/TEMPLATE.tmpl.tpl +36 -0
  36. data/data/arrow/templates/applet-status.tmpl +153 -0
  37. data/data/arrow/templates/args-display.tmpl +120 -0
  38. data/data/arrow/templates/config/display-table.tmpl +36 -0
  39. data/data/arrow/templates/config/display.tmpl +36 -0
  40. data/data/arrow/templates/counter-deleted.tmpl +33 -0
  41. data/data/arrow/templates/counter.tmpl +59 -0
  42. data/data/arrow/templates/dingus.tmpl +55 -0
  43. data/data/arrow/templates/enumtable.tmpl +8 -0
  44. data/data/arrow/templates/error-display.tmpl +92 -0
  45. data/data/arrow/templates/filemap.tmpl +89 -0
  46. data/data/arrow/templates/hello-world-src.tmpl +34 -0
  47. data/data/arrow/templates/hello-world.tmpl +60 -0
  48. data/data/arrow/templates/imgtext/fontlist.tmpl +46 -0
  49. data/data/arrow/templates/imgtext/form.tmpl +70 -0
  50. data/data/arrow/templates/imgtext/reload-error.tmpl +40 -0
  51. data/data/arrow/templates/imgtext/reload.tmpl +55 -0
  52. data/data/arrow/templates/inspect/display.tmpl +80 -0
  53. data/data/arrow/templates/loginform.tmpl +64 -0
  54. data/data/arrow/templates/logout.tmpl +32 -0
  55. data/data/arrow/templates/memcache/display.tmpl +41 -0
  56. data/data/arrow/templates/navbar.incl +27 -0
  57. data/data/arrow/templates/nosuchapplet.tmpl +32 -0
  58. data/data/arrow/templates/printsource.tmpl +35 -0
  59. data/data/arrow/templates/protected.tmpl +36 -0
  60. data/data/arrow/templates/rndimages.tmpl +38 -0
  61. data/data/arrow/templates/service-response.tmpl +13 -0
  62. data/data/arrow/templates/sharenotes/display.tmpl +38 -0
  63. data/data/arrow/templates/status.tmpl +120 -0
  64. data/data/arrow/templates/templateviewer.tmpl +43 -0
  65. data/data/arrow/templates/test/harness.tmpl +57 -0
  66. data/data/arrow/templates/test/list.tmpl +48 -0
  67. data/data/arrow/templates/test/problem.tmpl +42 -0
  68. data/data/arrow/templates/tutorial/index.tmpl +37 -0
  69. data/data/arrow/templates/tutorial/missingapplet.tmpl +29 -0
  70. data/data/arrow/templates/view-applet-nosuch.tmpl +32 -0
  71. data/data/arrow/templates/view-applet.tmpl +40 -0
  72. data/data/arrow/templates/view-template.tmpl +83 -0
  73. data/data/arrow/templates/wiki/formerror.tmpl +47 -0
  74. data/data/arrow/templates/wiki/markup_help.incl +6 -0
  75. data/data/arrow/templates/wiki/new.tmpl +56 -0
  76. data/data/arrow/templates/wiki/new_system.tmpl +122 -0
  77. data/data/arrow/templates/wiki/sectionlist.tmpl +43 -0
  78. data/data/arrow/templates/wiki/show.tmpl +34 -0
  79. data/docs/manual/layouts/default.page +43 -0
  80. data/docs/manual/lib/api-filter.rb +81 -0
  81. data/docs/manual/lib/editorial-filter.rb +64 -0
  82. data/docs/manual/lib/examples-filter.rb +244 -0
  83. data/docs/manual/lib/links-filter.rb +117 -0
  84. data/lib/apache/fakerequest.rb +448 -0
  85. data/lib/apache/logger.rb +33 -0
  86. data/lib/arrow.rb +51 -0
  87. data/lib/arrow/acceptparam.rb +207 -0
  88. data/lib/arrow/applet.rb +725 -0
  89. data/lib/arrow/appletmixins.rb +218 -0
  90. data/lib/arrow/appletregistry.rb +590 -0
  91. data/lib/arrow/applettestcase.rb +503 -0
  92. data/lib/arrow/broker.rb +255 -0
  93. data/lib/arrow/cache.rb +176 -0
  94. data/lib/arrow/config-loaders/yaml.rb +75 -0
  95. data/lib/arrow/config.rb +615 -0
  96. data/lib/arrow/constants.rb +24 -0
  97. data/lib/arrow/cookie.rb +359 -0
  98. data/lib/arrow/cookieset.rb +108 -0
  99. data/lib/arrow/dispatcher.rb +368 -0
  100. data/lib/arrow/dispatcherloader.rb +50 -0
  101. data/lib/arrow/exceptions.rb +61 -0
  102. data/lib/arrow/fallbackhandler.rb +48 -0
  103. data/lib/arrow/formvalidator.rb +631 -0
  104. data/lib/arrow/htmltokenizer.rb +343 -0
  105. data/lib/arrow/logger.rb +488 -0
  106. data/lib/arrow/logger/apacheoutputter.rb +69 -0
  107. data/lib/arrow/logger/arrayoutputter.rb +63 -0
  108. data/lib/arrow/logger/coloroutputter.rb +111 -0
  109. data/lib/arrow/logger/fileoutputter.rb +96 -0
  110. data/lib/arrow/logger/htmloutputter.rb +54 -0
  111. data/lib/arrow/logger/outputter.rb +123 -0
  112. data/lib/arrow/mixins.rb +425 -0
  113. data/lib/arrow/monkeypatches.rb +94 -0
  114. data/lib/arrow/object.rb +117 -0
  115. data/lib/arrow/path.rb +196 -0
  116. data/lib/arrow/service.rb +447 -0
  117. data/lib/arrow/session.rb +289 -0
  118. data/lib/arrow/session/dbstore.rb +100 -0
  119. data/lib/arrow/session/filelock.rb +160 -0
  120. data/lib/arrow/session/filestore.rb +132 -0
  121. data/lib/arrow/session/id.rb +98 -0
  122. data/lib/arrow/session/lock.rb +253 -0
  123. data/lib/arrow/session/md5id.rb +42 -0
  124. data/lib/arrow/session/nulllock.rb +42 -0
  125. data/lib/arrow/session/posixlock.rb +166 -0
  126. data/lib/arrow/session/sha1id.rb +54 -0
  127. data/lib/arrow/session/store.rb +366 -0
  128. data/lib/arrow/session/usertrackid.rb +52 -0
  129. data/lib/arrow/spechelpers.rb +73 -0
  130. data/lib/arrow/template.rb +713 -0
  131. data/lib/arrow/template/attr.rb +31 -0
  132. data/lib/arrow/template/call.rb +31 -0
  133. data/lib/arrow/template/comment.rb +33 -0
  134. data/lib/arrow/template/container.rb +118 -0
  135. data/lib/arrow/template/else.rb +41 -0
  136. data/lib/arrow/template/elsif.rb +44 -0
  137. data/lib/arrow/template/escape.rb +53 -0
  138. data/lib/arrow/template/export.rb +87 -0
  139. data/lib/arrow/template/for.rb +145 -0
  140. data/lib/arrow/template/if.rb +78 -0
  141. data/lib/arrow/template/import.rb +119 -0
  142. data/lib/arrow/template/include.rb +206 -0
  143. data/lib/arrow/template/iterator.rb +208 -0
  144. data/lib/arrow/template/nodes.rb +734 -0
  145. data/lib/arrow/template/parser.rb +571 -0
  146. data/lib/arrow/template/prettyprint.rb +53 -0
  147. data/lib/arrow/template/render.rb +191 -0
  148. data/lib/arrow/template/selectlist.rb +94 -0
  149. data/lib/arrow/template/set.rb +87 -0
  150. data/lib/arrow/template/timedelta.rb +81 -0
  151. data/lib/arrow/template/unless.rb +78 -0
  152. data/lib/arrow/template/urlencode.rb +51 -0
  153. data/lib/arrow/template/yield.rb +139 -0
  154. data/lib/arrow/templatefactory.rb +125 -0
  155. data/lib/arrow/testcase.rb +567 -0
  156. data/lib/arrow/transaction.rb +608 -0
  157. data/rake/191_compat.rb +26 -0
  158. data/rake/dependencies.rb +76 -0
  159. data/rake/documentation.rb +114 -0
  160. data/rake/helpers.rb +502 -0
  161. data/rake/hg.rb +282 -0
  162. data/rake/manual.rb +787 -0
  163. data/rake/packaging.rb +129 -0
  164. data/rake/publishing.rb +278 -0
  165. data/rake/style.rb +62 -0
  166. data/rake/svn.rb +668 -0
  167. data/rake/testing.rb +187 -0
  168. data/rake/verifytask.rb +64 -0
  169. data/spec/arrow/acceptparam_spec.rb +157 -0
  170. data/spec/arrow/applet_spec.rb +575 -0
  171. data/spec/arrow/appletmixins_spec.rb +409 -0
  172. data/spec/arrow/appletregistry_spec.rb +294 -0
  173. data/spec/arrow/broker_spec.rb +153 -0
  174. data/spec/arrow/config_spec.rb +224 -0
  175. data/spec/arrow/cookieset_spec.rb +164 -0
  176. data/spec/arrow/dispatcher_spec.rb +137 -0
  177. data/spec/arrow/dispatcherloader_spec.rb +65 -0
  178. data/spec/arrow/formvalidator_spec.rb +781 -0
  179. data/spec/arrow/logger_spec.rb +346 -0
  180. data/spec/arrow/mixins_spec.rb +120 -0
  181. data/spec/arrow/service_spec.rb +645 -0
  182. data/spec/arrow/session_spec.rb +121 -0
  183. data/spec/arrow/template/iterator_spec.rb +222 -0
  184. data/spec/arrow/templatefactory_spec.rb +185 -0
  185. data/spec/arrow/transaction_spec.rb +319 -0
  186. data/spec/arrow_spec.rb +37 -0
  187. data/spec/lib/appletmatchers.rb +281 -0
  188. data/spec/lib/constants.rb +77 -0
  189. data/spec/lib/helpers.rb +41 -0
  190. data/spec/lib/matchers.rb +44 -0
  191. data/tests/cookie.tests.rb +310 -0
  192. data/tests/path.tests.rb +157 -0
  193. data/tests/session.tests.rb +111 -0
  194. data/tests/session_id.tests.rb +82 -0
  195. data/tests/session_lock.tests.rb +191 -0
  196. data/tests/session_store.tests.rb +53 -0
  197. data/tests/template.tests.rb +1360 -0
  198. metadata +339 -0
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/ruby
2
+
3
+ #
4
+ # Constants for testing
5
+ #
6
+ #
7
+
8
+ require 'arrow'
9
+ require 'arrow/config'
10
+ require 'arrow/constants'
11
+
12
+
13
+ ### A module of testing constants
14
+ module Arrow::TestConstants
15
+
16
+ include Arrow::Constants
17
+
18
+ # Testing config values
19
+ TEST_CONFIG_HASH = {
20
+ :logging => { :global=>"notice" },
21
+ :gems => {
22
+ :require_signed => false,
23
+ :autoinstall => false,
24
+ :path => Arrow::Path.new([ "gems", *Gem.path ]),
25
+ :applets => {},
26
+ },
27
+ :applets => {
28
+ :pollInterval => 5,
29
+ :pattern => "*.rb",
30
+ :missingApplet => "/missing",
31
+ :errorApplet => "/error",
32
+ :path => [
33
+ "spec/data/applets",
34
+ "applets"
35
+ ],
36
+ :config => {},
37
+ :layout => {
38
+ :"/" => "Setup",
39
+ :"/missing" => "NoSuchAppletHandler",
40
+ :"/error" => "ErrorHandler",
41
+ },
42
+ },
43
+
44
+ :session => {
45
+ :idType => "md5:.",
46
+ :lockType => "recommended",
47
+ :storeType => "file:spec/data/sessions",
48
+ :idName => "arrow-session",
49
+ :rewriteUrls => true,
50
+ :expires => "+48h",
51
+ },
52
+
53
+ :templates => {
54
+ :cacheConfig => {
55
+ :maxNum => 20,
56
+ :maxSize => 2621440,
57
+ :maxObjSize => 131072,
58
+ :expiration => 36
59
+ },
60
+ :cache => true,
61
+ :path => [
62
+ "spec/data",
63
+ ],
64
+ :loader => "Arrow::Template",
65
+ },
66
+ }
67
+
68
+ TEST_CONFIG_HASH.freeze
69
+
70
+
71
+ TEST_CONFIG = Arrow::Config.new( TEST_CONFIG_HASH )
72
+ TEST_CONFIG.freeze
73
+
74
+
75
+ end
76
+
77
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+
3
+ #
4
+ # Some helper functions for RSpec specifications
5
+ #
6
+ #
7
+
8
+ require 'arrow'
9
+ require 'arrow/logger/htmloutputter'
10
+
11
+ ### A module of miscellaneous stuff that makes running RSpec a little nicer
12
+ module Arrow::SpecHelpers
13
+
14
+ # The default logging level for reset_logging/setup_logging
15
+ DEFAULT_LOG_LEVEL = :crit
16
+
17
+ ### Remove any outputters and reset the level to DEFAULT_LOG_LEVEL
18
+ def reset_logging
19
+ Arrow::Logger.reset
20
+ end
21
+
22
+ ### Set up an HTML log outputter at the specified +level+ that's been tailored to SpecMate
23
+ ### output.
24
+ def setup_logging( level=DEFAULT_LOG_LEVEL )
25
+ reset_logging()
26
+ description = "`%s' spec" % [ @_defined_description ]
27
+
28
+ # Only do this when executing from a spec in TextMate
29
+ if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
30
+ outputter = Arrow::Logger::Outputter.create( 'array' )
31
+ Thread.current['logger-output'] = outputter.array
32
+ else
33
+ outputter = Arrow::Logger::Outputter.create( 'color:stderr', description )
34
+ end
35
+
36
+ Arrow::Logger.global.outputters << outputter
37
+ Arrow::Logger::global.level = level
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,44 @@
1
+ #
2
+ # A collection of custom matchers for Arrow specifications
3
+ # $Id$
4
+ #
5
+
6
+ BEGIN {
7
+ require 'pathname'
8
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent
9
+
10
+ libdir = basedir + "lib"
11
+
12
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
13
+ }
14
+
15
+ require 'arrow'
16
+
17
+ module Arrow
18
+
19
+ module TimeMatchers
20
+ class BeAfter
21
+ def initialize( expected )
22
+ @expected = expected
23
+ end
24
+
25
+ def matches?( actual )
26
+ @actual = actual
27
+ @actual > @expected
28
+ end
29
+
30
+ def failure_message
31
+ "expected #{@actual} to be after #{@expected}"
32
+ end
33
+
34
+ def negative_failure_message
35
+ "expected #{@actual} not to be after #{@expected}"
36
+ end
37
+ end
38
+
39
+ def be_after( expected )
40
+ BeAfter.new( expected )
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,310 @@
1
+ #!/usr/bin/env ruby -w
2
+ #
3
+ # Unit test for the Arrow::Cookie class
4
+ # $Id$
5
+ #
6
+ # Copyright (c) (2006) RubyCrafters, LLC. Most rights reserved.
7
+ #
8
+ # This work is licensed under the Creative Commons Attribution-ShareAlike
9
+ # License. To view a copy of this license, visit
10
+ # http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative
11
+ # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12
+ #
13
+ #
14
+
15
+ unless defined? Arrow::TestCase
16
+ require 'pathname'
17
+
18
+ testsdir = Pathname.new(__FILE__).dirname.expand_path
19
+ basedir = testsdir.parent
20
+ libdir = basedir + 'lib'
21
+
22
+ $LOAD_PATH.unshift( libdir.to_s ) unless
23
+ $LOAD_PATH.include?( libdir.to_s )
24
+
25
+ require 'arrow/testcase'
26
+ end
27
+
28
+ require 'arrow/cookie'
29
+
30
+ ### Collection of tests for the Arrow::Cookie class.
31
+ class Arrow::CookieTestCase < Arrow::TestCase
32
+
33
+ SetCookie = 'trac_session=9917eb0543e34ff5921fbc45323a17f5; ' +
34
+ 'expires=Thu, 06-Jul-2006 22:15:58 GMT; Path=/projects/Arrow;'
35
+ Cookie = 'Cookie=trac_session=9917eb0543e34ff5921fbc45323a17f5; ' +
36
+ 'trac_auth=7eb12e3e5397d3435acb27fdf7061b98'
37
+
38
+
39
+ def setup
40
+ super
41
+ @cookie = Arrow::Cookie.new( "by_rickirac", "9917eb" )
42
+ end
43
+
44
+
45
+ #################################################################
46
+ ### T E S T S
47
+ #################################################################
48
+
49
+ def test_parse_with_nil_field_doesnt_error
50
+ rval = nil
51
+ assert_nothing_raised do
52
+ rval = Arrow::Cookie.parse( nil )
53
+ end
54
+
55
+ assert_instance_of Hash, rval
56
+ assert_equal 0, rval.length
57
+ end
58
+
59
+ def test_parse_with_empty_field_doesnt_error
60
+ rval = nil
61
+ assert_nothing_raised do
62
+ rval = Arrow::Cookie.parse( '' )
63
+ end
64
+
65
+ assert_instance_of Hash, rval
66
+ assert_equal 0, rval.length
67
+ end
68
+
69
+ def test_parse_single_value_cookie_should_return_single_value
70
+ rval = nil
71
+
72
+ assert_nothing_raised do
73
+ rval = Arrow::Cookie.parse( "a=b" )
74
+ end
75
+
76
+ assert_instance_of Hash, rval
77
+ assert_equal 1, rval.length
78
+
79
+ cookie = rval['a']
80
+ assert_instance_of Arrow::Cookie, cookie
81
+ assert_equal "a", cookie.name
82
+ assert_equal "b", cookie.value
83
+ assert_equal ["b"], cookie.values
84
+ end
85
+
86
+
87
+ def test_parse_multi_value_cookie_should_return_multiple_values
88
+ rval = nil
89
+
90
+ assert_nothing_raised do
91
+ rval = Arrow::Cookie.parse( "a=b&c" )
92
+ end
93
+
94
+ assert_instance_of Hash, rval
95
+ assert_equal 1, rval.length
96
+
97
+ cookie = rval['a']
98
+ assert_instance_of Arrow::Cookie, cookie
99
+ assert_equal "a", cookie.name
100
+ assert_equal "b", cookie.value
101
+ assert_equal ["b", "c"], cookie.values
102
+ end
103
+
104
+
105
+ def test_parse_two_multi_value_cookies_should_return_two_cookies_with_multiple_values
106
+ rval = nil
107
+
108
+ assert_nothing_raised do
109
+ rval = Arrow::Cookie.parse( "a=b&c; f=o&o" )
110
+ end
111
+
112
+ assert_instance_of Hash, rval
113
+ assert_equal 2, rval.length
114
+
115
+ cookie = rval['a']
116
+ assert_instance_of Arrow::Cookie, cookie
117
+ assert_equal "a", cookie.name
118
+ assert_equal "b", cookie.value
119
+ assert_equal ["b", "c"], cookie.values
120
+
121
+ cookie = rval['f']
122
+ assert_instance_of Arrow::Cookie, cookie
123
+ assert_equal "f", cookie.name
124
+ assert_equal "o", cookie.value
125
+ assert_equal ["o", "o"], cookie.values
126
+ end
127
+
128
+
129
+ def test_parse_with_empty_value_should_return_cookie_nonetheless
130
+ rval = nil
131
+
132
+ assert_nothing_raised do
133
+ rval = Arrow::Cookie.parse( "a=" )
134
+ end
135
+
136
+ assert_instance_of Hash, rval
137
+ assert_equal 1, rval.length
138
+
139
+ cookie = rval['a']
140
+ assert_instance_of Arrow::Cookie, cookie
141
+ assert_equal "a", cookie.name
142
+ assert_equal nil, cookie.value
143
+ assert_equal [], cookie.values
144
+ end
145
+
146
+
147
+ def test_parse_with_version_should_set_version
148
+ rval = nil
149
+
150
+ assert_nothing_raised do
151
+ rval = Arrow::Cookie.parse( %{$Version=1; a="b"} )
152
+ end
153
+
154
+ assert_instance_of Hash, rval
155
+ assert_equal 1, rval.length, "should be one cookie"
156
+
157
+ cookie = rval['a']
158
+ assert_instance_of Arrow::Cookie, cookie
159
+ assert_equal "a", cookie.name
160
+ assert_equal "b", cookie.value
161
+ assert_equal ["b"], cookie.values
162
+
163
+ assert_equal 1, cookie.version, "cookie version should be 1"
164
+ end
165
+
166
+
167
+ def test_parse_with_path_should_set_path
168
+ rval = nil
169
+
170
+ assert_nothing_raised do
171
+ rval = Arrow::Cookie.parse( %{a=b; $Path=/arrow} )
172
+ end
173
+
174
+ assert_instance_of Hash, rval
175
+ assert_equal 1, rval.length, "should be one cookie"
176
+
177
+ cookie = rval['a']
178
+ assert_instance_of Arrow::Cookie, cookie
179
+ assert_equal "a", cookie.name
180
+ assert_equal "b", cookie.value
181
+ assert_equal ["b"], cookie.values
182
+
183
+ assert_equal "/arrow", cookie.path, "cookie path should be /arrow"
184
+
185
+ end
186
+
187
+ def test_parse_with_domain_should_set_domain
188
+ rval = nil
189
+
190
+ assert_nothing_raised do
191
+ rval = Arrow::Cookie.parse( %{a=b; $domain=rubycrafters.com} )
192
+ end
193
+
194
+ assert_instance_of Hash, rval
195
+ assert_equal 1, rval.length, "should be one cookie"
196
+
197
+ cookie = rval['a']
198
+ assert_instance_of Arrow::Cookie, cookie
199
+ assert_equal "a", cookie.name
200
+ assert_equal "b", cookie.value
201
+ assert_equal ["b"], cookie.values
202
+
203
+ assert_equal ".rubycrafters.com", cookie.domain,
204
+ "cookie domain should be '.rubycrafters.com'"
205
+ end
206
+
207
+ def test_parse_with_invalid_cookie_name_doesnt_error
208
+ rval = nil
209
+ assert_nothing_raised do
210
+ rval = Arrow::Cookie.parse( "{a}=foo" )
211
+ end
212
+
213
+ assert_instance_of Hash, rval
214
+ assert_equal 0, rval.length
215
+ end
216
+
217
+ def test_to_s_with_single_value_generates_valid_cookie
218
+ rval = nil
219
+ assert_nothing_raised do
220
+ rval = @cookie.to_s
221
+ end
222
+
223
+ assert_equal %{by_rickirac=9917eb}, rval
224
+ end
225
+
226
+ def test_to_s_with_multiple_values_generates_valid_cookie
227
+ rval = nil
228
+ @cookie.values += ["brer lapin"]
229
+ assert_nothing_raised do
230
+ rval = @cookie.to_s
231
+ end
232
+
233
+ assert_equal %{by_rickirac=9917eb&brer%20lapin}, rval
234
+ end
235
+
236
+ def test_to_s_adds_version_for_versions_other_than_0
237
+ rval = nil
238
+ @cookie.version = 1
239
+ assert_nothing_raised do
240
+ rval = @cookie.to_s
241
+ end
242
+
243
+ assert_equal %{by_rickirac=9917eb; Version=1}, rval
244
+ end
245
+
246
+ def test_explicitly_specified_domain_must_always_start_with_a_dot
247
+ rval = nil
248
+ @cookie.domain = "foo.com"
249
+ assert_nothing_raised do
250
+ rval = @cookie.to_s
251
+ end
252
+
253
+ assert_equal %{by_rickirac=9917eb; Domain=.foo.com}, rval
254
+ end
255
+
256
+ def test_domain_eq_shouldnt_prepend_a_dot_if_it_already_has_one
257
+ rval = nil
258
+ @cookie.domain = ".rubycrafters.com"
259
+ assert_nothing_raised do
260
+ rval = @cookie.to_s
261
+ end
262
+ assert_equal %{by_rickirac=9917eb; Domain=.rubycrafters.com}, rval
263
+ end
264
+
265
+ def test_value_with_semicolon_is_escaped
266
+ rval = nil
267
+ @cookie.values += [%{"modern technology"; ain't it a paradox?}]
268
+ assert_nothing_raised do
269
+ rval = @cookie.to_s
270
+ end
271
+
272
+ assert_equal %{by_rickirac=9917eb&%22modern%20technology} +
273
+ %{%22%3B%20ain't%20it%20a%20paradox%3F}, rval
274
+ end
275
+
276
+ def test_expires_value_is_in_correct_format
277
+ rval = nil
278
+ now = Time.now
279
+ nowstring = now.gmtime.strftime( "%a, %d-%b-%Y %H:%M:%S GMT" )
280
+ @cookie.expires = now
281
+
282
+ assert_nothing_raised do
283
+ rval = @cookie.to_s
284
+ end
285
+
286
+ assert_include nowstring, rval
287
+ end
288
+
289
+ def test_cookies_with_the_same_name_should_be_considered_equal
290
+ other_cookie = Arrow::Cookie.new( "by_rickirac", "something else" )
291
+ assert @cookie.eql?( other_cookie ),
292
+ "%p should be eql? to %p" % [ @cookie, other_cookie ]
293
+ end
294
+
295
+ def test_cookie_expire_bang_should_set_the_expiration_date_to_a_time_in_the_past
296
+ assert_nothing_raised do
297
+ @cookie.expire!
298
+ end
299
+
300
+ expiration = @cookie.expires
301
+ assert expiration < Time.now - (25 * 60)
302
+ end
303
+
304
+
305
+ def test_cookie_hash_should_use_the_hash_of_the_cookies_name
306
+ assert_equal @cookie.name.hash, @cookie.hash
307
+ end
308
+
309
+ end
310
+