gambit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +2 -0
- data/CHANGELOG +7 -0
- data/COPYING +340 -0
- data/INSTALL +23 -0
- data/LICENSE +7 -0
- data/README +25 -0
- data/Rakefile +87 -0
- data/TODO +6 -0
- data/examples/bird_wars/game.rb +434 -0
- data/examples/bird_wars/html/chest.rhtml +37 -0
- data/examples/bird_wars/html/combat.rhtml +38 -0
- data/examples/bird_wars/html/fight.rhtml +71 -0
- data/examples/bird_wars/html/fridge.rhtml +31 -0
- data/examples/bird_wars/html/help.rhtml +30 -0
- data/examples/bird_wars/html/house.rhtml +36 -0
- data/examples/bird_wars/html/images/albatross.jpg +0 -0
- data/examples/bird_wars/html/images/alka_seltzer_small.png +0 -0
- data/examples/bird_wars/html/images/bazooka_small.png +0 -0
- data/examples/bird_wars/html/images/bb_gun_small.png +0 -0
- data/examples/bird_wars/html/images/cat_small.png +0 -0
- data/examples/bird_wars/html/images/combat.png +0 -0
- data/examples/bird_wars/html/images/crossbow_small.png +0 -0
- data/examples/bird_wars/html/images/cuckoo.jpg +0 -0
- data/examples/bird_wars/html/images/fridge.png +0 -0
- data/examples/bird_wars/html/images/gull.jpg +0 -0
- data/examples/bird_wars/html/images/house.jpg +0 -0
- data/examples/bird_wars/html/images/items.png +0 -0
- data/examples/bird_wars/html/images/not_found.png +0 -0
- data/examples/bird_wars/html/images/note.jpg +0 -0
- data/examples/bird_wars/html/images/oil_small.png +0 -0
- data/examples/bird_wars/html/images/one_stone_small.png +0 -0
- data/examples/bird_wars/html/images/owl.jpg +0 -0
- data/examples/bird_wars/html/images/poisoned_seeds_small.png +0 -0
- data/examples/bird_wars/html/images/rice_small.png +0 -0
- data/examples/bird_wars/html/images/shotgun_small.png +0 -0
- data/examples/bird_wars/html/images/slingshot_small.png +0 -0
- data/examples/bird_wars/html/images/soda_rings_small.png +0 -0
- data/examples/bird_wars/html/images/spear_small.png +0 -0
- data/examples/bird_wars/html/images/stork.jpg +0 -0
- data/examples/bird_wars/html/images/weapons.png +0 -0
- data/examples/bird_wars/html/images/woodpecker.jpg +0 -0
- data/examples/bird_wars/html/images/you.jpg +0 -0
- data/examples/bird_wars/html/index.rhtml +13 -0
- data/examples/bird_wars/html/weapons.rhtml +35 -0
- data/examples/cli/blackjack.rb +86 -0
- data/examples/cli/go.rb +93 -0
- data/examples/cli/space_trader2/planet_data +12280 -0
- data/examples/cli/space_trader2/space_trader2.rb +248 -0
- data/examples/cli/space_trader2/world.rb +127 -0
- data/examples/cli/spacetrader.rb +262 -0
- data/examples/cli/yahtzee.rb +161 -0
- data/examples/galactic_courier/Rakefile +9 -0
- data/examples/galactic_courier/bin/galactic_courier.rb +44 -0
- data/examples/galactic_courier/html/console.rhtml +15 -0
- data/examples/galactic_courier/html/images/barren.jpg +0 -0
- data/examples/galactic_courier/html/images/industrial.jpg +0 -0
- data/examples/galactic_courier/html/images/jungle.jpg +0 -0
- data/examples/galactic_courier/html/images/oceanic.jpg +0 -0
- data/examples/galactic_courier/html/images/tundra.jpg +0 -0
- data/examples/galactic_courier/html/images/volcanic.jpg +0 -0
- data/examples/galactic_courier/lib/galaxy.rb +64 -0
- data/examples/galactic_courier/lib/planet.rb +30 -0
- data/examples/galactic_courier/lib/sector.rb +84 -0
- data/examples/galactic_courier/lib/station.rb +18 -0
- data/examples/galactic_courier/test/tc_galaxy.rb +24 -0
- data/examples/galactic_courier/test/tc_planet.rb +22 -0
- data/examples/galactic_courier/test/tc_sector.rb +55 -0
- data/examples/galactic_courier/test/ts_all.rb +12 -0
- data/examples/gambit_mail/html/compose.rhtml +39 -0
- data/examples/gambit_mail/html/index.rhtml +3 -0
- data/examples/gambit_mail/html/mailbox.rhtml +47 -0
- data/examples/gambit_mail/html/message.rhtml +34 -0
- data/examples/gambit_mail/mail.rb +75 -0
- data/lib/gambit.rb +10 -0
- data/lib/gambit/server.rb +269 -0
- data/lib/gambit/server/gambiterror.rb +28 -0
- data/lib/gambit/server/game.rb +185 -0
- data/lib/gambit/server/game/eventform.rb +174 -0
- data/lib/gambit/server/message.rb +85 -0
- data/lib/gambit/server/player.rb +40 -0
- data/lib/gambit/tools.rb +13 -0
- data/lib/gambit/tools/board.rb +275 -0
- data/lib/gambit/tools/cards.rb +11 -0
- data/lib/gambit/tools/cards/card.rb +158 -0
- data/lib/gambit/tools/cards/deck.rb +99 -0
- data/lib/gambit/tools/cards/hand.rb +86 -0
- data/lib/gambit/tools/cards/pile.rb +107 -0
- data/lib/gambit/tools/currency.rb +148 -0
- data/lib/gambit/tools/dice.rb +219 -0
- data/lib/gambit/tools/movehistory.rb +164 -0
- data/lib/gambit/tools/scorecard.rb +333 -0
- data/lib/gambit/viewable.rb +71 -0
- data/setup.rb +1360 -0
- data/test/tc_board.rb +167 -0
- data/test/tc_cards.rb +182 -0
- data/test/tc_currency.rb +99 -0
- data/test/tc_dice.rb +83 -0
- data/test/tc_error.rb +34 -0
- data/test/tc_event.rb +367 -0
- data/test/tc_game.rb +29 -0
- data/test/tc_message.rb +35 -0
- data/test/tc_movehistory.rb +38 -0
- data/test/tc_player.rb +60 -0
- data/test/tc_scorecard.rb +112 -0
- data/test/tc_views.rb +353 -0
- data/test/test_game.rb +19 -0
- data/test/test_view.rhtml +2 -0
- data/test/ts_all.rb +12 -0
- data/test/ts_server.rb +14 -0
- data/test/ts_tools.rb +14 -0
- metadata +183 -0
data/test/tc_error.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_error.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-06-03.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "gambit/server/gambiterror"
|
11
|
+
|
12
|
+
class TestError < Test::Unit::TestCase
|
13
|
+
def test_viewable
|
14
|
+
assert_not_nil( error =
|
15
|
+
Gambit::Server::GambitError.new("You broke that!") )
|
16
|
+
assert_equal( "<!DOCTYPE html PUBLIC " +
|
17
|
+
"\"-//W3C//DTD XHTML 1.0 Strict//EN\"\n " +
|
18
|
+
"\"http://www.w3.org/TR/xhtml1/DTD/" +
|
19
|
+
"xhtml1-strict.dtd\">\n" +
|
20
|
+
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
|
21
|
+
"<head>\n" +
|
22
|
+
"\t<title>GambitError</title>\n" +
|
23
|
+
"</head><body>\n" +
|
24
|
+
"\t<h1>Gambit Has Thrown An Error</h1>\n" +
|
25
|
+
"\t<p>You broke that!</p>\n" +
|
26
|
+
"</body></html>\n", error.view(:error_page) )
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_throw
|
30
|
+
assert_raise(Gambit::Server::GambitError) do
|
31
|
+
raise Gambit::Server::GambitError, "Not good!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/tc_event.rb
ADDED
@@ -0,0 +1,367 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_event.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-06-03.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "test_game"
|
11
|
+
|
12
|
+
class TestEvent < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@game = MyGame.new
|
15
|
+
@id = @game.object_id
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_url
|
19
|
+
assert_equal("/event/#{@id}/kill_bird", @game.event(nil, "kill_bird"))
|
20
|
+
|
21
|
+
params = Hash.new
|
22
|
+
params["weapon"] = "slingshot"
|
23
|
+
params["item"] = "rice"
|
24
|
+
assert_equal( "/event/#{@id}/equip?item=rice&weapon=slingshot",
|
25
|
+
@game.event(nil, "equip", params) )
|
26
|
+
assert_equal( "/event/#{@id}/equip?item=rice&weapon=slingshot",
|
27
|
+
@game.event( nil, "equip", { "weapon" => "slingshot",
|
28
|
+
"item" => "rice" } ) )
|
29
|
+
assert_equal( "/event/#{@id}/equip?item=rice&weapon=slingshot",
|
30
|
+
@game.event( nil, "equip", "weapon" => "slingshot",
|
31
|
+
"item" => "rice" ) )
|
32
|
+
|
33
|
+
assert_equal( "/event/#{@id}/set_name?" +
|
34
|
+
"name=James%20Edward%20Gray%20II",
|
35
|
+
@game.event( nil, "set_name",
|
36
|
+
"name" => "James Edward Gray II" ) )
|
37
|
+
assert_equal( "/event/#{@id}/talk?" +
|
38
|
+
"say=What%20the%20%3F%23%40%25%21%20man%3F",
|
39
|
+
@game.event( nil, "talk",
|
40
|
+
"say" => "What the ?\#@%! man?" ) )
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_links
|
44
|
+
assert_equal( "<a class=\"event\" href=\"/event/#{@id}/travel?" +
|
45
|
+
"destinatiton=Gotham%20City\">" +
|
46
|
+
"Travel to Gotham City" +
|
47
|
+
"</a>",
|
48
|
+
@game.event( "Travel to Gotham City", "travel",
|
49
|
+
"destinatiton" => "Gotham City" ) )
|
50
|
+
assert_equal( "<a class=\"event\" href=\"/event/#{@id}/travel?" +
|
51
|
+
"destinatiton=Gotham%20City\">" +
|
52
|
+
"<img src=\"gotham.jpg\" />" +
|
53
|
+
"</a>",
|
54
|
+
@game.event( "<img src=\"gotham.jpg\" />", "travel",
|
55
|
+
"destinatiton" => "Gotham City" ) )
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_forms
|
59
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
60
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
61
|
+
"\t<p><input type=\"submit\" value=\"Submit\" />" +
|
62
|
+
" <input type=\"reset\" value=\"Reset\" /></p>\n" +
|
63
|
+
"</form>\n",
|
64
|
+
@game.event(nil, "send_mail") { true } )
|
65
|
+
|
66
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
67
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
68
|
+
"\t<p class=\"intro\">Enter message:</p>\n" +
|
69
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
70
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
71
|
+
"</form>\n",
|
72
|
+
@game.event("Enter message:", "send_mail") { true } )
|
73
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
74
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
75
|
+
"\t<p class=\"intro\">Welcome to Gambit Mail!</p>\n" +
|
76
|
+
"\t<p class=\"intro\">Enter message:</p>\n" +
|
77
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
78
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
79
|
+
"</form>\n",
|
80
|
+
@game.event( [ "Welcome to Gambit Mail!",
|
81
|
+
"Enter message:" ],
|
82
|
+
"send_mail" ) { true } )
|
83
|
+
|
84
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
85
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
86
|
+
"\t<p class=\"intro\">Enter message:</p>\n" +
|
87
|
+
"\t<input type=\"hidden\" name=\"from\" " +
|
88
|
+
"value=\"James Edward Gray II\" />\n" +
|
89
|
+
"\t<input type=\"hidden\" name=\"to\" " +
|
90
|
+
"value=\"Greg Brown\" />\n" +
|
91
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
92
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
93
|
+
"</form>\n",
|
94
|
+
@game.event( "Enter message:", "send_mail",
|
95
|
+
"from" => "James Edward Gray II",
|
96
|
+
"to" => "Greg Brown" ) { true } )
|
97
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
98
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
99
|
+
"\t<p class=\"intro\">Enter message:</p>\n" +
|
100
|
+
"\t<input type=\"hidden\" name=\"from\" " +
|
101
|
+
"value=\"James Edward Gray II\" />\n" +
|
102
|
+
"\t<input type=\"hidden\" name=\"to\" " +
|
103
|
+
"value=\"Greg Brown\" />\n" +
|
104
|
+
"\t<input type=\"hidden\" name=\"server\" " +
|
105
|
+
"value=\"smtp.somewhere.out.there\" />\n" +
|
106
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
107
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
108
|
+
"</form>\n",
|
109
|
+
@game.event( "Enter message:", "send_mail",
|
110
|
+
"from" => "James Edward Gray II",
|
111
|
+
"to" => "Greg Brown" ) do
|
112
|
+
hidden "server", "smtp.somewhere.out.there"
|
113
|
+
end )
|
114
|
+
|
115
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
116
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
117
|
+
"\t<p class=\"intro\">Enter message:</p>\n" +
|
118
|
+
"\t<dl>\n" +
|
119
|
+
"\t\t<dt><label for=\"subject\">" +
|
120
|
+
"Subject:</label></dt>\n" +
|
121
|
+
"\t\t<dd><input type=\"text\" " +
|
122
|
+
"id=\"subject\" name=\"subject\" " +
|
123
|
+
"maxlength=\"100\" /></dd>\n" +
|
124
|
+
"\t\t<dt><label for=\"message\">" +
|
125
|
+
"Message:</label></dt>\n" +
|
126
|
+
"\t\t<dd><input type=\"text\" " +
|
127
|
+
"id=\"message\" name=\"message\" />" +
|
128
|
+
"</dd>\n" +
|
129
|
+
"\t</dl>\n" +
|
130
|
+
"\t<input type=\"hidden\" name=\"from\" " +
|
131
|
+
"value=\"James Edward Gray II\" />\n" +
|
132
|
+
"\t<input type=\"hidden\" name=\"to\" " +
|
133
|
+
"value=\"Greg Brown\" />\n" +
|
134
|
+
"\t<input type=\"hidden\" name=\"server\" " +
|
135
|
+
"value=\"smtp.somewhere.out.there\" />\n" +
|
136
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
137
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
138
|
+
"</form>\n",
|
139
|
+
@game.event( "Enter message:", "send_mail",
|
140
|
+
"from" => "James Edward Gray II",
|
141
|
+
"to" => "Greg Brown" ) do
|
142
|
+
text "subject", "maxlength" => 100
|
143
|
+
text "message"
|
144
|
+
hidden "server", "smtp.somewhere.out.there"
|
145
|
+
end )
|
146
|
+
|
147
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
148
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
149
|
+
"\t<dl>\n" +
|
150
|
+
"\t\t<dt><label for=\"password\">" +
|
151
|
+
"Password:</label></dt>\n" +
|
152
|
+
"\t\t<dd><input type=\"password\" " +
|
153
|
+
"id=\"password\" name=\"password\" />" +
|
154
|
+
"</dd>\n" +
|
155
|
+
"\t</dl>\n" +
|
156
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
157
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
158
|
+
"</form>\n",
|
159
|
+
@game.event(nil, "send_mail") { password "password" } )
|
160
|
+
|
161
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
162
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
163
|
+
"\t<dl>\n" +
|
164
|
+
"\t\t<dt><label for=\"message\">" +
|
165
|
+
"Message:</label></dt>\n" +
|
166
|
+
"\t\t<dd><textarea id=\"message\" name=\"message\">" +
|
167
|
+
"</textarea></dd>\n" +
|
168
|
+
"\t</dl>\n" +
|
169
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
170
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
171
|
+
"</form>\n",
|
172
|
+
@game.event(nil, "send_mail") { document "message" } )
|
173
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
174
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
175
|
+
"\t<dl>\n" +
|
176
|
+
"\t\t<dt><label for=\"message\">" +
|
177
|
+
"Message:</label></dt>\n" +
|
178
|
+
"\t\t<dd><textarea id=\"message\" name=\"message\">" +
|
179
|
+
"This is the document text.</textarea></dd>\n" +
|
180
|
+
"\t</dl>\n" +
|
181
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
182
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
183
|
+
"</form>\n",
|
184
|
+
@game.event(nil, "send_mail") do
|
185
|
+
document "message", "This is the document text."
|
186
|
+
end )
|
187
|
+
|
188
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
189
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
190
|
+
"\t<p><label for=\"subject\">Subject:</label> " +
|
191
|
+
"<input type=\"text\" id=\"subject\" name=\"subject\" " +
|
192
|
+
"maxlength=\"100\" /></p>\n" +
|
193
|
+
"\t<img src=\"form_img.gif\" />\n" +
|
194
|
+
"\t<p><label for=\"message\">Message:</label> " +
|
195
|
+
"<input type=\"text\" " +
|
196
|
+
"id=\"message\" name=\"message\" /></p>\n" +
|
197
|
+
"\t<p>Priority: " +
|
198
|
+
"<input type=\"radio\" id=\"low\" name=\"priority\" " +
|
199
|
+
"value=\"low\" checked=\"checked\" />" +
|
200
|
+
"<label for=\"low\">Low</label> " +
|
201
|
+
"<input type=\"radio\" id=\"medium\" name=\"priority\" " +
|
202
|
+
"value=\"medium\" />" +
|
203
|
+
"<label for=\"medium\">Medium</label> " +
|
204
|
+
"<input type=\"radio\" id=\"important\" " +
|
205
|
+
"name=\"priority\" value=\"important\" />" +
|
206
|
+
"<label for=\"important\">Important</label></p>\n" +
|
207
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
208
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
209
|
+
"</form>\n",
|
210
|
+
@game.event(nil, "send_mail") do
|
211
|
+
text "subject", "maxlength" => 100
|
212
|
+
html "<img src=\"form_img.gif\" />"
|
213
|
+
text "message"
|
214
|
+
radios "priority", %w{low medium important},
|
215
|
+
"low" => { "checked" => "checked" }
|
216
|
+
end )
|
217
|
+
|
218
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
219
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
220
|
+
"\t<dl>\n" +
|
221
|
+
"\t\t<dt>Priority:</dt>\n" +
|
222
|
+
"\t\t<dd><input type=\"radio\" id=\"low\" " +
|
223
|
+
"name=\"priority\" value=\"low\" />" +
|
224
|
+
"<label for=\"low\">Low</label> " +
|
225
|
+
"<input type=\"radio\" id=\"medium\" " +
|
226
|
+
"name=\"priority\" value=\"medium\" />" +
|
227
|
+
"<label for=\"medium\">Medium</label> " +
|
228
|
+
"<input type=\"radio\" id=\"important\" " +
|
229
|
+
"name=\"priority\" value=\"important\" />" +
|
230
|
+
"<label for=\"important\">Important</label>" +
|
231
|
+
"</dd>\n" +
|
232
|
+
"\t</dl>\n" +
|
233
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
234
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
235
|
+
"</form>\n",
|
236
|
+
@game.event(nil, "send_mail") do
|
237
|
+
radios "priority", %w{low medium important}
|
238
|
+
end )
|
239
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
240
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
241
|
+
"\t<dl>\n" +
|
242
|
+
"\t\t<dt>Priority:</dt>\n" +
|
243
|
+
"\t\t<dd><input type=\"radio\" id=\"low\" " +
|
244
|
+
"name=\"priority\" value=\"low\" " +
|
245
|
+
"checked=\"checked\" />" +
|
246
|
+
"<label for=\"low\">Low</label> " +
|
247
|
+
"<input type=\"radio\" id=\"medium\" " +
|
248
|
+
"name=\"priority\" value=\"medium\" />" +
|
249
|
+
"<label for=\"medium\">Medium</label> " +
|
250
|
+
"<input type=\"radio\" id=\"important\" " +
|
251
|
+
"name=\"priority\" value=\"important\" />" +
|
252
|
+
"<label for=\"important\">Important</label>" +
|
253
|
+
"</dd>\n" +
|
254
|
+
"\t</dl>\n" +
|
255
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
256
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
257
|
+
"</form>\n",
|
258
|
+
@game.event(nil, "send_mail") do
|
259
|
+
radios "priority", %w{low medium important},
|
260
|
+
"low" => { "checked" => "checked" }
|
261
|
+
end )
|
262
|
+
|
263
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
264
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
265
|
+
"\t<dl>\n" +
|
266
|
+
"\t\t<dt>Options:</dt>\n" +
|
267
|
+
"\t\t<dd><input type=\"checkbox\" id=\"html\" " +
|
268
|
+
"name=\"options\" value=\"html\" />" +
|
269
|
+
"<label for=\"html\">Html</label> " +
|
270
|
+
"<input type=\"checkbox\" id=\"receipt\" " +
|
271
|
+
"name=\"options\" value=\"receipt\" />" +
|
272
|
+
"<label for=\"receipt\">Receipt</label>" +
|
273
|
+
"</dd>\n" +
|
274
|
+
"\t</dl>\n" +
|
275
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
276
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
277
|
+
"</form>\n",
|
278
|
+
@game.event(nil, "send_mail") do
|
279
|
+
checks "options", %w{html receipt}
|
280
|
+
end )
|
281
|
+
|
282
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
283
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
284
|
+
"\t<dl>\n" +
|
285
|
+
"\t\t<dt><label for=\"signature\">" +
|
286
|
+
"Signature:</label></dt>\n" +
|
287
|
+
"\t\t<dd><select id=\"signature\" name=\"signature\">" +
|
288
|
+
"<option value=\"default\">Default</option>" +
|
289
|
+
"<option value=\"short\">Short</option>" +
|
290
|
+
"</select></dd>\n" +
|
291
|
+
"\t</dl>\n" +
|
292
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
293
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
294
|
+
"</form>\n",
|
295
|
+
@game.event(nil, "send_mail") do
|
296
|
+
menu "signature", %w{default short}
|
297
|
+
end )
|
298
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
299
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
300
|
+
"\t<dl>\n" +
|
301
|
+
"\t\t<dt><label for=\"signature\">" +
|
302
|
+
"Signature:</label></dt>\n" +
|
303
|
+
"\t\t<dd><select id=\"signature\" name=\"signature\" " +
|
304
|
+
"size=\"5\">" +
|
305
|
+
"<option value=\"default\" " +
|
306
|
+
"selected=\"selected\">Default</option>" +
|
307
|
+
"<option value=\"short\">Short</option>" +
|
308
|
+
"</select></dd>\n" +
|
309
|
+
"\t</dl>\n" +
|
310
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
311
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
312
|
+
"</form>\n",
|
313
|
+
@game.event(nil, "send_mail") do
|
314
|
+
menu "signature", %w{default short},
|
315
|
+
{"default" => {"selected" => "selected"}},
|
316
|
+
"size" => 5
|
317
|
+
end )
|
318
|
+
|
319
|
+
Gambit::Server::Game::EventForm.register_view( :raw_elements,
|
320
|
+
<<-END_RAW.gsub(/^\t{2}/, "") )
|
321
|
+
% @elements.each do |element|
|
322
|
+
% if element =~ /^<(?:input|textarea|select)/
|
323
|
+
% name = element[/name="[^"]+"/][6..-2]
|
324
|
+
% if element =~ /^<input type="(?:checkbox|radio|)"/
|
325
|
+
<%= name.capitalize.tr("_", " ") %>: <%= element %>
|
326
|
+
% else
|
327
|
+
<label for="<%= name %>"><%=
|
328
|
+
name.capitalize.tr("_", " ") %>:</label> <%= element %>
|
329
|
+
% end
|
330
|
+
% else
|
331
|
+
<%= element %>
|
332
|
+
% end
|
333
|
+
% end
|
334
|
+
END_RAW
|
335
|
+
assert_equal( "<form class=\"event\" method=\"post\" " +
|
336
|
+
"action=\"/event/#{@id}/send_mail\">\n" +
|
337
|
+
"\t<label for=\"subject\">Subject:</label> " +
|
338
|
+
"<input type=\"text\" id=\"subject\" name=\"subject\" " +
|
339
|
+
"maxlength=\"100\" />\n" +
|
340
|
+
"\t<img src=\"form_img.gif\" />\n" +
|
341
|
+
"\t<label for=\"message\">Message:</label> " +
|
342
|
+
"<input type=\"text\" " +
|
343
|
+
"id=\"message\" name=\"message\" />\n" +
|
344
|
+
"\tPriority: " +
|
345
|
+
"<input type=\"radio\" id=\"low\" name=\"priority\" " +
|
346
|
+
"value=\"low\" checked=\"checked\" />" +
|
347
|
+
"<label for=\"low\">Low</label> " +
|
348
|
+
"<input type=\"radio\" id=\"medium\" name=\"priority\" " +
|
349
|
+
"value=\"medium\" />" +
|
350
|
+
"<label for=\"medium\">Medium</label> " +
|
351
|
+
"<input type=\"radio\" id=\"important\" " +
|
352
|
+
"name=\"priority\" value=\"important\" />" +
|
353
|
+
"<label for=\"important\">Important</label>\n" +
|
354
|
+
"\t<p><input type=\"submit\" value=\"Submit\" /> " +
|
355
|
+
"<input type=\"reset\" value=\"Reset\" /></p>\n" +
|
356
|
+
"</form>\n",
|
357
|
+
@game.event(nil, "send_mail") do
|
358
|
+
text "subject", "maxlength" => 100
|
359
|
+
html "<img src=\"form_img.gif\" />"
|
360
|
+
text "message"
|
361
|
+
radios "priority", %w{low medium important},
|
362
|
+
"low" => { "checked" => "checked" }
|
363
|
+
|
364
|
+
@element_style = :raw
|
365
|
+
end )
|
366
|
+
end
|
367
|
+
end
|
data/test/tc_game.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_game.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-06-03.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "gambit/server/gambiterror"
|
11
|
+
require "test_game"
|
12
|
+
|
13
|
+
class TestGame < Test::Unit::TestCase
|
14
|
+
def test_events
|
15
|
+
assert_not_nil(game = MyGame.new)
|
16
|
+
assert_equal( "Passed: {\"setting\"=>\"value\"}",
|
17
|
+
game.do_event(nil, "test", "setting" => "value") )
|
18
|
+
assert_raise(Gambit::Server::GambitError) { game.do_event(nil, "none") }
|
19
|
+
|
20
|
+
assert_equal("index.rhtml", game.do_login(nil))
|
21
|
+
|
22
|
+
assert_equal("index.rhtml", game.do_configure(nil))
|
23
|
+
assert_equal("Game number: #{game.object_id}.", game.name)
|
24
|
+
assert_equal( "index.rhtml",
|
25
|
+
game.do_configure( nil,
|
26
|
+
"game_name" => "James's Revenge!" ) )
|
27
|
+
assert_equal("James's Revenge!", game.name)
|
28
|
+
end
|
29
|
+
end
|
data/test/tc_message.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_message.rb
|
4
|
+
#
|
5
|
+
# Created by Gregory Brown on 2005-06-04.
|
6
|
+
# Copyright 2005 smtose.org. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "gambit/server/message"
|
11
|
+
|
12
|
+
class TestMessage < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@message = Gambit::Server::Message.new( "Gregory Brown", "James Gray",
|
15
|
+
"Test Message", "A test" )
|
16
|
+
@message.cc << "Allen Turechek" << "Emily Laskin"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_add_cc
|
20
|
+
@message.cc << "Prateek Bahl"
|
21
|
+
assert_equal( ["Allen Turechek", "Emily Laskin", "Prateek Bahl"],
|
22
|
+
@message.cc )
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_text_view
|
26
|
+
assert_equal( "From: Gregory Brown\n" +
|
27
|
+
"To: James Gray\n" +
|
28
|
+
"CC: Allen Turechek, Emily Laskin\n" +
|
29
|
+
"Subject: Test Message\n\n"+
|
30
|
+
"A test\n\n" +
|
31
|
+
"Sent: #{Time.now}\n", @message.view(:gambit_text) )
|
32
|
+
assert_equal( "Gregory Brown\tTest Message\tSent: #{Time.now}",
|
33
|
+
@message.view(:gambit_text_short) )
|
34
|
+
end
|
35
|
+
end
|