rubysl-cgi 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/cgi.rb +1 -0
- data/lib/rubysl/cgi.rb +2 -0
- data/lib/rubysl/cgi/cgi.rb +2333 -0
- data/lib/rubysl/cgi/version.rb +5 -0
- data/rubysl-cgi.gemspec +23 -0
- data/spec/cookie/domain_spec.rb +22 -0
- data/spec/cookie/expires_spec.rb +22 -0
- data/spec/cookie/initialize_spec.rb +146 -0
- data/spec/cookie/name_spec.rb +22 -0
- data/spec/cookie/parse_spec.rb +17 -0
- data/spec/cookie/path_spec.rb +22 -0
- data/spec/cookie/secure_spec.rb +69 -0
- data/spec/cookie/to_s_spec.rb +28 -0
- data/spec/cookie/value_spec.rb +79 -0
- data/spec/escapeElement_spec.rb +19 -0
- data/spec/escapeHTML_spec.rb +25 -0
- data/spec/escape_spec.rb +13 -0
- data/spec/header_spec.rb +7 -0
- data/spec/htmlextension/a_spec.rb +48 -0
- data/spec/htmlextension/base_spec.rb +32 -0
- data/spec/htmlextension/blockquote_spec.rb +32 -0
- data/spec/htmlextension/br_spec.rb +21 -0
- data/spec/htmlextension/caption_spec.rb +32 -0
- data/spec/htmlextension/checkbox_group_spec.rb +77 -0
- data/spec/htmlextension/checkbox_spec.rb +76 -0
- data/spec/htmlextension/doctype_spec.rb +26 -0
- data/spec/htmlextension/file_field_spec.rb +73 -0
- data/spec/htmlextension/fixtures/common.rb +16 -0
- data/spec/htmlextension/form_spec.rb +57 -0
- data/spec/htmlextension/frame_spec.rb +13 -0
- data/spec/htmlextension/frameset_spec.rb +13 -0
- data/spec/htmlextension/hidden_spec.rb +58 -0
- data/spec/htmlextension/html_spec.rb +65 -0
- data/spec/htmlextension/image_button_spec.rb +68 -0
- data/spec/htmlextension/img_spec.rb +84 -0
- data/spec/htmlextension/multipart_form_spec.rb +63 -0
- data/spec/htmlextension/password_field_spec.rb +83 -0
- data/spec/htmlextension/popup_menu_spec.rb +7 -0
- data/spec/htmlextension/radio_button_spec.rb +76 -0
- data/spec/htmlextension/radio_group_spec.rb +78 -0
- data/spec/htmlextension/reset_spec.rb +56 -0
- data/spec/htmlextension/scrolling_list_spec.rb +7 -0
- data/spec/htmlextension/shared/popup_menu.rb +94 -0
- data/spec/htmlextension/submit_spec.rb +56 -0
- data/spec/htmlextension/text_field_spec.rb +83 -0
- data/spec/htmlextension/textarea_spec.rb +72 -0
- data/spec/http_header_spec.rb +9 -0
- data/spec/initialize_spec.rb +171 -0
- data/spec/out_spec.rb +50 -0
- data/spec/parse_spec.rb +23 -0
- data/spec/pretty_spec.rb +23 -0
- data/spec/print_spec.rb +25 -0
- data/spec/queryextension/accept_charset_spec.rb +21 -0
- data/spec/queryextension/accept_encoding_spec.rb +21 -0
- data/spec/queryextension/accept_language_spec.rb +21 -0
- data/spec/queryextension/accept_spec.rb +21 -0
- data/spec/queryextension/auth_type_spec.rb +21 -0
- data/spec/queryextension/cache_control_spec.rb +21 -0
- data/spec/queryextension/content_length_spec.rb +25 -0
- data/spec/queryextension/content_type_spec.rb +21 -0
- data/spec/queryextension/cookies_spec.rb +9 -0
- data/spec/queryextension/element_reference_spec.rb +33 -0
- data/spec/queryextension/from_spec.rb +21 -0
- data/spec/queryextension/gateway_interface_spec.rb +21 -0
- data/spec/queryextension/has_key_spec.rb +6 -0
- data/spec/queryextension/host_spec.rb +21 -0
- data/spec/queryextension/include_spec.rb +6 -0
- data/spec/queryextension/key_spec.rb +6 -0
- data/spec/queryextension/keys_spec.rb +19 -0
- data/spec/queryextension/multipart_spec.rb +39 -0
- data/spec/queryextension/negotiate_spec.rb +21 -0
- data/spec/queryextension/params_spec.rb +44 -0
- data/spec/queryextension/path_info_spec.rb +21 -0
- data/spec/queryextension/path_translated_spec.rb +21 -0
- data/spec/queryextension/pragma_spec.rb +21 -0
- data/spec/queryextension/query_string_spec.rb +21 -0
- data/spec/queryextension/raw_cookie2_spec.rb +21 -0
- data/spec/queryextension/raw_cookie_spec.rb +21 -0
- data/spec/queryextension/referer_spec.rb +21 -0
- data/spec/queryextension/remote_addr_spec.rb +21 -0
- data/spec/queryextension/remote_host_spec.rb +21 -0
- data/spec/queryextension/remote_ident_spec.rb +21 -0
- data/spec/queryextension/remote_user_spec.rb +21 -0
- data/spec/queryextension/request_method_spec.rb +21 -0
- data/spec/queryextension/script_name_spec.rb +21 -0
- data/spec/queryextension/server_name_spec.rb +21 -0
- data/spec/queryextension/server_port_spec.rb +25 -0
- data/spec/queryextension/server_protocol_spec.rb +21 -0
- data/spec/queryextension/server_software_spec.rb +21 -0
- data/spec/queryextension/shared/has_key.rb +19 -0
- data/spec/queryextension/user_agent_spec.rb +21 -0
- data/spec/rfc1123_date_spec.rb +9 -0
- data/spec/shared/http_header.rb +111 -0
- data/spec/unescapeElement_spec.rb +19 -0
- data/spec/unescapeHTML_spec.rb +33 -0
- data/spec/unescape_spec.rb +14 -0
- metadata +293 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI.escapeElement when passed String, elements, ..." do
|
4
|
+
it "escapes only the tags of the passed elements in the passed String" do
|
5
|
+
res = CGI.escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
|
6
|
+
res.should == "<BR><A HREF="url"></A>"
|
7
|
+
|
8
|
+
res = CGI.escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
9
|
+
res.should == "<BR><A HREF="url"></A>"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "is case-insensitive" do
|
13
|
+
res = CGI.escapeElement('<BR><A HREF="url"></A>', "a", "img")
|
14
|
+
res.should == '<BR><A HREF="url"></A>'
|
15
|
+
|
16
|
+
res = CGI.escapeElement('<br><a href="url"></a>', "A", "IMG")
|
17
|
+
res.should == '<br><a href="url"></a>'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI.escapeHTML" do
|
4
|
+
ruby_version_is ""..."2.0" do
|
5
|
+
it "escapes special HTML characters (&\"<>) in the passed argument" do
|
6
|
+
CGI.escapeHTML('& < > "').should == '& < > "'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "does not escape any other characters" do
|
10
|
+
chars = " !\#$%'()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
11
|
+
CGI.escapeHTML(chars).should == chars
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ruby_version_is "2.0" do
|
16
|
+
it "escapes special HTML characters (&\"<>') in the passed argument" do
|
17
|
+
CGI.escapeHTML(%[& < > " ']).should == '& < > " ''
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not escape any other characters" do
|
21
|
+
chars = " !\#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
22
|
+
CGI.escapeHTML(chars).should == chars
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/escape_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI.escape" do
|
4
|
+
it "url-encodes the passed argument" do
|
5
|
+
input = " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
6
|
+
expected = "+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
|
7
|
+
CGI.escape(input).should == expected
|
8
|
+
|
9
|
+
input = "http://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
|
10
|
+
expected = 'http%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
|
11
|
+
CGI.escape(input).should == expected
|
12
|
+
end
|
13
|
+
end
|
data/spec/header_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#a" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when passed a String" do
|
10
|
+
it "returns an 'a'-element, using the passed String as the 'href'-attribute" do
|
11
|
+
output = @html.a("http://www.example.com")
|
12
|
+
output.should equal_element("A", "HREF" => "http://www.example.com")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "includes the passed block's return value when passed a block" do
|
16
|
+
output = @html.a("http://www.example.com") { "Example" }
|
17
|
+
output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed a Hash" do
|
22
|
+
it "returns an 'a'-element, using the passed Hash for attributes" do
|
23
|
+
attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
|
24
|
+
@html.a(attributes).should equal_element("A", attributes)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "includes the passed block's return value when passed a block" do
|
28
|
+
attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
|
29
|
+
@html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when each HTML generation" do
|
34
|
+
it "returns the doctype declaration for HTML3" do
|
35
|
+
CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>)
|
36
|
+
CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the doctype declaration for HTML4" do
|
40
|
+
CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>)
|
41
|
+
CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>)
|
42
|
+
end
|
43
|
+
it "returns the doctype declaration for the Transitional version of HTML4" do
|
44
|
+
CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>)
|
45
|
+
CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#base" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when bassed a String" do
|
10
|
+
it "returns a 'base'-element, using the passed String as the 'href'-attribute" do
|
11
|
+
output = @html.base("http://www.example.com")
|
12
|
+
output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, :not_closed => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "ignores a passed block" do
|
16
|
+
output = @html.base("http://www.example.com") { "Example" }
|
17
|
+
output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, :not_closed => true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed a Hash" do
|
22
|
+
it "returns a 'base'-element, using the passed Hash for attributes" do
|
23
|
+
output = @html.base("HREF" => "http://www.example.com", "ID" => "test")
|
24
|
+
output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, :not_closed => true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ignores a passed block" do
|
28
|
+
output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" }
|
29
|
+
output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, :not_closed => true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#blockquote" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when passed a String" do
|
10
|
+
it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do
|
11
|
+
output = @html.blockquote("http://www.example.com/quotes/foo.html")
|
12
|
+
output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "includes the passed block's return value when passed a block" do
|
16
|
+
output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
|
17
|
+
output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed a Hash" do
|
22
|
+
it "returns a 'blockquote'-element, using the passed Hash for attributes" do
|
23
|
+
output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
|
24
|
+
output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "includes the passed block's return value when passed a block" do
|
28
|
+
output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" }
|
29
|
+
output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#br" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when each HTML generation" do
|
10
|
+
it "returns the doctype declaration for HTML3" do
|
11
|
+
CGISpecs.cgi_new("html3").br.should == "<BR>"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the doctype declaration for HTML4" do
|
15
|
+
CGISpecs.cgi_new("html4").br.should == "<BR>"
|
16
|
+
end
|
17
|
+
it "returns the doctype declaration for the Transitional version of HTML4" do
|
18
|
+
CGISpecs.cgi_new("html4Tr").br.should == "<BR>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#caption" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when passed a String" do
|
10
|
+
it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do
|
11
|
+
output = @html.caption("left")
|
12
|
+
output.should equal_element("CAPTION", "ALIGN" => "left")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "includes the passed block's return value when passed a block" do
|
16
|
+
output = @html.caption("left") { "Capital Cities" }
|
17
|
+
output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed a Hash" do
|
22
|
+
it "returns a 'caption'-element, using the passed Hash for attributes" do
|
23
|
+
output = @html.caption("ALIGN" => "left", "ID" => "test")
|
24
|
+
output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "includes the passed block's return value when passed a block" do
|
28
|
+
output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" }
|
29
|
+
output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#checkbox_group" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when passed name, values ..." do
|
10
|
+
it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do
|
11
|
+
output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz"))
|
12
|
+
output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
13
|
+
output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
14
|
+
output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", :not_closed => true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows passing a value inside an Array" do
|
18
|
+
output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"]))
|
19
|
+
output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
20
|
+
output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
21
|
+
output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", :not_closed => true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "allows passing a value as an Array containing the value and the checked state or a label" do
|
25
|
+
output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
|
26
|
+
output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
27
|
+
output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
28
|
+
output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", :not_closed => true)
|
29
|
+
end
|
30
|
+
|
31
|
+
ruby_bug "http://redmine.ruby-lang.org/issues/show/443", "1.8.7" do
|
32
|
+
it "allows passing a value as an Array containing the value, a label and the checked state" do
|
33
|
+
output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
|
34
|
+
output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", :not_closed => true)
|
35
|
+
output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", :not_closed => true)
|
36
|
+
output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", :not_closed => true)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns an empty String when passed no values" do
|
41
|
+
@html.checkbox_group("test").should == ""
|
42
|
+
end
|
43
|
+
|
44
|
+
it "ignores a passed block" do
|
45
|
+
output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" })
|
46
|
+
output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
47
|
+
output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
48
|
+
output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", :not_closed => true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when passed Hash" do
|
53
|
+
it "uses the passed Hash to generate the checkbox sequence" do
|
54
|
+
output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
|
55
|
+
output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
56
|
+
output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
57
|
+
output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", :not_closed => true)
|
58
|
+
|
59
|
+
output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
|
60
|
+
output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
61
|
+
output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
62
|
+
output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", :not_closed => true)
|
63
|
+
|
64
|
+
output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
|
65
|
+
output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", :not_closed => true)
|
66
|
+
output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", :not_closed => true)
|
67
|
+
output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", :not_closed => true)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "ignores a passed block" do
|
71
|
+
output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
|
72
|
+
output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", :not_closed => true)
|
73
|
+
output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", :not_closed => true)
|
74
|
+
output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", :not_closed => true)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#checkbox" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when passed no arguments" do
|
10
|
+
it "returns a checkbox-'input'-element without a name" do
|
11
|
+
output = @html.checkbox
|
12
|
+
output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", :not_closed => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "ignores a passed block" do
|
16
|
+
output = @html.checkbox { "test" }
|
17
|
+
output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", :not_closed => true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed name" do
|
22
|
+
it "returns a checkbox-'input'-element with the passed name" do
|
23
|
+
output = @html.checkbox("test")
|
24
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", :not_closed => true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ignores a passed block" do
|
28
|
+
output = @html.checkbox("test") { "test" }
|
29
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", :not_closed => true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "CGI::HtmlExtension#checkbox when passed name, value" do
|
34
|
+
it "returns a checkbox-'input'-element with the passed name and value" do
|
35
|
+
output = @html.checkbox("test", "test-value")
|
36
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", :not_closed => true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "ignores a passed block" do
|
40
|
+
output = @html.checkbox("test", "test-value") { "test" }
|
41
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", :not_closed => true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when passed name, value, checked" do
|
46
|
+
it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do
|
47
|
+
output = @html.checkbox("test", "test-value", true)
|
48
|
+
output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", :not_closed => true)
|
49
|
+
|
50
|
+
output = @html.checkbox("test", "test-value", false)
|
51
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", :not_closed => true)
|
52
|
+
|
53
|
+
output = @html.checkbox("test", "test-value", nil)
|
54
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", :not_closed => true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "ignores a passed block" do
|
58
|
+
output = @html.checkbox("test", "test-value", nil) { "test" }
|
59
|
+
output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", :not_closed => true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when passed Hash" do
|
64
|
+
it "returns a checkbox-'input'-element using the passed Hash for attributes" do
|
65
|
+
attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
|
66
|
+
output = @html.checkbox(attributes)
|
67
|
+
output.should equal_element("INPUT", attributes, "", :not_closed => true)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "ignores a passed block" do
|
71
|
+
attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
|
72
|
+
output = @html.checkbox(attributes) { "test" }
|
73
|
+
output.should equal_element("INPUT", attributes, "", :not_closed => true)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#doctype" do
|
5
|
+
describe "when each HTML generation" do
|
6
|
+
it "returns the doctype declaration for HTML3" do
|
7
|
+
expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
|
8
|
+
CGISpecs.cgi_new("html3").doctype.should == expect
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the doctype declaration for HTML4" do
|
12
|
+
expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
|
13
|
+
CGISpecs.cgi_new("html4").doctype.should == expect
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the doctype declaration for the Frameset version of HTML4" do
|
17
|
+
expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
|
18
|
+
CGISpecs.cgi_new("html4Fr").doctype.should == expect
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the doctype declaration for the Transitional version of HTML4" do
|
22
|
+
expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
|
23
|
+
CGISpecs.cgi_new("html4Tr").doctype.should == expect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
3
|
+
|
4
|
+
describe "CGI::HtmlExtension#file_field" do
|
5
|
+
before(:each) do
|
6
|
+
@html = CGISpecs.cgi_new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when passed no arguments" do
|
10
|
+
it "returns a file-'input'-element without a name and a size of 20" do
|
11
|
+
output = @html.file_field
|
12
|
+
output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", :not_closed => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "ignores a passed block" do
|
16
|
+
output = @html.file_field { "test" }
|
17
|
+
output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", :not_closed => true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed name" do
|
22
|
+
it "returns a checkbox-'input'-element with the passed name" do
|
23
|
+
output = @html.file_field("Example")
|
24
|
+
output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", :not_closed => true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "ignores a passed block" do
|
28
|
+
output = @html.file_field("Example") { "test" }
|
29
|
+
output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", :not_closed => true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when passed name, size" do
|
34
|
+
it "returns a checkbox-'input'-element with the passed name and size" do
|
35
|
+
output = @html.file_field("Example", 40)
|
36
|
+
output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", :not_closed => true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "ignores a passed block" do
|
40
|
+
output = @html.file_field("Example", 40) { "test" }
|
41
|
+
output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", :not_closed => true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when passed name, size, maxlength" do
|
46
|
+
it "returns a checkbox-'input'-element with the passed name, size and maxlength" do
|
47
|
+
output = @html.file_field("Example", 40, 100)
|
48
|
+
output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", :not_closed => true)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "ignores a passed block" do
|
52
|
+
output = @html.file_field("Example", 40, 100) { "test" }
|
53
|
+
output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", :not_closed => true)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "when passed a Hash" do
|
58
|
+
ruby_bug "http://redmine.ruby-lang.org/issues/show/255", "1.8.7" do
|
59
|
+
it "returns a file-'input'-element using the passed Hash for attributes" do
|
60
|
+
output = @html.file_field("NAME" => "test", "SIZE" => 40)
|
61
|
+
output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", :not_closed => true)
|
62
|
+
|
63
|
+
output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100)
|
64
|
+
output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", :not_closed => true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "ignores a passed block" do
|
68
|
+
output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" }
|
69
|
+
output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", :not_closed => true)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|