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,121 @@
|
|
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
|
+
require 'rubygems'
|
13
|
+
require 'spec'
|
14
|
+
require 'apache/fakerequest'
|
15
|
+
require 'arrow'
|
16
|
+
require 'arrow/session'
|
17
|
+
|
18
|
+
require 'spec/lib/helpers'
|
19
|
+
require 'spec/lib/constants'
|
20
|
+
|
21
|
+
|
22
|
+
include Arrow::TestConstants
|
23
|
+
|
24
|
+
|
25
|
+
#####################################################################
|
26
|
+
### C O N T E X T S
|
27
|
+
#####################################################################
|
28
|
+
|
29
|
+
describe Arrow::Session do
|
30
|
+
include Arrow::SpecHelpers
|
31
|
+
|
32
|
+
### Configuration
|
33
|
+
SESSION_DIR = File.dirname( File.expand_path(__FILE__) ) + "/sessions"
|
34
|
+
|
35
|
+
TEST_ID_URI = "md5:."
|
36
|
+
TEST_ID_NAME = "test_id"
|
37
|
+
TEST_ID_TYPE = 'Arrow::Session::MD5Id'
|
38
|
+
TEST_LOCK_URI = "file:#{SESSION_DIR}"
|
39
|
+
TEST_LOCK_TYPE = 'Arrow::Session::FileLock'
|
40
|
+
TEST_STORE_URI = "file:#{SESSION_DIR}"
|
41
|
+
TEST_STORE_TYPE = 'Arrow::Session::YamlStore'
|
42
|
+
|
43
|
+
TEST_SESSION_ID = "6bfb3f041cf9204c3a2ea4611bd5c9d1"
|
44
|
+
|
45
|
+
TEST_SESSION_CONFIG_HASH = TEST_CONFIG_HASH.merge( :session => {
|
46
|
+
:idType => TEST_ID_URI,
|
47
|
+
:idName => TEST_ID_NAME,
|
48
|
+
:lockType => TEST_LOCK_URI,
|
49
|
+
:storeType => TEST_STORE_URI,
|
50
|
+
})
|
51
|
+
|
52
|
+
|
53
|
+
before( :all ) do
|
54
|
+
setup_logging( :crit )
|
55
|
+
@config = Arrow::Config.new( TEST_SESSION_CONFIG_HASH )
|
56
|
+
end
|
57
|
+
|
58
|
+
after( :all ) do
|
59
|
+
reset_logging()
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
it "uses the id contained in the configured session cookie if present when creating the id" do
|
64
|
+
txn = mock( "transaction" )
|
65
|
+
request = stub( "request object" )
|
66
|
+
txn.stub!( :request ).and_return( request )
|
67
|
+
session_cookie = mock( "session cookie" )
|
68
|
+
cookieset = mock( "arrow cookieset" )
|
69
|
+
|
70
|
+
txn.should_receive( :request_cookies ).at_least( :once ).and_return( cookieset )
|
71
|
+
cookieset.should_receive( :include? ).with( TEST_ID_NAME ).and_return( true )
|
72
|
+
cookieset.should_receive( :[] ).with( TEST_ID_NAME ).and_return( session_cookie )
|
73
|
+
session_cookie.should_receive( :value ).and_return( TEST_SESSION_ID )
|
74
|
+
|
75
|
+
@config.session.idName.should == TEST_ID_NAME
|
76
|
+
Arrow::Session.create_id( @config.session, txn )
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
it "knows what the session cookie name is after being configured" do
|
81
|
+
Arrow::Session.configure( @config.session )
|
82
|
+
Arrow::Session.session_cookie_name.should == TEST_ID_NAME
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
describe "instance" do
|
87
|
+
|
88
|
+
before( :all ) do
|
89
|
+
Arrow::Session.configure( @config.session )
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
before( :each ) do
|
94
|
+
@cookieset = Arrow::CookieSet.new
|
95
|
+
@config = Arrow::Config.new
|
96
|
+
@config.session.idName = TEST_ID_NAME
|
97
|
+
@txn = mock( "transaction" )
|
98
|
+
@store = mock( "session store" )
|
99
|
+
@lock = mock( "session lock" )
|
100
|
+
|
101
|
+
Arrow::Session.configure( @config.session )
|
102
|
+
|
103
|
+
@store.stub!( :[]= )
|
104
|
+
@session = Arrow::Session.new( :id, @lock, @store, @txn )
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
it "adds the session cookie to the request when it is saved" do
|
109
|
+
@lock.stub!( :release_all_locks )
|
110
|
+
@txn.should_receive( :cookies ).and_return( @cookieset )
|
111
|
+
|
112
|
+
@store.should_receive( :save )
|
113
|
+
@session.save
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# vim: set nosta noet ts=4 sw=4:
|
@@ -0,0 +1,222 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
require 'pathname'
|
5
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
6
|
+
|
7
|
+
libdir = basedir + "lib"
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
10
|
+
}
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'spec'
|
14
|
+
|
15
|
+
require 'apache/fakerequest'
|
16
|
+
require 'arrow'
|
17
|
+
require 'arrow/template/iterator'
|
18
|
+
|
19
|
+
require 'spec/lib/helpers'
|
20
|
+
require 'spec/lib/constants'
|
21
|
+
|
22
|
+
|
23
|
+
include Arrow::TestConstants
|
24
|
+
|
25
|
+
|
26
|
+
#####################################################################
|
27
|
+
### C O N T E X T S
|
28
|
+
#####################################################################
|
29
|
+
|
30
|
+
describe Arrow::Template::Iterator do
|
31
|
+
include Arrow::SpecHelpers
|
32
|
+
|
33
|
+
TEST_ITERATOR_ITEMS = [
|
34
|
+
"Achomawi",
|
35
|
+
"Chemakum",
|
36
|
+
"Chukchansi",
|
37
|
+
"Clayoquot",
|
38
|
+
"Coast Salish",
|
39
|
+
"Cowichan",
|
40
|
+
"Haida",
|
41
|
+
"Hupa",
|
42
|
+
"Hesquiat",
|
43
|
+
"Karok",
|
44
|
+
"Klamath",
|
45
|
+
"Koskimo",
|
46
|
+
"Kwakiutl",
|
47
|
+
"Lummi",
|
48
|
+
"Makah",
|
49
|
+
"Nootka",
|
50
|
+
"Puget Sound Salish",
|
51
|
+
"Quileute",
|
52
|
+
"Quinault",
|
53
|
+
"Shasta",
|
54
|
+
"Skokomish",
|
55
|
+
"Tolowa",
|
56
|
+
"Tututni",
|
57
|
+
"Willapa",
|
58
|
+
"Wiyot",
|
59
|
+
"Yurok",
|
60
|
+
]
|
61
|
+
|
62
|
+
|
63
|
+
it "can be constructed with unsplatted arrays" do
|
64
|
+
Arrow::Template::Iterator.new( @items ).items.should == @items
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
it "can be constructed with a splatted list" do
|
69
|
+
Arrow::Template::Iterator.new( :fii, :baq, :bax ).items.should == [:fii, :baq, :bax]
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
before( :each ) do
|
74
|
+
@items = TEST_ITERATOR_ITEMS.dup
|
75
|
+
@iter = Arrow::Template::Iterator.new( @items )
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
it "is enumerable" do
|
80
|
+
@iter.map {|iter, item| item }.should == @items
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
it "knows which is the first iteration" do
|
85
|
+
@iter.find {|iter, item| iter.first? }.last.should == @items.first
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
it "knows which is the last iteration" do
|
90
|
+
@iter.find {|iter, item| iter.last? }.last.should == @items.last
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
it "knows how to break out of the iteration" do
|
95
|
+
stuff = []
|
96
|
+
|
97
|
+
@iter.each do |iter, item|
|
98
|
+
break if iter.iteration >= @items.length / 2
|
99
|
+
stuff << item
|
100
|
+
end
|
101
|
+
|
102
|
+
stuff.should == @items[ 0, @items.length / 2 ]
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
it "knows how to skip iterations" do
|
107
|
+
stuff = []
|
108
|
+
|
109
|
+
@iter.each do |iter, item|
|
110
|
+
stuff << item
|
111
|
+
iter.skip
|
112
|
+
end
|
113
|
+
|
114
|
+
expected = []
|
115
|
+
@items.each_with_index do |item, i|
|
116
|
+
expected << item if ( i % 2 ).zero?
|
117
|
+
end
|
118
|
+
|
119
|
+
stuff.should == expected
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
it "knows how to skip backwards" do
|
124
|
+
stuff = []
|
125
|
+
|
126
|
+
@iter.each do |iter, item|
|
127
|
+
stuff << item
|
128
|
+
iter.skip( -2 ) if iter.last? && stuff.length == @items.length
|
129
|
+
end
|
130
|
+
|
131
|
+
expected = @items + @items[-2,2]
|
132
|
+
|
133
|
+
stuff.should == expected
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
it "knows if the previous iteration skipped one or more items" do
|
138
|
+
stuff = []
|
139
|
+
|
140
|
+
@iter.each do |iter, item|
|
141
|
+
if iter.first?
|
142
|
+
iter.skip
|
143
|
+
elsif iter.skipped?
|
144
|
+
stuff << :skipped
|
145
|
+
end
|
146
|
+
stuff << item
|
147
|
+
end
|
148
|
+
|
149
|
+
expected = @items.dup
|
150
|
+
expected[0,2] = [:skipped]
|
151
|
+
|
152
|
+
stuff.should == expected
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
it "knows how to redo an iterations" do
|
157
|
+
stuff = []
|
158
|
+
|
159
|
+
@iter.each do |iter, item|
|
160
|
+
stuff << item
|
161
|
+
iter.redo if stuff.length == 1
|
162
|
+
end
|
163
|
+
|
164
|
+
stuff.should == [ @items.first ] + @items
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
it "can restart the iteration" do
|
169
|
+
stuff = []
|
170
|
+
@iter.each do |iter, item|
|
171
|
+
stuff << item
|
172
|
+
iter.restart if iter.last? && stuff.length <= @items.length
|
173
|
+
end
|
174
|
+
|
175
|
+
stuff.should == @items + @items
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
it "knows if its iteration is even" do
|
180
|
+
stuff = []
|
181
|
+
@iter.each do |iter, item|
|
182
|
+
if iter.even?
|
183
|
+
stuff << item
|
184
|
+
else
|
185
|
+
stuff << :odd
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
expected = @items.inject([]) {|a,i| a << ((a.length % 2).nonzero? ? :odd : i); a }
|
190
|
+
stuff.should == expected
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
it "knows if its iteration is odd" do
|
195
|
+
stuff = []
|
196
|
+
@iter.each do |iter, item|
|
197
|
+
if iter.odd?
|
198
|
+
stuff << item
|
199
|
+
else
|
200
|
+
stuff << :even
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
expected = @items.inject([]) {|a,i| a << ((a.length % 2).zero? ? :even : i); a }
|
205
|
+
stuff.should == expected
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
it "can produce 'even' or 'odd' depending on whether the iteration is even or odd" do
|
210
|
+
stuff = []
|
211
|
+
@iter.each do |iter, item|
|
212
|
+
stuff << iter.even_or_odd
|
213
|
+
end
|
214
|
+
|
215
|
+
expected = @items.inject([]) {|a,i| a << ((a.length % 2).zero? ? 'even' : 'odd'); a }
|
216
|
+
stuff.should == expected
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
# vim: set nosta noet ts=4 sw=4:
|
@@ -0,0 +1,185 @@
|
|
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 'arrow/templatefactory'
|
17
|
+
|
18
|
+
require 'spec/lib/helpers'
|
19
|
+
require 'spec/lib/constants'
|
20
|
+
rescue LoadError
|
21
|
+
unless Object.const_defined?( :Gem )
|
22
|
+
require 'rubygems'
|
23
|
+
retry
|
24
|
+
end
|
25
|
+
raise
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
### A testing loader class
|
30
|
+
class Arrow::TestingClassTemplateLoader
|
31
|
+
def self::load( *args )
|
32
|
+
# Mocked
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
### A testing loader object
|
37
|
+
class Arrow::TestingInstanceTemplateLoader
|
38
|
+
def initialize( config )
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
undef_method :load
|
43
|
+
end
|
44
|
+
|
45
|
+
def load( *args )
|
46
|
+
# Mocked
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
#####################################################################
|
52
|
+
### C O N T E X T S
|
53
|
+
#####################################################################
|
54
|
+
|
55
|
+
describe Arrow::TemplateFactory do
|
56
|
+
include Arrow::SpecHelpers
|
57
|
+
|
58
|
+
before( :each ) do
|
59
|
+
setup_logging( :crit )
|
60
|
+
end
|
61
|
+
|
62
|
+
after( :each ) do
|
63
|
+
reset_logging()
|
64
|
+
end
|
65
|
+
|
66
|
+
describe " configured with a loader class" do
|
67
|
+
before( :each ) do
|
68
|
+
tmplconfig = mock( "templates config", :null_object => true )
|
69
|
+
tmplconfig.stub!( :cache ).and_return( false )
|
70
|
+
tmplconfig.stub!( :loader ).
|
71
|
+
and_return( 'Arrow::TestingClassTemplateLoader' )
|
72
|
+
|
73
|
+
config = stub( "config", :templates => tmplconfig )
|
74
|
+
|
75
|
+
@factory = Arrow::TemplateFactory.new( config )
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
it "has the loader class object registered as its loader" do
|
80
|
+
@factory.loader.should == Arrow::TestingClassTemplateLoader
|
81
|
+
end
|
82
|
+
|
83
|
+
it "calls the loader's #load method to load templates" do
|
84
|
+
loader = mock( "loader", :null_object => true )
|
85
|
+
@factory.loader = loader
|
86
|
+
@factory.path = :path
|
87
|
+
|
88
|
+
loader.should_receive( :load ).with( 'templatename', :path ).
|
89
|
+
and_return( :template_object )
|
90
|
+
|
91
|
+
@factory.load_from_file( 'templatename' ).should == :template_object
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe " configured with a loader object" do
|
96
|
+
before( :each ) do
|
97
|
+
tmplconfig = mock( "templates config", :null_object => true )
|
98
|
+
tmplconfig.stub!( :cache ).and_return( false )
|
99
|
+
tmplconfig.stub!( :loader ).
|
100
|
+
and_return( 'Arrow::TestingInstanceTemplateLoader' )
|
101
|
+
|
102
|
+
config = stub( "config", :templates => tmplconfig )
|
103
|
+
|
104
|
+
@factory = Arrow::TemplateFactory.new( config )
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
it "has the loader instance registered as its loader" do
|
109
|
+
@factory.loader.should be_an_instance_of( Arrow::TestingInstanceTemplateLoader )
|
110
|
+
end
|
111
|
+
|
112
|
+
it "calls the loader's #load method to load templates" do
|
113
|
+
loader = mock( "loader", :null_object => true )
|
114
|
+
@factory.loader = loader
|
115
|
+
@factory.path = :path
|
116
|
+
|
117
|
+
loader.should_receive( :load ).with( 'templatename', :path ).
|
118
|
+
and_return( :template_object )
|
119
|
+
|
120
|
+
@factory.load_from_file( 'templatename' ).should == :template_object
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
describe " configured to use caching" do
|
126
|
+
before( :each ) do
|
127
|
+
tmplconfig = mock( "templates config", :null_object => true )
|
128
|
+
tmplconfig.stub!( :loader ).
|
129
|
+
and_return( 'Arrow::TestingInstanceTemplateLoader' )
|
130
|
+
tmplconfig.stub!( :cache ).and_return( true )
|
131
|
+
tmplconfig.stub!( :cacheConfig ).and_return( {} )
|
132
|
+
|
133
|
+
config = stub( "config", :templates => tmplconfig )
|
134
|
+
|
135
|
+
@factory = Arrow::TemplateFactory.new( config )
|
136
|
+
@mock_cache = mock( "cache", :null_object => true )
|
137
|
+
@factory.cache = @mock_cache
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
it "fetches templates through the cache" do
|
142
|
+
template = stub( "template", :changed? => false, :dup => :template_copy )
|
143
|
+
@mock_cache.should_receive( :fetch ).with( :templatename ).
|
144
|
+
and_return( template )
|
145
|
+
|
146
|
+
@factory.get_template( :templatename ).should == :template_copy
|
147
|
+
end
|
148
|
+
|
149
|
+
it "invalidates cached templates that have changed since loading" do
|
150
|
+
template = stub( "template", :changed? => true, :dup => :template_copy )
|
151
|
+
@mock_cache.should_receive( :fetch ).twice.with( :templatename ).
|
152
|
+
and_return( template )
|
153
|
+
@mock_cache.should_receive( :invalidate ).with( :templatename )
|
154
|
+
|
155
|
+
@factory.get_template( :templatename ).should == :template_copy
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
describe " configured to not use caching" do
|
162
|
+
before( :each ) do
|
163
|
+
tmplconfig = mock( "templates config", :null_object => true )
|
164
|
+
tmplconfig.stub!( :loader ).
|
165
|
+
and_return( 'Arrow::TestingInstanceTemplateLoader' )
|
166
|
+
tmplconfig.stub!( :cache ).and_return( false )
|
167
|
+
tmplconfig.stub!( :path ).and_return( :path )
|
168
|
+
|
169
|
+
config = stub( "config", :templates => tmplconfig )
|
170
|
+
|
171
|
+
@factory = Arrow::TemplateFactory.new( config )
|
172
|
+
@mock_loader = mock( "template loader" )
|
173
|
+
@factory.loader = @mock_loader
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should not fetch templates through the cache" do
|
177
|
+
@mock_loader.should_receive( :load ).
|
178
|
+
with( :template_name, :path ).
|
179
|
+
and_return( :template )
|
180
|
+
@factory.get_template( :template_name ).should == :template
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# vim: set nosta noet ts=4 sw=4:
|