egalite 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. data/.gitignore +17 -0
  2. data/README.md +91 -0
  3. data/auth/basic.rb +32 -0
  4. data/blank.rb +53 -0
  5. data/egalite.rb +742 -0
  6. data/errorconsole.rb +77 -0
  7. data/examples/simple/example.rb +39 -0
  8. data/examples/simple/pages/test.html +15 -0
  9. data/examples/simple_db/example_db.rb +103 -0
  10. data/examples/simple_db/pages/edit.html +6 -0
  11. data/helper.rb +251 -0
  12. data/keitai/keitai.rb +107 -0
  13. data/keitai/ketai.rb +11 -0
  14. data/keitai/rack/ketai/carrier/abstract.rb +131 -0
  15. data/keitai/rack/ketai/carrier/au.rb +78 -0
  16. data/keitai/rack/ketai/carrier/docomo.rb +80 -0
  17. data/keitai/rack/ketai/carrier/emoji/ausjisstrtoemojiid.rb +1391 -0
  18. data/keitai/rack/ketai/carrier/emoji/docomosjisstrtoemojiid.rb +759 -0
  19. data/keitai/rack/ketai/carrier/emoji/emojidata.rb +836 -0
  20. data/keitai/rack/ketai/carrier/emoji/softbankutf8strtoemojiid.rb +1119 -0
  21. data/keitai/rack/ketai/carrier/emoji/softbankwebcodetoutf8str.rb +499 -0
  22. data/keitai/rack/ketai/carrier/iphone.rb +8 -0
  23. data/keitai/rack/ketai/carrier/softbank.rb +82 -0
  24. data/keitai/rack/ketai/carrier.rb +17 -0
  25. data/keitai/rack/ketai/middleware.rb +24 -0
  26. data/m17n.rb +193 -0
  27. data/rack/auth/abstract/handler.rb +37 -0
  28. data/rack/auth/abstract/request.rb +37 -0
  29. data/rack/auth/basic.rb +58 -0
  30. data/rack/auth/digest/md5.rb +124 -0
  31. data/rack/auth/digest/nonce.rb +51 -0
  32. data/rack/auth/digest/params.rb +55 -0
  33. data/rack/auth/digest/request.rb +40 -0
  34. data/rack/builder.rb +80 -0
  35. data/rack/cascade.rb +41 -0
  36. data/rack/chunked.rb +49 -0
  37. data/rack/commonlogger.rb +49 -0
  38. data/rack/conditionalget.rb +47 -0
  39. data/rack/config.rb +15 -0
  40. data/rack/content_length.rb +29 -0
  41. data/rack/content_type.rb +23 -0
  42. data/rack/deflater.rb +96 -0
  43. data/rack/directory.rb +157 -0
  44. data/rack/etag.rb +32 -0
  45. data/rack/file.rb +92 -0
  46. data/rack/handler/cgi.rb +62 -0
  47. data/rack/handler/evented_mongrel.rb +8 -0
  48. data/rack/handler/fastcgi.rb +89 -0
  49. data/rack/handler/lsws.rb +63 -0
  50. data/rack/handler/mongrel.rb +90 -0
  51. data/rack/handler/scgi.rb +59 -0
  52. data/rack/handler/swiftiplied_mongrel.rb +8 -0
  53. data/rack/handler/thin.rb +18 -0
  54. data/rack/handler/webrick.rb +73 -0
  55. data/rack/handler.rb +88 -0
  56. data/rack/head.rb +19 -0
  57. data/rack/lint.rb +567 -0
  58. data/rack/lobster.rb +65 -0
  59. data/rack/lock.rb +16 -0
  60. data/rack/logger.rb +20 -0
  61. data/rack/methodoverride.rb +27 -0
  62. data/rack/mime.rb +208 -0
  63. data/rack/mock.rb +190 -0
  64. data/rack/nulllogger.rb +18 -0
  65. data/rack/recursive.rb +61 -0
  66. data/rack/reloader.rb +109 -0
  67. data/rack/request.rb +273 -0
  68. data/rack/response.rb +150 -0
  69. data/rack/rewindable_input.rb +103 -0
  70. data/rack/runtime.rb +27 -0
  71. data/rack/sendfile.rb +144 -0
  72. data/rack/server.rb +271 -0
  73. data/rack/session/abstract/id.rb +140 -0
  74. data/rack/session/cookie.rb +90 -0
  75. data/rack/session/memcache.rb +119 -0
  76. data/rack/session/pool.rb +100 -0
  77. data/rack/showexceptions.rb +349 -0
  78. data/rack/showstatus.rb +106 -0
  79. data/rack/static.rb +38 -0
  80. data/rack/urlmap.rb +55 -0
  81. data/rack/utils.rb +662 -0
  82. data/rack.rb +81 -0
  83. data/route.rb +231 -0
  84. data/sendmail.rb +222 -0
  85. data/sequel_helper.rb +20 -0
  86. data/session.rb +132 -0
  87. data/stringify_hash.rb +63 -0
  88. data/support.rb +35 -0
  89. data/template.rb +287 -0
  90. data/test/french.html +13 -0
  91. data/test/french_msg.html +3 -0
  92. data/test/m17n.txt +30 -0
  93. data/test/mobile.html +15 -0
  94. data/test/setup.rb +8 -0
  95. data/test/static/test.txt +1 -0
  96. data/test/template.html +58 -0
  97. data/test/template_inner.html +1 -0
  98. data/test/template_innerparam.html +1 -0
  99. data/test/test_auth.rb +43 -0
  100. data/test/test_blank.rb +44 -0
  101. data/test/test_csrf.rb +87 -0
  102. data/test/test_errorconsole.rb +91 -0
  103. data/test/test_handler.rb +155 -0
  104. data/test/test_helper.rb +296 -0
  105. data/test/test_keitai.rb +107 -0
  106. data/test/test_m17n.rb +129 -0
  107. data/test/test_route.rb +192 -0
  108. data/test/test_sendmail.rb +146 -0
  109. data/test/test_session.rb +83 -0
  110. data/test/test_stringify_hash.rb +67 -0
  111. data/test/test_template.rb +114 -0
  112. data/test.bat +2 -0
  113. metadata +240 -0
data/test/test_m17n.rb ADDED
@@ -0,0 +1,129 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'egalite'
6
+ require 'm17n'
7
+
8
+ require 'rack/test'
9
+
10
+ require 'setup'
11
+
12
+ class FrenchController < Egalite::Controller
13
+ include Egalite::M17N::Filters
14
+
15
+ def get
16
+ {:g => [:text => 'Do you speak English?']}
17
+ end
18
+ def langcode
19
+ @lang.langcode
20
+ end
21
+ def dlg
22
+ delegate(:action => :msg, :message => 'I am an English man.')
23
+ end
24
+ def msg
25
+ {:message => params[:message]}
26
+ end
27
+ def placeholder
28
+ _("Hoge {0}.", "foo")
29
+ end
30
+ end
31
+
32
+ class T_Translation < Test::Unit::TestCase
33
+ include Rack::Test::Methods
34
+
35
+ def setup
36
+ Egalite::M17N::Translation.load(File.join(File.dirname(__FILE__),'m17n.txt'))
37
+ Egalite::M17N::Translation.allow_content_negotiation = true
38
+ Egalite::M17N::Translation.user_default_lang = 'en'
39
+ end
40
+ def app
41
+ Egalite::Handler.new(:template_path => File.dirname(__FILE__))
42
+ end
43
+ def test_string_translation
44
+ # English
45
+ get "/french/placeholder"
46
+ assert last_response.ok?
47
+ assert_no_match /foo Piyo./, last_response.body
48
+ assert_match /Hoge foo./, last_response.body
49
+
50
+ # French
51
+ get "/french/placeholder", {}, {'HTTP_ACCEPT_LANGUAGE' => 'ja,fr;q=0.8,en'}
52
+ assert last_response.ok?
53
+ assert_match /foo Piyo./, last_response.body
54
+ assert_no_match /Hoge foo./, last_response.body
55
+ end
56
+ def test_translation
57
+ # English
58
+ get "/french"
59
+ assert last_response.ok?
60
+ assert_no_match /Parlez vous Francais\?/, last_response.body
61
+ assert_match /Do you speak English\?/, last_response.body
62
+ assert_no_match /Prix/, last_response.body
63
+ assert_match /Price/, last_response.body
64
+ assert_no_match /Nom de Produit/, last_response.body
65
+ assert_match /Product Name/, last_response.body
66
+ assert_no_match %r|/hoge/itembtn1_fr.jpg|, last_response.body
67
+ assert_match %r|/hoge/itembtn1.jpg|, last_response.body
68
+
69
+ # French
70
+ get "/french", {}, {'HTTP_ACCEPT_LANGUAGE' => 'ja,fr;q=0.8,en'}
71
+ assert last_response.ok?
72
+ assert_match /Parlez vous Francais\?/, last_response.body
73
+ assert_no_match /Do you speak English\?/, last_response.body
74
+ assert_match /Prix/, last_response.body
75
+ assert_no_match /Price/, last_response.body
76
+ assert_match /Nom de Produit/, last_response.body
77
+ assert_no_match /Product Name/, last_response.body
78
+ assert_match %r|/hoge/itembtn1_fr.jpg|, last_response.body
79
+ assert_no_match %r|/hoge/itembtn1.jpg|, last_response.body
80
+ end
81
+ def test_translationmsg
82
+ # English
83
+ get "/french/dlg"
84
+ assert last_response.ok?
85
+ assert_no_match /@@@Je suis un Francais\.@@@/, last_response.body
86
+ assert_match /I am an English man\./, last_response.body
87
+
88
+ get "/french/dlg", {}, {'HTTP_ACCEPT_LANGUAGE' => 'en,fr;q=0.8'}
89
+ assert last_response.ok?
90
+ assert_no_match /@@@Je suis un Francais\.@@@/, last_response.body
91
+ assert_match /I am an English man\./, last_response.body
92
+ get "/french/dlg", {}, {'HTTP_ACCEPT_LANGUAGE' => 'fr', 'HTTP_HOST' => 'en.example.com'}
93
+
94
+ assert last_response.ok?
95
+ assert_no_match /@@@Je suis un Francais\.@@@/, last_response.body
96
+ assert_match /I am an English man\./, last_response.body
97
+
98
+ # French
99
+ get "/french/dlg", {}, {'HTTP_ACCEPT_LANGUAGE' => 'ja,fr;q=0.8,en'}
100
+ assert_match /@@@Je suis un Francais\.@@@/, last_response.body
101
+ assert_no_match /I am an English man\./, last_response.body
102
+
103
+ get "/french/dlg", {}, {'HTTP_HOST' => 'fr.example.com'}
104
+ assert_match /@@@Je suis un Francais\.@@@/, last_response.body
105
+ assert_no_match /I am an English man\./, last_response.body
106
+
107
+ get "/french/dlg", {}, {'HTTP_ACCEPT_LANGUAGE' => 'zh-hans-cn'}
108
+ assert_match /@@@Je suis un Francais\.@@@/, last_response.body
109
+ assert_no_match /I am an English man\./, last_response.body
110
+
111
+ get "/french/dlg", {}, {'HTTP_ACCEPT_LANGUAGE' => 'fr-fr'}
112
+ assert_match /@@@Je suis un Francais\.@@@/, last_response.body
113
+ assert_no_match /I am an English man\./, last_response.body
114
+ end
115
+ def test_langcode
116
+ get "/french/langcode"
117
+ assert last_response.ok?
118
+ assert_equal "en", last_response.body
119
+
120
+ get "/french/langcode", {}, {'HTTP_HOST' => 'fr.example.com'}
121
+ assert last_response.ok?
122
+ assert_equal "fr", last_response.body
123
+
124
+ get "/french/langcode", {}, {'HTTP_HOST' => 'zh-hans-cn.example.com'}
125
+ assert last_response.ok?
126
+ assert_equal "fr", last_response.body
127
+ end
128
+ end
129
+
@@ -0,0 +1,192 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'egalite'
6
+
7
+ require 'rack/test'
8
+
9
+ require 'setup'
10
+
11
+ class DefaultController < Egalite::Controller
12
+ def get(s)
13
+ return url_for(:action => :pathtest) if s == "NoControllerNoAction1"
14
+ return url_for(:controller => :route, :action => :pathtest) if s == "NoControllerNoAction2"
15
+
16
+ s ? s : "root"
17
+ end
18
+ def hashparams
19
+ url_for({:hoge => {:a => 1, :b => 2}})
20
+ end
21
+ def stringparams
22
+ url_for(:params => :abc)
23
+ end
24
+ def pathtest
25
+ req.path_info
26
+ end
27
+ def urltest
28
+ url_for(:controller => :route, :action => :foo, :id => '1', :hoge => :piyo)
29
+ end
30
+ def urltest2
31
+ url_for(:action => :pathtest, :id => '1', :hoge => :piyo)
32
+ end
33
+ def linkto
34
+ link_to("nya",:controller => :route, :action => :foo, :id => '1', :hoge => :piyo)
35
+ end
36
+ def https
37
+ url_for(:action => :hoge, :scheme => :https)
38
+ end
39
+ def host
40
+ url_for(:action => :piyo, :host => 'hoge.example.org')
41
+ end
42
+ end
43
+
44
+ class RouteController < Egalite::Controller
45
+ def get(s)
46
+ s ? s : "null"
47
+ end
48
+ def pathtest
49
+ req.path_info
50
+ end
51
+ def urltest
52
+ url_for(:controller => '/', :action => :pathtest, :id => '1', :hoge => :piyo)
53
+ end
54
+ def urltest2
55
+ url_for(:action => :pathtest, :id => '1', :hoge => :piyo)
56
+ end
57
+ def urltest3
58
+ url_for(:controller => 'noactionroute', :action => :pathtest, :id => '1', :hoge => :piyo)
59
+ end
60
+ def urltest4
61
+ url_for(:controller => :route, :action => nil, :id => 1)
62
+ end
63
+ end
64
+
65
+ class OneSlashController < Egalite::Controller
66
+ def get(s)
67
+ s ? s : "oneslash"
68
+ end
69
+ def pathtest
70
+ req.path_info
71
+ end
72
+ def urltest
73
+ url_for(:controller => '/', :action => :pathtest, :id => '1', :hoge => :piyo)
74
+ end
75
+ def urltest2
76
+ url_for(:action => :pathtest, :id => '1', :hoge => :piyo)
77
+ end
78
+ end
79
+
80
+ class NoactionrouteController < Egalite::Controller
81
+ def get
82
+ url_for(:action => :foo, :id => '1', :hoge => :piyo)
83
+ end
84
+ end
85
+
86
+ class T_Route < Test::Unit::TestCase
87
+ include Rack::Test::Methods
88
+
89
+ def app
90
+ Egalite::Handler.new
91
+ end
92
+ def test_root
93
+ get "/"
94
+ assert last_response.ok?
95
+ assert last_response.body == "root"
96
+ get "/piyo"
97
+ assert last_response.ok?
98
+ assert last_response.body == "piyo"
99
+ get "/hashparams"
100
+ assert last_response.ok?
101
+ assert_match /\/hashparams\?hoge\[[ab]\]=[12]&hoge\[[ab]\]=[12]/, last_response.body
102
+ get "/stringparams"
103
+ assert last_response.ok?
104
+ assert last_response.body == "/stringparams/abc"
105
+ get "/https"
106
+ assert last_response.ok?
107
+ assert last_response.body == "https://example.org/hoge"
108
+ get "/host"
109
+ assert last_response.ok?
110
+ assert last_response.body == "http://hoge.example.org/piyo"
111
+ end
112
+ def test_path
113
+ get "/pathtest/"
114
+ assert last_response.ok?
115
+ assert last_response.body == ""
116
+ get "/pathtest/a"
117
+ assert last_response.ok?
118
+ assert last_response.body == "a"
119
+ get "/pathtest/a/b/c"
120
+ assert last_response.ok?
121
+ assert last_response.body == "a/b/c"
122
+ end
123
+ def test_noslash
124
+ get "/route/"
125
+ assert last_response.ok?
126
+ assert last_response.body == "null"
127
+ get "/route/hoge"
128
+ assert last_response.ok?
129
+ assert last_response.body == "hoge"
130
+ get "/route/pathtest"
131
+ assert last_response.ok?
132
+ assert last_response.body == ""
133
+ get "/route/pathtest/a/b/c"
134
+ assert last_response.ok?
135
+ assert last_response.body == "a/b/c"
136
+ end
137
+ def test_oneslash
138
+ get "/one/slash"
139
+ assert last_response.ok?
140
+ assert last_response.body == "oneslash"
141
+ get "/one/slash/hoge"
142
+ assert last_response.ok?
143
+ assert last_response.body == "hoge"
144
+ get "/one/slash/pathtest"
145
+ assert last_response.ok?
146
+ assert last_response.body == ""
147
+ get "/one/slash/pathtest/a/b/c"
148
+ assert last_response.ok?
149
+ assert last_response.body == "a/b/c"
150
+ end
151
+ def test_urltest
152
+ get "/urltest"
153
+ assert last_response.ok?
154
+ assert last_response.body == "/route/foo/1?hoge=piyo"
155
+ get "/urltest2"
156
+ assert last_response.ok?
157
+ assert last_response.body == "/pathtest/1?hoge=piyo"
158
+ get "/linkto"
159
+ assert last_response.ok?
160
+ assert last_response.body == "<a href='/route/foo/1?hoge=piyo'>nya</a>"
161
+ get "/route/urltest"
162
+ assert last_response.ok?
163
+ assert last_response.body == "/pathtest/1?hoge=piyo"
164
+ get "/route/urltest2"
165
+ assert last_response.ok?
166
+ assert last_response.body == "/route/pathtest/1?hoge=piyo"
167
+ get "/route/urltest3"
168
+ assert last_response.ok?
169
+ assert last_response.body == "/noactionroute/pathtest/1?hoge=piyo"
170
+ get "/route/urltest4"
171
+ assert last_response.ok?
172
+ assert last_response.body == "/route/1"
173
+ get "/one/slash/urltest"
174
+ assert last_response.ok?
175
+ assert last_response.body == "/pathtest/1?hoge=piyo"
176
+ get "/one/slash/urltest2"
177
+ assert last_response.ok?
178
+ assert last_response.body == "/one/slash/pathtest/1?hoge=piyo"
179
+ get "/noactionroute"
180
+ assert last_response.ok?
181
+ assert last_response.body == "/noactionroute/foo/1?hoge=piyo"
182
+ get "/noactionroute/hoge"
183
+ assert last_response.ok?
184
+ assert last_response.body == "/noactionroute/foo/1?hoge=piyo"
185
+ get "/NoControllerNoAction1"
186
+ assert last_response.ok?
187
+ assert last_response.body == "/pathtest"
188
+ get "/NoControllerNoAction2"
189
+ assert last_response.ok?
190
+ assert last_response.body == "/route/pathtest"
191
+ end
192
+ end
@@ -0,0 +1,146 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
+
3
+ require 'test/unit'
4
+ require 'sendmail'
5
+
6
+ $KCODE = 'utf8'
7
+
8
+ class T_Sendmail < Test::Unit::TestCase
9
+ def test_folding
10
+ s = Sendmail.folding('To', "012345678 \n\n "*20)
11
+ a = s.split(/\n/)
12
+ assert_equal 69, a[0].size
13
+ assert_equal 70, a[1].size
14
+ assert_match /\A\s[0-9\s]{69}\Z/, a[1]
15
+ assert_equal 200-70-70, a[2].size
16
+ s2 = Sendmail.folding('To', s)
17
+ assert_equal s, s2
18
+ end
19
+ def test_encode_phrase
20
+ s = Sendmail.encode_phrase('To', "0123\"6\\9\x00"*20)
21
+ assert_equal "\n \"" + ('0123\\"6\\\\9'*20) + '"', s
22
+ end
23
+ def test_encode_unstructured
24
+ s = Sendmail.encode_unstructured('To', "0123\"6\\9\x00"*20)
25
+ assert_equal "\n " + ('0123"6\\9'*20), s
26
+ end
27
+ def test_parse_addrspec
28
+ (local, domain) = Sendmail.parse_addrspec('"baz\\"@bar\\"@foo"@example.com')
29
+ assert_equal '"baz\\"@bar\\"@foo"', local
30
+ assert_equal 'example.com', domain
31
+ (local, domain) = Sendmail.parse_addrspec('"a"@example.com')
32
+ assert_equal '"a"', local
33
+ assert_equal 'example.com', domain
34
+ (local, domain) = Sendmail.parse_addrspec('bar@example.com')
35
+ assert_equal 'bar', local
36
+ assert_equal 'example.com', domain
37
+ (local, domain) = Sendmail.parse_addrspec('bar@example.com.')
38
+ assert_equal nil, local
39
+ (local, domain) = Sendmail.parse_addrspec('bar@example..com')
40
+ assert_equal nil, local
41
+ (local, domain) = Sendmail.parse_addrspec('bar@example')
42
+ assert_equal nil, local
43
+ end
44
+ def test_address
45
+ s = Sendmail.address('foo@example.com', '新井 俊一', 'To')
46
+ assert_match /\A\=\?UTF-8\?B\?(.+?)\?\= <foo@example.com>\Z/, s
47
+ s = Sendmail.address('foo@example.com', "\x00ARAI \n Shunichi", 'To')
48
+ assert_match /"ARAI Shunichi" <foo@example.com>\Z/, s
49
+ end
50
+ def test_multibyte_folding
51
+ s = Sendmail.multibyte_folding('Subject', 'あいうえお'*20)
52
+ a = s.split(/\n/)
53
+ assert "Subject: #{a[0]}".size < 76
54
+ s2 = a.map { |e|
55
+ assert e.size < 77
56
+ assert_match /\A\s?\=\?UTF-8\?B\?(.+?)\?\=\Z/, e
57
+ e =~ /\=\?UTF-8\?B\?(.+?)\?\=/
58
+ $1.unpack('m')[0]
59
+ }.join
60
+ assert_equal 'あいうえお'*20, s2
61
+ end
62
+ def test_mailboxlist
63
+ s = Sendmail.mailboxlist('foo@example.com')
64
+ assert_equal 'foo@example.com',s
65
+ end
66
+ def parse_message(s)
67
+ (header, body) = s.split(/\n\n/,2)
68
+ headers = {}
69
+ header.gsub(/\n[\s\t]+/, ' ').split(/\n/).each { |line|
70
+ (k,v) = line.split(/: +/,2)
71
+ headers[k] = v
72
+ }
73
+ [headers, body]
74
+ end
75
+ def test_message_7bit
76
+ s = Sendmail.message('hoge',:from=>'hoge@example.com',:subject=>'test')
77
+ (h,b) = parse_message(s)
78
+ assert_equal 'hoge', b
79
+ assert_equal '1.0', h['MIME-Version']
80
+ assert Time.rfc822(h['Date'])
81
+ assert_equal '7bit', h['Content-Transfer-Encoding']
82
+ assert_equal 'text/plain; charset=UTF-8', h['Content-Type']
83
+ assert_equal 'test', h['Subject']
84
+ end
85
+ def test_message_multibyte
86
+ s = Sendmail.message('あいうえお',:from=>'hoge@example.com')
87
+ (h,b) = parse_message(s)
88
+ assert_equal 'あいうえお', b.unpack('m')[0]
89
+ assert_equal '1.0', h['MIME-Version']
90
+ assert Time.rfc822(h['Date'])
91
+ assert_equal 'base64', h['Content-Transfer-Encoding']
92
+ assert_equal 'text/plain; charset=UTF-8', h['Content-Type']
93
+ end
94
+ def params
95
+ {
96
+ :date => Time.local(0),
97
+ :from => 'hoge@example.com',
98
+ :to => [Sendmail.address('arai@example.com','新井俊一'),
99
+ ['tanaka@example.com','田中太郎'],
100
+ {:address => 'takeda@example.com', :name => '武田一郎'},
101
+ 'ueno@example.com'
102
+ ],
103
+ :cc => Sendmail.address('foo@example.com', 'Foo Bar'),
104
+ :bcc => Sendmail.address('zzz@example.com', 'zzz'),
105
+ :reply_to=> Sendmail.address('baz@example.com', 'Baz Bzz'),
106
+ :subject => 'こんにちは',
107
+ }
108
+ end
109
+ def test_message_headers
110
+ assert_raise(RuntimeError) { Sendmail.message('',{}) }
111
+ assert_raise(RuntimeError) { Sendmail.message('',{:sender => ['1','2']}) }
112
+ assert_raise(RuntimeError) { Sendmail.message('',{:from => [1,2,3]}) }
113
+ s = Sendmail.message('あいうえお',params)
114
+ (h,b) = parse_message(s)
115
+ assert_equal 'あいうえお', b.unpack('m')[0]
116
+ assert_equal '1.0', h['MIME-Version']
117
+ assert_equal Time.local(0), Time.rfc822(h['Date'])
118
+ assert_equal 'base64', h['Content-Transfer-Encoding']
119
+ assert_equal 'text/plain; charset=UTF-8', h['Content-Type']
120
+ assert_equal 'hoge@example.com', h['From']
121
+ assert_match /\A\=\?UTF-8\?B\?(.+?)\?\=\n?\Z/, h['Subject']
122
+ h['Subject'] =~ /\A\=\?UTF-8\?B\?(.+?)\?\=/
123
+ assert_equal 'こんにちは', $1.unpack('m')[0]
124
+ to = h['To']
125
+ tos = to.split(/\s*,\s+/)
126
+ assert_match /\A\=\?UTF-8\?B\?(.+?)\?\= <arai@example.com>\Z/, tos[0]
127
+ assert_match /\A\=\?UTF-8\?B\?(.+?)\?\= <tanaka@example.com>\Z/, tos[1]
128
+ assert_match /\A\=\?UTF-8\?B\?(.+?)\?\= <takeda@example.com>\Z/, tos[2]
129
+ assert_match /\Aueno@example.com\Z/, tos[3]
130
+ to =~ /\A\=\?UTF-8\?B\?(.+?)\?\=.+?\=\?UTF-8\?B\?(.+?)\?\=.+?\=\?UTF-8\?B\?(.+?)\?\=/
131
+ (a,b,c) = [$1,$2,$3].map { |s| s.unpack('m')[0] }
132
+ assert_match '新井俊一', a
133
+ assert_match '田中太郎', b
134
+ assert_match '武田一郎', c
135
+ assert_match '"Foo Bar" <foo@example.com>', h['Cc']
136
+ assert_match '"Baz Bzz" <baz@example.com>', h['Reply-To']
137
+ assert_nil h['Bcc']
138
+ end
139
+ def test_to_addresses
140
+ a = Sendmail.to_addresses(params)
141
+ %w[foo@example.com arai@example.com tanaka@example.com takeda@example.com ueno@example.com zzz@example.com].each { |s|
142
+ assert a.include?(s)
143
+ }
144
+ end
145
+ end
146
+
@@ -0,0 +1,83 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'egalite'
6
+ require 'sequel'
7
+
8
+ require 'rack/test'
9
+
10
+ require 'setup'
11
+
12
+ class SessionController < Egalite::Controller
13
+ def login(id)
14
+ session.create(:user_id => id)
15
+ redirect :action => :page
16
+ end
17
+ def page
18
+ return redirect_to :action => :login if session[:user_id] == nil
19
+ session[:user_id].to_s
20
+ end
21
+ def modify(id)
22
+ session[:user_id] = id
23
+ session.save
24
+ redirect :action => :page
25
+ end
26
+ def logout
27
+ session.delete
28
+ redirect :action => :login
29
+ end
30
+ end
31
+
32
+ class T_Session < Test::Unit::TestCase
33
+ include Rack::Test::Methods
34
+
35
+ def app
36
+ db = Sequel.sqlite
37
+ Egalite::SessionSequel.create_table(db)
38
+ db.alter_table :sessions do
39
+ add_column :user_id, :integer
40
+ end
41
+ Egalite::Handler.new(
42
+ :db => db,
43
+ :session_handler => Egalite::SessionSequel
44
+ )
45
+ end
46
+ def test_session
47
+ get "/session/page"
48
+ assert last_response.redirect?
49
+ assert last_response.headers['location'] == "/session/login"
50
+ assert last_response.headers['set-cookie'].blank?
51
+ get "/session/login/9876"
52
+ assert last_response.redirect?
53
+ assert last_response.headers['location'] == "/session/page"
54
+ assert last_response.headers['set-cookie'] =~ /^egalite_session=[0-9]+_[0-9a-z]+;\s+/
55
+ get "/session/page"
56
+ assert last_response.ok?
57
+ assert last_response.body =~ /9876/
58
+ assert last_response.headers['set-cookie'] =~ /^egalite_session=[0-9]+_[0-9a-z]+;\s+/
59
+ get "/session/modify/1234"
60
+ assert last_response.redirect?
61
+ assert last_response.headers['location'] == "/session/page"
62
+ assert last_response.headers['set-cookie'] =~ /^egalite_session=[0-9]+_[0-9a-z]+;\s+/
63
+ get "/session/page"
64
+ assert last_response.ok?
65
+ assert last_response.body =~ /1234/
66
+ assert last_response.headers['set-cookie'] =~ /^egalite_session=[0-9]+_[0-9a-z]+;\s+/
67
+ get "/session/logout"
68
+ assert last_response.redirect?
69
+ assert last_response.headers['location'] == "/session/login"
70
+ assert last_response.headers['set-cookie'] =~ /^egalite_session=;\s+/
71
+ get "/session/page"
72
+ assert last_response.redirect?
73
+ assert last_response.headers['location'] == "/session/login"
74
+ assert last_response.headers['set-cookie'].blank?
75
+ end
76
+ def test_abstract_session
77
+ session = Egalite::Session.new(nil,nil)
78
+ assert_raise(NotImplementedError) { session.create }
79
+ assert_raise(NotImplementedError) { session.load }
80
+ assert_raise(NotImplementedError) { session.save }
81
+ assert_raise(NotImplementedError) { session.delete }
82
+ end
83
+ end
@@ -0,0 +1,67 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'egalite'
7
+ require 'rexml/xpath'
8
+ require 'rexml/document'
9
+
10
+
11
+ class T_StringifyHash < Test::Unit::TestCase
12
+ include Egalite
13
+
14
+ def setup
15
+ @target = StringifyHash.new
16
+ end
17
+
18
+ def test_key_set_should_assume_symbol_as_string
19
+
20
+ @target[:key] = 10
21
+ assert_equal(@target["key"], 10)
22
+ end
23
+
24
+ def test_key_get_should_assume_symbol_as_string
25
+ @target["key"] = 10
26
+ assert_equal(@target[:key], 10)
27
+ end
28
+
29
+ def test_key_p_should_assume_symbol_as_string
30
+ @target["key"] = 10
31
+ assert(@target.key?(:key))
32
+ end
33
+
34
+ def test_update_should_assume_symbol_as_string
35
+ @target.update({:key => 10})
36
+ assert(@target.key?("key"))
37
+ end
38
+
39
+ def test_fetch_should_be_ok
40
+ @target["key"] = 10
41
+ assert_equal(@target.fetch(:key), 10)
42
+ end
43
+
44
+ def test_values_at_should_be_ok
45
+ @target["key1"] = 10
46
+ @target["key2"] = 20
47
+ assert_equal([10, 20], @target.values_at(:key1, :key2))
48
+ end
49
+
50
+ def test_dup_should_create_new_one
51
+ another = @target.dup
52
+ assert_equal(another, @target)
53
+ assert_equal(another.class, StringifyHash)
54
+ another["hoge"] = "ika"
55
+ assert(another != @target) # should be different instance
56
+ end
57
+
58
+ def test_dup_should_create_new_hash
59
+ another = @target.to_hash
60
+ assert_equal(another.class, Hash)
61
+ another["hoge"] = "ika"
62
+ assert(another != @target) # should be different instance
63
+ end
64
+ end
65
+
66
+ # XXX: test form
67
+ # XXX: test expand_name