raw 0.49.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/CONTRIBUTORS +106 -0
- data/doc/LICENSE +32 -0
- data/doc/coding_conventions.txt +11 -0
- data/lib/raw.rb +42 -0
- data/lib/raw/adapter.rb +113 -0
- data/lib/raw/adapter/cgi.rb +41 -0
- data/lib/raw/adapter/fastcgi.rb +48 -0
- data/lib/raw/adapter/mongrel.rb +146 -0
- data/lib/raw/adapter/script.rb +94 -0
- data/lib/raw/adapter/webrick.rb +144 -0
- data/lib/raw/adapter/webrick/vcr.rb +91 -0
- data/lib/raw/cgi.rb +323 -0
- data/lib/raw/cgi/cookie.rb +47 -0
- data/lib/raw/cgi/http.rb +62 -0
- data/lib/raw/compiler.rb +138 -0
- data/lib/raw/compiler/filter/cleanup.rb +21 -0
- data/lib/raw/compiler/filter/elements.rb +166 -0
- data/lib/raw/compiler/filter/elements/element.rb +210 -0
- data/lib/raw/compiler/filter/localization.rb +23 -0
- data/lib/raw/compiler/filter/markup.rb +32 -0
- data/lib/raw/compiler/filter/morph.rb +123 -0
- data/lib/raw/compiler/filter/morph/each.rb +34 -0
- data/lib/raw/compiler/filter/morph/for.rb +11 -0
- data/lib/raw/compiler/filter/morph/if.rb +26 -0
- data/lib/raw/compiler/filter/morph/selected_if.rb +43 -0
- data/lib/raw/compiler/filter/morph/standard.rb +55 -0
- data/lib/raw/compiler/filter/morph/times.rb +27 -0
- data/lib/raw/compiler/filter/script.rb +116 -0
- data/lib/raw/compiler/filter/squeeze.rb +16 -0
- data/lib/raw/compiler/filter/static_include.rb +74 -0
- data/lib/raw/compiler/filter/template.rb +121 -0
- data/lib/raw/compiler/reloader.rb +96 -0
- data/lib/raw/context.rb +154 -0
- data/lib/raw/context/flash.rb +157 -0
- data/lib/raw/context/global.rb +88 -0
- data/lib/raw/context/request.rb +338 -0
- data/lib/raw/context/response.rb +57 -0
- data/lib/raw/context/session.rb +198 -0
- data/lib/raw/context/session/drb.rb +11 -0
- data/lib/raw/context/session/file.rb +15 -0
- data/lib/raw/context/session/memcached.rb +13 -0
- data/lib/raw/context/session/memory.rb +12 -0
- data/lib/raw/context/session/og.rb +15 -0
- data/lib/raw/context/session/pstore.rb +13 -0
- data/lib/raw/control.rb +18 -0
- data/lib/raw/control/attribute.rb +91 -0
- data/lib/raw/control/attribute/checkbox.rb +25 -0
- data/lib/raw/control/attribute/datetime.rb +21 -0
- data/lib/raw/control/attribute/file.rb +20 -0
- data/lib/raw/control/attribute/fixnum.rb +26 -0
- data/lib/raw/control/attribute/float.rb +26 -0
- data/lib/raw/control/attribute/options.rb +38 -0
- data/lib/raw/control/attribute/password.rb +16 -0
- data/lib/raw/control/attribute/text.rb +16 -0
- data/lib/raw/control/attribute/textarea.rb +16 -0
- data/lib/raw/control/none.rb +16 -0
- data/lib/raw/control/relation.rb +59 -0
- data/lib/raw/control/relation/belongs_to.rb +0 -0
- data/lib/raw/control/relation/has_many.rb +97 -0
- data/lib/raw/control/relation/joins_many.rb +0 -0
- data/lib/raw/control/relation/many_to_many.rb +0 -0
- data/lib/raw/control/relation/refers_to.rb +29 -0
- data/lib/raw/controller.rb +37 -0
- data/lib/raw/controller/publishable.rb +160 -0
- data/lib/raw/dispatcher.rb +209 -0
- data/lib/raw/dispatcher/format.rb +108 -0
- data/lib/raw/dispatcher/format/atom.rb +31 -0
- data/lib/raw/dispatcher/format/css.rb +0 -0
- data/lib/raw/dispatcher/format/html.rb +42 -0
- data/lib/raw/dispatcher/format/json.rb +31 -0
- data/lib/raw/dispatcher/format/rss.rb +33 -0
- data/lib/raw/dispatcher/format/xoxo.rb +31 -0
- data/lib/raw/dispatcher/mounter.rb +60 -0
- data/lib/raw/dispatcher/router.rb +111 -0
- data/lib/raw/errors.rb +19 -0
- data/lib/raw/helper.rb +86 -0
- data/lib/raw/helper/benchmark.rb +23 -0
- data/lib/raw/helper/buffer.rb +60 -0
- data/lib/raw/helper/cookie.rb +32 -0
- data/lib/raw/helper/debug.rb +28 -0
- data/lib/raw/helper/default.rb +16 -0
- data/lib/raw/helper/feed.rb +451 -0
- data/lib/raw/helper/form.rb +284 -0
- data/lib/raw/helper/javascript.rb +59 -0
- data/lib/raw/helper/layout.rb +40 -0
- data/lib/raw/helper/navigation.rb +87 -0
- data/lib/raw/helper/pager.rb +305 -0
- data/lib/raw/helper/table.rb +247 -0
- data/lib/raw/helper/xhtml.rb +218 -0
- data/lib/raw/helper/xml.rb +125 -0
- data/lib/raw/mixin/magick.rb +35 -0
- data/lib/raw/mixin/sweeper.rb +71 -0
- data/lib/raw/mixin/thumbnails.rb +1 -0
- data/lib/raw/mixin/webfile.rb +165 -0
- data/lib/raw/render.rb +271 -0
- data/lib/raw/render/builder.rb +26 -0
- data/lib/raw/render/caching.rb +81 -0
- data/lib/raw/render/call.rb +43 -0
- data/lib/raw/render/send_file.rb +46 -0
- data/lib/raw/render/stream.rb +39 -0
- data/lib/raw/scaffold.rb +13 -0
- data/lib/raw/scaffold/controller.rb +25 -0
- data/lib/raw/scaffold/model.rb +157 -0
- data/lib/raw/test.rb +5 -0
- data/lib/raw/test/assertions.rb +169 -0
- data/lib/raw/test/context.rb +55 -0
- data/lib/raw/test/testcase.rb +79 -0
- data/lib/raw/util/attr.rb +128 -0
- data/lib/raw/util/encode_uri.rb +149 -0
- data/lib/raw/util/html_filter.rb +538 -0
- data/lib/raw/util/markup.rb +130 -0
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/CONFIG.rb +3 -0
- data/test/nitro/adapter/raw_post1.bin +9 -0
- data/test/nitro/adapter/tc_webrick.rb +16 -0
- data/test/nitro/cgi/tc_cookie.rb +14 -0
- data/test/nitro/cgi/tc_request.rb +61 -0
- data/test/nitro/compiler/tc_client_morpher.rb +47 -0
- data/test/nitro/compiler/tc_compiler.rb +25 -0
- data/test/nitro/dispatcher/tc_mounter.rb +47 -0
- data/test/nitro/helper/tc_feed.rb +135 -0
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_pager.rb +35 -0
- data/test/nitro/helper/tc_table.rb +68 -0
- data/test/nitro/helper/tc_xhtml.rb +19 -0
- data/test/nitro/tc_caching.rb +19 -0
- data/test/nitro/tc_cgi.rb +222 -0
- data/test/nitro/tc_context.rb +17 -0
- data/test/nitro/tc_controller.rb +103 -0
- data/test/nitro/tc_controller_aspect.rb +32 -0
- data/test/nitro/tc_controller_params.rb +885 -0
- data/test/nitro/tc_dispatcher.rb +109 -0
- data/test/nitro/tc_element.rb +85 -0
- data/test/nitro/tc_flash.rb +59 -0
- data/test/nitro/tc_helper.rb +47 -0
- data/test/nitro/tc_render.rb +119 -0
- data/test/nitro/tc_router.rb +61 -0
- data/test/nitro/tc_server.rb +35 -0
- data/test/nitro/tc_session.rb +66 -0
- data/test/nitro/tc_template.rb +71 -0
- data/test/nitro/util/tc_encode_url.rb +87 -0
- data/test/nitro/util/tc_markup.rb +31 -0
- data/test/public/blog/another/very_litle/index.xhtml +1 -0
- data/test/public/blog/inc1.xhtml +2 -0
- data/test/public/blog/inc2.xhtml +1 -0
- data/test/public/blog/list.xhtml +9 -0
- data/test/public/dummy_mailer/registration.xhtml +5 -0
- metadata +244 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'nitro/helper/navigation'
|
5
|
+
|
6
|
+
|
7
|
+
class TC_NavigationHelper < Test::Unit::TestCase # :nodoc: all
|
8
|
+
include Nitro
|
9
|
+
include NavigationHelper
|
10
|
+
FirstController = Class.new(Controller) do
|
11
|
+
def self.mount_path() "controller1" end
|
12
|
+
end
|
13
|
+
Second = Class.new(Controller) do
|
14
|
+
def self.mount_path() "controller2" end
|
15
|
+
end
|
16
|
+
MockRequest=Struct.new(:path)
|
17
|
+
attr :request
|
18
|
+
def setup
|
19
|
+
@request=MockRequest.new("controller1")
|
20
|
+
end
|
21
|
+
def check_div(text)
|
22
|
+
#offsets accomodate \n
|
23
|
+
assert_equal '<div id="navcontainer">',text[0,23]
|
24
|
+
assert_equal '</div>',text[-8,6]
|
25
|
+
end
|
26
|
+
def check_ul(text)
|
27
|
+
assert_equal '<ul id="navlist">',text[25,17]
|
28
|
+
assert_equal '</ul>',text[-14,5]
|
29
|
+
end
|
30
|
+
def test_navfor_around_html
|
31
|
+
text= menu_for(FirstController)
|
32
|
+
check_div(text)
|
33
|
+
check_ul(text)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_navfor_inner_html_single
|
37
|
+
text= menu_for(FirstController)
|
38
|
+
text.gsub!(%r{</?(div|ul).*?>},'')
|
39
|
+
text.gsub!("\n",'')
|
40
|
+
assert_equal '<li id="active"><a href="controller1" id="current"> TC_NavigationHelper::First </a></li>',
|
41
|
+
text.strip
|
42
|
+
end
|
43
|
+
def test_navfor_inner_html_many
|
44
|
+
text = menu_for(FirstController,Second)
|
45
|
+
assert_match %r|href="controller1" id="current">| , text
|
46
|
+
assert_match %r|href="controller2">| , text
|
47
|
+
assert_match %r| TC_NavigationHelper::First | , text
|
48
|
+
assert_match %r| TC_NavigationHelper::Second |, text
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_navfor_yielding
|
52
|
+
text= menu_for(FirstController,Second) do |controller|
|
53
|
+
controller==FirstController ? 'first' : 'second'
|
54
|
+
end
|
55
|
+
assert_match %r|<a href="controller1".*first </a>|,text
|
56
|
+
assert_match %r|<a href="controller2".*second </a>|,text
|
57
|
+
end
|
58
|
+
def test_navforhash_around_html
|
59
|
+
text= menu_from_hash('path'=>'text')
|
60
|
+
check_div(text)
|
61
|
+
check_ul(text)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_navforhash_inner_html_single
|
65
|
+
text= menu_from_hash('link'=>'text')
|
66
|
+
text.gsub!(%r{</?(div|ul).*?>},'')
|
67
|
+
text.gsub!("\n",'')
|
68
|
+
assert_equal '<li><a href="link"> text </a></li>',
|
69
|
+
text.strip
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'nitro/helper/pager'
|
6
|
+
|
7
|
+
class TC_Pager < Test::Unit::TestCase # :nodoc: all
|
8
|
+
include Nitro
|
9
|
+
include Nitro::PagerHelper
|
10
|
+
|
11
|
+
class RequestMock < Hash
|
12
|
+
attr_accessor :query
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@query = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(k, default)
|
19
|
+
return self[k] || default
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def request
|
24
|
+
RequestMock.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_all
|
28
|
+
stuff = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
29
|
+
|
30
|
+
items, pager = paginate(stuff, :per_page => 2)
|
31
|
+
assert_equal 2, items.size
|
32
|
+
assert_equal 9, pager.total_count
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'nitro/helper/table'
|
5
|
+
|
6
|
+
class TC_TableHelper < Test::Unit::TestCase # :nodoc: all
|
7
|
+
include Nitro
|
8
|
+
include TableHelper
|
9
|
+
|
10
|
+
User = Struct.new(:name, :password, :email)
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@headers = %w{Name Password Email}
|
14
|
+
@users = [
|
15
|
+
User.new('gmosx', 'huh?', 'gm@nowhere.com'),
|
16
|
+
User.new('renos', 'nah', 'renos@nowhere.com'),
|
17
|
+
User.new('stella', 'hoh', 'stella@love.com')
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
@users = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_table
|
26
|
+
values = @users.collect { |u| [u.name, u.password, u.email] }
|
27
|
+
table = build_table(:id => 'test', :headers => @headers, :values => values)
|
28
|
+
res = %|<table id="test"><tr><th>Name</th><th>Password</th><th>Email</th></tr><tr><td>gmosx</td><td>huh?</td><td>gm@nowhere.com</td></tr><tr><td>renos</td><td>nah</td><td>renos@nowhere.com</td></tr><tr><td>stella</td><td>hoh</td><td>stella@love.com</td></tr></table>|
|
29
|
+
assert_equal res, table
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_table_footer
|
33
|
+
values = @users.collect { |u| [u.name, u.password, u.email] }
|
34
|
+
footers = ["#{@users.size}users", '', '']
|
35
|
+
|
36
|
+
table = build_table(:id => 'test2', :headers => @headers, :values => values, :footers => footers)
|
37
|
+
|
38
|
+
res = %|<table id="test2"><thead><tr><th>Name</th><th>Password</th><th>Email</th></tr></thead><tfoot><tr><td>3users</td><td></td><td></td></tr></tfoot><tr><td>gmosx</td><td>huh?</td><td>gm@nowhere.com</td></tr><tr><td>renos</td><td>nah</td><td>renos@nowhere.com</td></tr><tr><td>stella</td><td>hoh</td><td>stella@love.com</td></tr></table>|
|
39
|
+
assert_equal res, table
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_table_tbody
|
43
|
+
values = []
|
44
|
+
values << @users[0...1].collect { |u| [u.name, u.password, u.email] }
|
45
|
+
values << @users[1..2].collect { |u| [u.name, u.password, u.email] }
|
46
|
+
table = build_table(:id => 'test', :headers => @headers, :values => values)
|
47
|
+
res = %|<table id="test"><thead><tr><th>Name</th><th>Password</th><th>Email</th></tr></thead><tbody><tr><td>gmosx</td><td>huh?</td><td>gm@nowhere.com</td></tr></tbody><tbody><tr><td>renos</td><td>nah</td><td>renos@nowhere.com</td></tr><tr><td>stella</td><td>hoh</td><td>stella@love.com</td></tr></tbody></table>|
|
48
|
+
assert_equal res, table
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_table_alternating_rows
|
52
|
+
values = @users.collect { |u| [u.name, u.password, u.email] }
|
53
|
+
table = build_table(:id => 'test', :headers => @headers, :values => values, :alternating_rows => true)
|
54
|
+
res = %|<table id="test"><tr><th>Name</th><th>Password</th><th>Email</th></tr><tr class="row_odd"><td>gmosx</td><td>huh?</td><td>gm@nowhere.com</td></tr><tr class="row_even"><td>renos</td><td>nah</td><td>renos@nowhere.com</td></tr><tr class="row_odd"><td>stella</td><td>hoh</td><td>stella@love.com</td></tr></table>|
|
55
|
+
assert_equal res, table
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_table_alternating_rows_tbody
|
59
|
+
values = []
|
60
|
+
values << @users[0...1].collect { |u| [u.name, u.password, u.email] }
|
61
|
+
values << @users[1..2].collect { |u| [u.name, u.password, u.email] }
|
62
|
+
table = build_table(:id => 'test', :headers => @headers, :values => values, :alternating_rows => true)
|
63
|
+
res = %|<table id="test"><thead><tr><th>Name</th><th>Password</th><th>Email</th></tr></thead><tbody><tr class="row_odd"><td>gmosx</td><td>huh?</td><td>gm@nowhere.com</td></tr></tbody><tbody><tr class="row_even"><td>renos</td><td>nah</td><td>renos@nowhere.com</td></tr><tr class="row_odd"><td>stella</td><td>hoh</td><td>stella@love.com</td></tr></tbody></table>|
|
64
|
+
assert_equal res, table
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'nitro/helper/xhtml'
|
5
|
+
|
6
|
+
class TC_XhtmlHelper < Test::Unit::TestCase # :nodoc: all
|
7
|
+
include Nitro
|
8
|
+
include XhtmlHelper
|
9
|
+
|
10
|
+
def test_all
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_popup
|
14
|
+
res = popup :text => 'Pop', :url => 'add-comment', :scrollbars => true
|
15
|
+
exp = %{<a href="#" onclick="javascript: var pwl = (screen.width - 320) / 2; var pwt = (screen.height - 240) / 2; window.open('add-comment', 'Popup', 'width=320,height=240,top='+pwt+',left='+pwl+', resizable=no,scrollbars=yes'); return false;"">Pop</a>}
|
16
|
+
assert_equal exp, res
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'nitro/caching'
|
6
|
+
|
7
|
+
class TC_Caching < Test::Unit::TestCase # :nodoc: all
|
8
|
+
include Nitro
|
9
|
+
|
10
|
+
class DummyCa
|
11
|
+
include Nitro::Caching
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_all
|
15
|
+
# bug:
|
16
|
+
assert_equal [], Caching.public_instance_methods
|
17
|
+
assert_equal [], DummyCa.public_instance_methods.grep(/caching/)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'socket'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
require 'facets/core/kernel/assign_with'
|
10
|
+
|
11
|
+
require 'nitro/cgi'
|
12
|
+
require 'nitro/cgi/cookie'
|
13
|
+
|
14
|
+
class String
|
15
|
+
class << self
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'inline'
|
19
|
+
|
20
|
+
inline do |builder|
|
21
|
+
builder.c_raw <<-EOS
|
22
|
+
static VALUE rnd(int argc, VALUE* args, VALUE self)
|
23
|
+
{
|
24
|
+
if (!argc)
|
25
|
+
rb_raise(rb_eArgError, "not enough arguments");
|
26
|
+
if (argc > 0)
|
27
|
+
Check_Type(args[0], T_FIXNUM);
|
28
|
+
if (argc > 1)
|
29
|
+
Check_Type(args[1], T_FIXNUM);
|
30
|
+
|
31
|
+
int size = FIX2INT(args[0]);
|
32
|
+
int seed = argc > 1 ? FIX2INT(args[1]) : 0;
|
33
|
+
int i = 0;
|
34
|
+
VALUE str = rb_str_new((char*)0, size);
|
35
|
+
|
36
|
+
srandom(seed);
|
37
|
+
|
38
|
+
for (; i < size; i++) {
|
39
|
+
RSTRING(str)->ptr[i] = (char)(((random() % ('z' - ' ')) + ' '));
|
40
|
+
}
|
41
|
+
|
42
|
+
return str;
|
43
|
+
}
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
|
47
|
+
def random(size, seed = 22)
|
48
|
+
return rnd(size.to_i, seed.to_i)
|
49
|
+
end
|
50
|
+
|
51
|
+
rescue Exception => e
|
52
|
+
puts "please install Ruby::Inline (gem install RubyInline) to speed up this test"
|
53
|
+
|
54
|
+
def random(size)
|
55
|
+
s = String.new
|
56
|
+
range = (' '..'z').to_a
|
57
|
+
r_size = range.size
|
58
|
+
for i in (0...size)
|
59
|
+
s << range[Kernel.rand(r_size)] # ascii range
|
60
|
+
end
|
61
|
+
s
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class TestAdapterCgi < Test::Unit::TestCase # :nodoc: all
|
70
|
+
include Nitro
|
71
|
+
|
72
|
+
def test_rnd
|
73
|
+
size = 500
|
74
|
+
d = String.random(size)
|
75
|
+
|
76
|
+
assert_equal size, d.size
|
77
|
+
assert d.all? {|x| (' '..'z').include?(x) }, 'has to have ascii, had: ' + d.inspect
|
78
|
+
end
|
79
|
+
|
80
|
+
class User
|
81
|
+
attr_accessor :name
|
82
|
+
attr_accessor :password
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_parse_query_parameters
|
86
|
+
qs = 'name=tml;id=12354'
|
87
|
+
params = Cgi.parse_query_string(qs)
|
88
|
+
assert_equal 2, params.size
|
89
|
+
assert_equal 'tml', params['name']
|
90
|
+
|
91
|
+
qs = ''
|
92
|
+
params = Cgi.parse_query_string(qs)
|
93
|
+
assert_equal 0, params.size
|
94
|
+
|
95
|
+
qs = nil
|
96
|
+
params = Cgi.parse_query_string(qs)
|
97
|
+
assert_equal 0, params.size
|
98
|
+
|
99
|
+
qs = 'name=tml;arr[]=1;arr[]=2;arr[]=3'
|
100
|
+
params = Cgi.parse_query_string(qs)
|
101
|
+
assert_equal 2, params.size
|
102
|
+
arr = params['arr']
|
103
|
+
assert_equal 3, arr.size
|
104
|
+
|
105
|
+
qs = 'other=1;user.name=gmosx;user.password=hello'
|
106
|
+
params = Cgi.parse_query_string(qs)
|
107
|
+
assert_equal 2, params.size
|
108
|
+
u = params['user']
|
109
|
+
assert_equal 'gmosx', u['name']
|
110
|
+
assert_equal 'hello', u['password']
|
111
|
+
|
112
|
+
user = User.new
|
113
|
+
user.assign_with(params['user'])
|
114
|
+
assert_equal 'gmosx', user.name
|
115
|
+
assert_equal 'hello', user.password
|
116
|
+
|
117
|
+
# Ruby/Scriptaculous compatibility.
|
118
|
+
|
119
|
+
qs = 'other=1;user[name]=gmosx;user[password]=hello'
|
120
|
+
params = Cgi.parse_query_string(qs)
|
121
|
+
assert_equal 2, params.size
|
122
|
+
u = params['user']
|
123
|
+
assert_equal 'gmosx', u['name']
|
124
|
+
assert_equal 'hello', u['password']
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_parse_cookies
|
128
|
+
context = OpenStruct.new
|
129
|
+
context.env = {}
|
130
|
+
context.env['HTTP_COOKIE'] = 'nsid=123; nauth=gmosx:passwd'
|
131
|
+
Cgi.parse_cookies(context)
|
132
|
+
assert_equal 2, context.cookies.size
|
133
|
+
assert_equal '123', context.cookies['nsid']
|
134
|
+
|
135
|
+
context.env = {}
|
136
|
+
context.env['HTTP_COOKIE'] = 'nsid=123; nsid=23123'
|
137
|
+
cookies = Cgi.parse_cookies(context)
|
138
|
+
assert_equal 1, context.cookies.size
|
139
|
+
assert_equal "123" + "\0" + "23123", context.cookies['nsid']
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_response_headers
|
143
|
+
ctx = OpenStruct.new
|
144
|
+
ctx.status = 200
|
145
|
+
ctx.response_cookies = {
|
146
|
+
'nsid' => Cookie.new('nsid', '1233'),
|
147
|
+
'nauth' => Cookie.new('nauth', 'gmosx')
|
148
|
+
}
|
149
|
+
ctx.response_headers = {
|
150
|
+
'Content-Type' => 'text/html'
|
151
|
+
}
|
152
|
+
|
153
|
+
res = "Status: 200 OK\r\nContent-Type: text/html\r\nSet-Cookie: nauthnauth=gmosx; Path=/\r\nSet-Cookie: nsidnsid=1233; Path=/\r\n\r\n"
|
154
|
+
assert_equal res, Cgi.response_headers(ctx)
|
155
|
+
end
|
156
|
+
=begin
|
157
|
+
def test_parse_multipart
|
158
|
+
context = OpenStruct.new
|
159
|
+
context.in = File.open(File.join(File.dirname(__FILE__), 'raw_post1.bin'))
|
160
|
+
context.headers = { 'CONTENT_LENGTH' => 11963 }
|
161
|
+
boundary = '---------------------------277124474474241471962886717'
|
162
|
+
CgiUtils.parse_multipart(context, boundary)
|
163
|
+
end
|
164
|
+
=end
|
165
|
+
|
166
|
+
def test_parse_multipart
|
167
|
+
# MIME block close falls on read boundary, also contains an empty field.
|
168
|
+
boundary = "---------------------------15773515131648678014689318540"
|
169
|
+
closure = "#{Cgi::EOL}--#{boundary}--#{Cgi::EOL}"
|
170
|
+
block_size = Cgi.buffer_size
|
171
|
+
|
172
|
+
input = StringIO.new
|
173
|
+
input << "--#{boundary}#{Cgi::EOL}"
|
174
|
+
input << "Content-Disposition: form-data; name=\"test_file_a\"; filename=\"test_case.txt\"#{Cgi::EOL}Content-Type: application/octet-stream#{Cgi::EOL}#{Cgi::EOL}"
|
175
|
+
fake_file_a = String.random(block_size - input.size - (closure.size/2))
|
176
|
+
input << fake_file_a
|
177
|
+
input_after_fake_file = input.size
|
178
|
+
input << "#{Cgi::EOL}--#{boundary}#{Cgi::EOL}"
|
179
|
+
|
180
|
+
#Boundary fell inbetween two reads?
|
181
|
+
assert_equal((block_size > input_after_fake_file) && (block_size < input.size),true)
|
182
|
+
|
183
|
+
input << "Content-Disposition: form-data; name=\"test_file_b\"; filename=\"test_case.txt\"#{Cgi::EOL}Content-Type: application/octet-stream#{Cgi::EOL}#{Cgi::EOL}"
|
184
|
+
fake_file_b = Tempfile.new("TCCGI")
|
185
|
+
|
186
|
+
i = 0
|
187
|
+
file_size = 1024*1024*10 # 10MB
|
188
|
+
i += fake_file_b.write String.random(1024*10) while i < file_size
|
189
|
+
|
190
|
+
fake_file_b.rewind
|
191
|
+
input << fake_file_b.read
|
192
|
+
fake_file_b.rewind
|
193
|
+
input << "#{Cgi::EOL}--#{boundary}#{Cgi::EOL}"
|
194
|
+
|
195
|
+
input << "Content-Disposition: form-data; name=\"empty_field\"#{Cgi::EOL}#{Cgi::EOL}"
|
196
|
+
input << closure
|
197
|
+
input.rewind
|
198
|
+
start = Time.now
|
199
|
+
params = Nitro::Cgi.parse_multipart(make_context(input), boundary)
|
200
|
+
duration = Time.now - start
|
201
|
+
# puts "\nparse_multipart took: #{duration} seconds\n"
|
202
|
+
assert_equal(fake_file_a,params['test_file_a'].to_s)
|
203
|
+
assert_equal(fake_file_b.read,params['test_file_b'].to_s)
|
204
|
+
assert_equal(String.new,params['empty_field'].to_s)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def make_context(input)
|
209
|
+
context = OpenStruct.new
|
210
|
+
context.in = input
|
211
|
+
context.content_length = input.size
|
212
|
+
context.env = { 'HTTP_USER_AGENT' => 'TestCase' }
|
213
|
+
context.session = Hash.new
|
214
|
+
class << context.session
|
215
|
+
def sync
|
216
|
+
true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
context
|
220
|
+
end
|
221
|
+
end
|
222
|
+
# Tempfile.new("CGI")
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'nitro/context'
|
7
|
+
|
8
|
+
class TC_Context < Test::Unit::TestCase # :nodoc: all
|
9
|
+
include Nitro
|
10
|
+
|
11
|
+
def test_context
|
12
|
+
conf = OpenStruct.new
|
13
|
+
conf.dispatcher = nil
|
14
|
+
c = Context.new(conf)
|
15
|
+
assert_equal 200, c.status
|
16
|
+
end
|
17
|
+
end
|