arrow 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +1590 -0
- data/LICENSE +28 -0
- data/README +75 -0
- data/Rakefile +366 -0
- data/Rakefile.local +63 -0
- data/data/arrow/applets/TEMPLATE.rb.tpl +53 -0
- data/data/arrow/applets/args.rb +50 -0
- data/data/arrow/applets/config.rb +55 -0
- data/data/arrow/applets/error.rb +63 -0
- data/data/arrow/applets/files.rb +46 -0
- data/data/arrow/applets/inspect.rb +46 -0
- data/data/arrow/applets/nosuchapplet.rb +31 -0
- data/data/arrow/applets/status.rb +92 -0
- data/data/arrow/applets/test.rb +133 -0
- data/data/arrow/applets/tutorial/counter.rb +96 -0
- data/data/arrow/applets/tutorial/dingus.rb +67 -0
- data/data/arrow/applets/tutorial/hello.rb +34 -0
- data/data/arrow/applets/tutorial/hello2.rb +73 -0
- data/data/arrow/applets/tutorial/imgtext.rb +90 -0
- data/data/arrow/applets/tutorial/imgtext2.rb +286 -0
- data/data/arrow/applets/tutorial/index.rb +36 -0
- data/data/arrow/applets/tutorial/logo.rb +98 -0
- data/data/arrow/applets/tutorial/memcache.rb +61 -0
- data/data/arrow/applets/tutorial/missing.rb +37 -0
- data/data/arrow/applets/tutorial/protected.rb +100 -0
- data/data/arrow/applets/tutorial/redirector.rb +52 -0
- data/data/arrow/applets/tutorial/rndimages.rb +159 -0
- data/data/arrow/applets/tutorial/sharenotes.rb +83 -0
- data/data/arrow/applets/tutorial/subclassed-hello.rb +32 -0
- data/data/arrow/applets/tutorial/superhello.rb +72 -0
- data/data/arrow/applets/tutorial/timeclock.rb +78 -0
- data/data/arrow/applets/view-applet.rb +123 -0
- data/data/arrow/applets/view-template.rb +85 -0
- data/data/arrow/applets/wiki.rb +274 -0
- data/data/arrow/templates/TEMPLATE.tmpl.tpl +36 -0
- data/data/arrow/templates/applet-status.tmpl +153 -0
- data/data/arrow/templates/args-display.tmpl +120 -0
- data/data/arrow/templates/config/display-table.tmpl +36 -0
- data/data/arrow/templates/config/display.tmpl +36 -0
- data/data/arrow/templates/counter-deleted.tmpl +33 -0
- data/data/arrow/templates/counter.tmpl +59 -0
- data/data/arrow/templates/dingus.tmpl +55 -0
- data/data/arrow/templates/enumtable.tmpl +8 -0
- data/data/arrow/templates/error-display.tmpl +92 -0
- data/data/arrow/templates/filemap.tmpl +89 -0
- data/data/arrow/templates/hello-world-src.tmpl +34 -0
- data/data/arrow/templates/hello-world.tmpl +60 -0
- data/data/arrow/templates/imgtext/fontlist.tmpl +46 -0
- data/data/arrow/templates/imgtext/form.tmpl +70 -0
- data/data/arrow/templates/imgtext/reload-error.tmpl +40 -0
- data/data/arrow/templates/imgtext/reload.tmpl +55 -0
- data/data/arrow/templates/inspect/display.tmpl +80 -0
- data/data/arrow/templates/loginform.tmpl +64 -0
- data/data/arrow/templates/logout.tmpl +32 -0
- data/data/arrow/templates/memcache/display.tmpl +41 -0
- data/data/arrow/templates/navbar.incl +27 -0
- data/data/arrow/templates/nosuchapplet.tmpl +32 -0
- data/data/arrow/templates/printsource.tmpl +35 -0
- data/data/arrow/templates/protected.tmpl +36 -0
- data/data/arrow/templates/rndimages.tmpl +38 -0
- data/data/arrow/templates/service-response.tmpl +13 -0
- data/data/arrow/templates/sharenotes/display.tmpl +38 -0
- data/data/arrow/templates/status.tmpl +120 -0
- data/data/arrow/templates/templateviewer.tmpl +43 -0
- data/data/arrow/templates/test/harness.tmpl +57 -0
- data/data/arrow/templates/test/list.tmpl +48 -0
- data/data/arrow/templates/test/problem.tmpl +42 -0
- data/data/arrow/templates/tutorial/index.tmpl +37 -0
- data/data/arrow/templates/tutorial/missingapplet.tmpl +29 -0
- data/data/arrow/templates/view-applet-nosuch.tmpl +32 -0
- data/data/arrow/templates/view-applet.tmpl +40 -0
- data/data/arrow/templates/view-template.tmpl +83 -0
- data/data/arrow/templates/wiki/formerror.tmpl +47 -0
- data/data/arrow/templates/wiki/markup_help.incl +6 -0
- data/data/arrow/templates/wiki/new.tmpl +56 -0
- data/data/arrow/templates/wiki/new_system.tmpl +122 -0
- data/data/arrow/templates/wiki/sectionlist.tmpl +43 -0
- data/data/arrow/templates/wiki/show.tmpl +34 -0
- data/docs/manual/layouts/default.page +43 -0
- data/docs/manual/lib/api-filter.rb +81 -0
- data/docs/manual/lib/editorial-filter.rb +64 -0
- data/docs/manual/lib/examples-filter.rb +244 -0
- data/docs/manual/lib/links-filter.rb +117 -0
- data/lib/apache/fakerequest.rb +448 -0
- data/lib/apache/logger.rb +33 -0
- data/lib/arrow.rb +51 -0
- data/lib/arrow/acceptparam.rb +207 -0
- data/lib/arrow/applet.rb +725 -0
- data/lib/arrow/appletmixins.rb +218 -0
- data/lib/arrow/appletregistry.rb +590 -0
- data/lib/arrow/applettestcase.rb +503 -0
- data/lib/arrow/broker.rb +255 -0
- data/lib/arrow/cache.rb +176 -0
- data/lib/arrow/config-loaders/yaml.rb +75 -0
- data/lib/arrow/config.rb +615 -0
- data/lib/arrow/constants.rb +24 -0
- data/lib/arrow/cookie.rb +359 -0
- data/lib/arrow/cookieset.rb +108 -0
- data/lib/arrow/dispatcher.rb +368 -0
- data/lib/arrow/dispatcherloader.rb +50 -0
- data/lib/arrow/exceptions.rb +61 -0
- data/lib/arrow/fallbackhandler.rb +48 -0
- data/lib/arrow/formvalidator.rb +631 -0
- data/lib/arrow/htmltokenizer.rb +343 -0
- data/lib/arrow/logger.rb +488 -0
- data/lib/arrow/logger/apacheoutputter.rb +69 -0
- data/lib/arrow/logger/arrayoutputter.rb +63 -0
- data/lib/arrow/logger/coloroutputter.rb +111 -0
- data/lib/arrow/logger/fileoutputter.rb +96 -0
- data/lib/arrow/logger/htmloutputter.rb +54 -0
- data/lib/arrow/logger/outputter.rb +123 -0
- data/lib/arrow/mixins.rb +425 -0
- data/lib/arrow/monkeypatches.rb +94 -0
- data/lib/arrow/object.rb +117 -0
- data/lib/arrow/path.rb +196 -0
- data/lib/arrow/service.rb +447 -0
- data/lib/arrow/session.rb +289 -0
- data/lib/arrow/session/dbstore.rb +100 -0
- data/lib/arrow/session/filelock.rb +160 -0
- data/lib/arrow/session/filestore.rb +132 -0
- data/lib/arrow/session/id.rb +98 -0
- data/lib/arrow/session/lock.rb +253 -0
- data/lib/arrow/session/md5id.rb +42 -0
- data/lib/arrow/session/nulllock.rb +42 -0
- data/lib/arrow/session/posixlock.rb +166 -0
- data/lib/arrow/session/sha1id.rb +54 -0
- data/lib/arrow/session/store.rb +366 -0
- data/lib/arrow/session/usertrackid.rb +52 -0
- data/lib/arrow/spechelpers.rb +73 -0
- data/lib/arrow/template.rb +713 -0
- data/lib/arrow/template/attr.rb +31 -0
- data/lib/arrow/template/call.rb +31 -0
- data/lib/arrow/template/comment.rb +33 -0
- data/lib/arrow/template/container.rb +118 -0
- data/lib/arrow/template/else.rb +41 -0
- data/lib/arrow/template/elsif.rb +44 -0
- data/lib/arrow/template/escape.rb +53 -0
- data/lib/arrow/template/export.rb +87 -0
- data/lib/arrow/template/for.rb +145 -0
- data/lib/arrow/template/if.rb +78 -0
- data/lib/arrow/template/import.rb +119 -0
- data/lib/arrow/template/include.rb +206 -0
- data/lib/arrow/template/iterator.rb +208 -0
- data/lib/arrow/template/nodes.rb +734 -0
- data/lib/arrow/template/parser.rb +571 -0
- data/lib/arrow/template/prettyprint.rb +53 -0
- data/lib/arrow/template/render.rb +191 -0
- data/lib/arrow/template/selectlist.rb +94 -0
- data/lib/arrow/template/set.rb +87 -0
- data/lib/arrow/template/timedelta.rb +81 -0
- data/lib/arrow/template/unless.rb +78 -0
- data/lib/arrow/template/urlencode.rb +51 -0
- data/lib/arrow/template/yield.rb +139 -0
- data/lib/arrow/templatefactory.rb +125 -0
- data/lib/arrow/testcase.rb +567 -0
- data/lib/arrow/transaction.rb +608 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/documentation.rb +114 -0
- data/rake/helpers.rb +502 -0
- data/rake/hg.rb +282 -0
- data/rake/manual.rb +787 -0
- data/rake/packaging.rb +129 -0
- data/rake/publishing.rb +278 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +668 -0
- data/rake/testing.rb +187 -0
- data/rake/verifytask.rb +64 -0
- data/spec/arrow/acceptparam_spec.rb +157 -0
- data/spec/arrow/applet_spec.rb +575 -0
- data/spec/arrow/appletmixins_spec.rb +409 -0
- data/spec/arrow/appletregistry_spec.rb +294 -0
- data/spec/arrow/broker_spec.rb +153 -0
- data/spec/arrow/config_spec.rb +224 -0
- data/spec/arrow/cookieset_spec.rb +164 -0
- data/spec/arrow/dispatcher_spec.rb +137 -0
- data/spec/arrow/dispatcherloader_spec.rb +65 -0
- data/spec/arrow/formvalidator_spec.rb +781 -0
- data/spec/arrow/logger_spec.rb +346 -0
- data/spec/arrow/mixins_spec.rb +120 -0
- data/spec/arrow/service_spec.rb +645 -0
- data/spec/arrow/session_spec.rb +121 -0
- data/spec/arrow/template/iterator_spec.rb +222 -0
- data/spec/arrow/templatefactory_spec.rb +185 -0
- data/spec/arrow/transaction_spec.rb +319 -0
- data/spec/arrow_spec.rb +37 -0
- data/spec/lib/appletmatchers.rb +281 -0
- data/spec/lib/constants.rb +77 -0
- data/spec/lib/helpers.rb +41 -0
- data/spec/lib/matchers.rb +44 -0
- data/tests/cookie.tests.rb +310 -0
- data/tests/path.tests.rb +157 -0
- data/tests/session.tests.rb +111 -0
- data/tests/session_id.tests.rb +82 -0
- data/tests/session_lock.tests.rb +191 -0
- data/tests/session_store.tests.rb +53 -0
- data/tests/template.tests.rb +1360 -0
- metadata +339 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
require 'pathname'
|
5
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
+
|
7
|
+
libdir = basedir + "lib"
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
10
|
+
}
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'spec'
|
14
|
+
require 'apache/fakerequest'
|
15
|
+
require 'arrow'
|
16
|
+
require 'spec/lib/helpers'
|
17
|
+
require 'arrow/broker'
|
18
|
+
rescue LoadError
|
19
|
+
unless Object.const_defined?( :Gem )
|
20
|
+
require 'rubygems'
|
21
|
+
retry
|
22
|
+
end
|
23
|
+
raise
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
#####################################################################
|
28
|
+
### C O N T E X T S
|
29
|
+
#####################################################################
|
30
|
+
|
31
|
+
describe Arrow::Broker do
|
32
|
+
include Arrow::SpecHelpers
|
33
|
+
|
34
|
+
before( :all ) do
|
35
|
+
setup_logging( :crit )
|
36
|
+
end
|
37
|
+
|
38
|
+
after( :all ) do
|
39
|
+
reset_logging()
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
before( :each ) do
|
44
|
+
conf = Arrow::Config.new( TEST_CONFIG )
|
45
|
+
@broker = Arrow::Broker.new( conf )
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
#################################################################
|
50
|
+
### H E L P E R F U N C T I O N S
|
51
|
+
#################################################################
|
52
|
+
|
53
|
+
def make_applet_chain( uri, *applets )
|
54
|
+
chain = []
|
55
|
+
uriparts = uri.split( %r{/} )
|
56
|
+
|
57
|
+
applets.each_with_index do |applet, i|
|
58
|
+
chain << Arrow::AppletRegistry::ChainLink.new(
|
59
|
+
applet,
|
60
|
+
uriparts[0..i+1].join('/'),
|
61
|
+
uriparts[i+2 .. -1] || []
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
return chain
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
#################################################################
|
70
|
+
### E X A M P L E S
|
71
|
+
#################################################################
|
72
|
+
|
73
|
+
it "runs an applet when dispatching a uri that maps to it" do
|
74
|
+
applet = mock( "applet", :null_object => true )
|
75
|
+
appletchain = make_applet_chain( '/admin/create/job/1', applet )
|
76
|
+
@broker.registry = stub( "applet registry",
|
77
|
+
:check_for_updates => true,
|
78
|
+
:find_applet_chain => appletchain
|
79
|
+
)
|
80
|
+
|
81
|
+
txn = mock( "transaction", :null_object => true )
|
82
|
+
txn.should_receive( :path ).and_return( '/admin/create/job/1' )
|
83
|
+
|
84
|
+
applet.should_receive( :run ).
|
85
|
+
with( txn, "create", "job", "1" ).
|
86
|
+
and_return( :passed )
|
87
|
+
|
88
|
+
@broker.delegate( txn ).should == :passed
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
it "chains calls through multiple applets when a uri maps to more than one" do
|
93
|
+
applet1 = mock( "delegating applet 1" )
|
94
|
+
applet2 = mock( "delegating applet 2" )
|
95
|
+
applet3 = mock( "target applet" )
|
96
|
+
|
97
|
+
appletchain = make_applet_chain( '/admin/create/job/1', applet1, applet2, applet3 )
|
98
|
+
@broker.registry = stub( "applet registry",
|
99
|
+
:check_for_updates => true,
|
100
|
+
:find_applet_chain => appletchain
|
101
|
+
)
|
102
|
+
|
103
|
+
txn = mock( "transaction", :null_object => true )
|
104
|
+
txn.should_receive( :path ).and_return( '/admin/create/job/1' )
|
105
|
+
signature = stub( "applet signature", :name => 'mock applet' )
|
106
|
+
|
107
|
+
applet1.should_receive( :signature ).
|
108
|
+
at_least(:once).
|
109
|
+
and_return( signature )
|
110
|
+
applet1.should_receive( :delegate ).
|
111
|
+
with( txn, appletchain[1,2], "create", "job", "1" ).
|
112
|
+
and_yield( nil )
|
113
|
+
applet2.should_receive( :signature ).
|
114
|
+
at_least(:once).
|
115
|
+
and_return( signature )
|
116
|
+
applet2.should_receive( :delegate ).
|
117
|
+
with( txn, appletchain[2..2], "job", "1" ).
|
118
|
+
and_yield( nil )
|
119
|
+
applet3.should_receive( :signature ).
|
120
|
+
at_least(:once).
|
121
|
+
and_return( signature )
|
122
|
+
applet3.should_receive( :run ).
|
123
|
+
with( txn, "1" ).
|
124
|
+
and_return( :passed )
|
125
|
+
|
126
|
+
@broker.delegate( txn ) #.should == :passed # RSpec 1.0 broke this
|
127
|
+
end
|
128
|
+
|
129
|
+
describe " for a root-mounted dispatcher" do
|
130
|
+
|
131
|
+
it "runs the root applet for a request to an empty path" do
|
132
|
+
conf = Arrow::Config.new( TEST_CONFIG )
|
133
|
+
broker = Arrow::Broker.new( conf )
|
134
|
+
|
135
|
+
applet = mock( "applet", :null_object => true )
|
136
|
+
appletchain = make_applet_chain( '/', applet )
|
137
|
+
broker.registry = stub( "applet registry",
|
138
|
+
:check_for_updates => true,
|
139
|
+
:find_applet_chain => appletchain
|
140
|
+
)
|
141
|
+
|
142
|
+
txn = mock( "transaction", :null_object => true )
|
143
|
+
txn.should_receive( :path ).and_return( '' )
|
144
|
+
|
145
|
+
applet.should_receive( :run ).
|
146
|
+
with( txn ).
|
147
|
+
and_return( :passed )
|
148
|
+
|
149
|
+
broker.delegate( txn ).should == :passed
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Specification for the Arrow::Config class
|
4
|
+
# $Id$
|
5
|
+
#
|
6
|
+
# Copyright (c) 2004-2008 The FaerieMUD Consortium. Most rights reserved.
|
7
|
+
#
|
8
|
+
|
9
|
+
BEGIN {
|
10
|
+
require 'pathname'
|
11
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
12
|
+
|
13
|
+
libdir = basedir + "lib"
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
16
|
+
}
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'spec'
|
20
|
+
require 'apache/fakerequest'
|
21
|
+
require 'arrow'
|
22
|
+
require 'arrow/config'
|
23
|
+
|
24
|
+
require 'spec/lib/helpers'
|
25
|
+
require 'spec/lib/constants'
|
26
|
+
rescue LoadError
|
27
|
+
unless Object.const_defined?( :Gem )
|
28
|
+
require 'rubygems'
|
29
|
+
retry
|
30
|
+
end
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
include Arrow::TestConstants
|
36
|
+
|
37
|
+
|
38
|
+
#####################################################################
|
39
|
+
### C O N T E X T S
|
40
|
+
#####################################################################
|
41
|
+
|
42
|
+
describe Arrow::Config do
|
43
|
+
include Arrow::SpecHelpers
|
44
|
+
|
45
|
+
before( :all ) do
|
46
|
+
setup_logging( :crit )
|
47
|
+
end
|
48
|
+
|
49
|
+
after( :all ) do
|
50
|
+
reset_logging()
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
#################################################################
|
56
|
+
### E X A M P L E S
|
57
|
+
#################################################################
|
58
|
+
|
59
|
+
describe Arrow::Config::ConfigStruct do
|
60
|
+
|
61
|
+
it "can be constructed from a Hash" do
|
62
|
+
struct = Arrow::Config::ConfigStruct.new( TEST_CONFIG_HASH )
|
63
|
+
struct.should have(5).members
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "instance" do
|
67
|
+
before( :each ) do
|
68
|
+
@struct = Arrow::Config::ConfigStruct.new( TEST_CONFIG_HASH )
|
69
|
+
end
|
70
|
+
|
71
|
+
it "knows what its keys are" do
|
72
|
+
@struct.keys.should have( TEST_CONFIG_HASH.length ).members
|
73
|
+
@struct.keys.should include( *TEST_CONFIG_HASH.keys )
|
74
|
+
end
|
75
|
+
|
76
|
+
it "knows if it has a particular key" do
|
77
|
+
@struct.should have_key( :templates )
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can look up its values via the Hash index interface" do
|
81
|
+
@struct[:applets][:path].should == TEST_CONFIG_HASH[:applets][:path]
|
82
|
+
end
|
83
|
+
|
84
|
+
it "can turn itself back into a Hash" do
|
85
|
+
@struct.to_hash.should == TEST_CONFIG_HASH
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
it "has reasonable defaults when instantiated without arguments" do
|
94
|
+
config = Arrow::Config.new
|
95
|
+
config.to_hash.should == Arrow::Config::DEFAULTS
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
it "can be initialized with a Hash" do
|
100
|
+
config = Arrow::Config.new( TEST_CONFIG_HASH.dup )
|
101
|
+
config.to_hash.should == TEST_CONFIG_HASH
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
### Test instantiation of the Config class with configuration values.
|
106
|
+
def test_11_InstantiationWithArgs
|
107
|
+
printTestHeader "Arrow::Config: Instantiation with arguments"
|
108
|
+
rval = config = nil
|
109
|
+
|
110
|
+
assert_nothing_raised {
|
111
|
+
config = Arrow::Config.new( TestConfig )
|
112
|
+
}
|
113
|
+
assert_instance_of Arrow::Config, config
|
114
|
+
|
115
|
+
# The configuration values should be the test config merged with the
|
116
|
+
# defaults for the config class.
|
117
|
+
(TestConfig.keys|Arrow::Config::DEFAULTS.keys).each {|key|
|
118
|
+
val = TestConfig[key] || Arrow::Config::DEFAULTS[key]
|
119
|
+
assert_nothing_raised { rval = config.send(key) }
|
120
|
+
assert_config_equal val, rval, key
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
### Test the abstract Config::Loader class.
|
126
|
+
def test_30_Loader
|
127
|
+
printTestHeader "Arrow::Config: Loader base class"
|
128
|
+
rval = loader = nil
|
129
|
+
createTime = Time.now
|
130
|
+
|
131
|
+
assert_nothing_raised { loader = Arrow::Config::Loader.create('test') }
|
132
|
+
assert_kind_of Arrow::Config::Loader, loader
|
133
|
+
|
134
|
+
# The #load method
|
135
|
+
assert_respond_to loader, :load
|
136
|
+
assert_nothing_raised { rval = loader.load("foo") }
|
137
|
+
assert_instance_of Hash, rval
|
138
|
+
assert rval.key?( :applets ), "Loaded hash has an :applets key"
|
139
|
+
assert rval.key?( :templates ), "Loaded hash has a :templates key"
|
140
|
+
|
141
|
+
# The #save method
|
142
|
+
assert_respond_to loader, :save
|
143
|
+
assert_nothing_raised { loader.save(rval, "foo") }
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
### Test the .create method of Loader with the YAML Loader class.
|
148
|
+
def test_31_CreateYamlLoader
|
149
|
+
printTestHeader "Arrow::Config: YAML loader"
|
150
|
+
loader = rval = nil
|
151
|
+
|
152
|
+
assert_nothing_raised {
|
153
|
+
loader = Arrow::Config::Loader.create( 'yaml' )
|
154
|
+
}
|
155
|
+
assert_kind_of Arrow::Config::Loader, loader
|
156
|
+
|
157
|
+
assert_nothing_raised {
|
158
|
+
loader = Arrow::Config::Loader.create( 'YAML' )
|
159
|
+
}
|
160
|
+
assert_kind_of Arrow::Config::Loader, loader
|
161
|
+
|
162
|
+
assert_nothing_raised {
|
163
|
+
loader = Arrow::Config::Loader.create( 'Yaml' )
|
164
|
+
}
|
165
|
+
assert_kind_of Arrow::Config::Loader, loader
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
### Write config
|
170
|
+
def test_40_ConfigWriteRead
|
171
|
+
printTestHeader "Arrow::Config: #write and #read"
|
172
|
+
|
173
|
+
config = Arrow::Config.new( TestConfig )
|
174
|
+
assert_nothing_raised {
|
175
|
+
config.write( TestConfigFilename )
|
176
|
+
}
|
177
|
+
|
178
|
+
otherConfig = Arrow::Config.load( TestConfigFilename )
|
179
|
+
|
180
|
+
assert_config_equal config.struct, otherConfig.struct
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
### Changed predicate knows something has changed after regular set
|
185
|
+
def test_50_changed_after_set
|
186
|
+
printTestHeader "Arrow::Config: #changed? after .member="
|
187
|
+
rval = nil
|
188
|
+
config = Arrow::Config.new( TestConfig )
|
189
|
+
|
190
|
+
# Make sure the brand-new config struct knows it's unchanged
|
191
|
+
assert_nothing_raised do
|
192
|
+
rval = config.changed?
|
193
|
+
end
|
194
|
+
assert_equal false, rval
|
195
|
+
|
196
|
+
# Change something via the regular accessors
|
197
|
+
config.templates.cache = false
|
198
|
+
|
199
|
+
# Make sure it knows something changed
|
200
|
+
assert_nothing_raised do
|
201
|
+
rval = config.changed?
|
202
|
+
end
|
203
|
+
assert_equal true, rval
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
### "Changed" predicate knows something has changed after merge-in-place
|
208
|
+
def test_55_changed_after_merge
|
209
|
+
printTestHeader "Arrow::Config: #changed? after #merge!"
|
210
|
+
rval = nil
|
211
|
+
config = Arrow::Config.new( TestConfig )
|
212
|
+
config2 = Arrow::Config.new()
|
213
|
+
|
214
|
+
# Now merge the defaults back into the test config
|
215
|
+
config.merge!( config2 )
|
216
|
+
|
217
|
+
# Make sure it knows something changed
|
218
|
+
assert_nothing_raised do
|
219
|
+
rval = config.changed?
|
220
|
+
end
|
221
|
+
assert_equal true, rval
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
require 'pathname'
|
5
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
|
+
|
7
|
+
libdir = basedir + "lib"
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
10
|
+
}
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'digest/md5'
|
14
|
+
require 'spec'
|
15
|
+
require 'apache/fakerequest'
|
16
|
+
require 'arrow'
|
17
|
+
require 'arrow/cookieset'
|
18
|
+
rescue LoadError
|
19
|
+
unless Object.const_defined?( :Gem )
|
20
|
+
require 'rubygems'
|
21
|
+
retry
|
22
|
+
end
|
23
|
+
raise
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
#####################################################################
|
28
|
+
### C O N T E X T S
|
29
|
+
#####################################################################
|
30
|
+
|
31
|
+
describe Arrow::CookieSet do
|
32
|
+
before(:each) do
|
33
|
+
@cookieset = Arrow::CookieSet.new
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
it "is able to enummerate over each cookie in the set" do
|
38
|
+
pants_cookie = Arrow::Cookie.new( 'pants', 'baggy' )
|
39
|
+
shirt_cookie = Arrow::Cookie.new( 'shirt', 'pirate' )
|
40
|
+
@cookieset << shirt_cookie << pants_cookie
|
41
|
+
|
42
|
+
cookies = []
|
43
|
+
@cookieset.each do |cookie|
|
44
|
+
cookies << cookie
|
45
|
+
end
|
46
|
+
|
47
|
+
cookies.length.should == 2
|
48
|
+
cookies.should include( pants_cookie )
|
49
|
+
cookies.should include( shirt_cookie )
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is able to add a cookie referenced symbolically" do
|
53
|
+
pants_cookie = Arrow::Cookie.new( 'pants', 'denim' )
|
54
|
+
@cookieset[:pants] = pants_cookie
|
55
|
+
@cookieset['pants'].should == pants_cookie
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
it "autos-create a cookie for a non-cookie passed to the index setter" do
|
60
|
+
lambda { @cookieset['bar'] = 'badgerbadgerbadgerbadger' }.should_not raise_error()
|
61
|
+
|
62
|
+
@cookieset['bar'].should be_an_instance_of( Arrow::Cookie )
|
63
|
+
@cookieset['bar'].value.should == 'badgerbadgerbadgerbadger'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an exception if the name of a cookie being set doesn't agree with the key it being set with" do
|
67
|
+
pants_cookie = Arrow::Cookie.new( 'pants', 'corduroy' )
|
68
|
+
lambda { @cookieset['shirt'] = pants_cookie }.should raise_error( ArgumentError )
|
69
|
+
end
|
70
|
+
|
71
|
+
it "implements Enumerable" do
|
72
|
+
Enumerable.instance_methods( false ).each do |meth|
|
73
|
+
@cookieset.should respond_to( meth )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is able to set a cookie's value symbolically to something other than a String" do
|
78
|
+
@cookieset[:wof] = Digest::MD5.hexdigest( Time.now.to_s )
|
79
|
+
end
|
80
|
+
|
81
|
+
it "is able to set a cookie with a Symbol key" do
|
82
|
+
@cookieset[:wof] = Arrow::Cookie.new( :wof, "something" )
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Arrow::CookieSet, " created with an Array of cookies" do
|
88
|
+
it "should flatten the array" do
|
89
|
+
cookie_array = []
|
90
|
+
cookie_array << Arrow::Cookie.new( 'foo', 'bar' )
|
91
|
+
cookie_array << [Arrow::Cookie.new( 'shmoop', 'torgo!' )]
|
92
|
+
|
93
|
+
cookieset = nil
|
94
|
+
lambda {cookieset = Arrow::CookieSet.new(cookie_array)}.should_not raise_error()
|
95
|
+
cookieset.length.should == 2
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe Arrow::CookieSet, " with a 'foo' cookie" do
|
100
|
+
before(:each) do
|
101
|
+
@cookie = Arrow::Cookie.new( 'foo', 'bar' )
|
102
|
+
@cookieset = Arrow::CookieSet.new( @cookie )
|
103
|
+
end
|
104
|
+
|
105
|
+
it "contains only one cookie" do
|
106
|
+
@cookieset.length.should == 1
|
107
|
+
end
|
108
|
+
|
109
|
+
it "is able to return the 'foo' Arrow::Cookie via its index operator" do
|
110
|
+
@cookieset[ 'foo' ].should == @cookie
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
it "is able to return the 'foo' Arrow::Cookie via its symbolic name" do
|
115
|
+
@cookieset[ :foo ].should == @cookie
|
116
|
+
end
|
117
|
+
|
118
|
+
it "knows if it includes a cookie named 'foo'" do
|
119
|
+
@cookieset.should include( 'foo' )
|
120
|
+
end
|
121
|
+
|
122
|
+
it "knows if it includes a cookie referenced by :foo" do
|
123
|
+
@cookieset.should include( :foo )
|
124
|
+
end
|
125
|
+
|
126
|
+
it "knows that it doesn't contain a cookie named 'lollypop'" do
|
127
|
+
@cookieset.should_not include( 'lollypop' )
|
128
|
+
end
|
129
|
+
|
130
|
+
it "knows that it includes the 'foo' cookie object" do
|
131
|
+
@cookieset.should include( @cookie )
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
it "adds a cookie to the set if it has a different name" do
|
136
|
+
new_cookie = Arrow::Cookie.new( 'bar', 'foo' )
|
137
|
+
@cookieset << new_cookie
|
138
|
+
|
139
|
+
@cookieset.length.should == 2
|
140
|
+
@cookieset.should include( new_cookie )
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
it "replaces any existing same-named cookie added via appending" do
|
145
|
+
new_cookie = Arrow::Cookie.new( 'foo', 'giant scallops of doom' )
|
146
|
+
@cookieset << new_cookie
|
147
|
+
|
148
|
+
@cookieset.length.should == 1
|
149
|
+
@cookieset.should include( new_cookie )
|
150
|
+
@cookieset['foo'].should equal( new_cookie )
|
151
|
+
end
|
152
|
+
|
153
|
+
it "replaces any existing same-named cookie set via the index operator" do
|
154
|
+
new_cookie = Arrow::Cookie.new( 'foo', 'giant scallops of doom' )
|
155
|
+
@cookieset[:foo] = new_cookie
|
156
|
+
|
157
|
+
@cookieset.length.should == 1
|
158
|
+
@cookieset.should include( new_cookie )
|
159
|
+
@cookieset['foo'].should equal( new_cookie )
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
# vim: set nosta noet ts=4 sw=4:
|