rubysl-cgi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +2 -0
  8. data/lib/cgi.rb +1 -0
  9. data/lib/rubysl/cgi.rb +2 -0
  10. data/lib/rubysl/cgi/cgi.rb +2333 -0
  11. data/lib/rubysl/cgi/version.rb +5 -0
  12. data/rubysl-cgi.gemspec +23 -0
  13. data/spec/cookie/domain_spec.rb +22 -0
  14. data/spec/cookie/expires_spec.rb +22 -0
  15. data/spec/cookie/initialize_spec.rb +146 -0
  16. data/spec/cookie/name_spec.rb +22 -0
  17. data/spec/cookie/parse_spec.rb +17 -0
  18. data/spec/cookie/path_spec.rb +22 -0
  19. data/spec/cookie/secure_spec.rb +69 -0
  20. data/spec/cookie/to_s_spec.rb +28 -0
  21. data/spec/cookie/value_spec.rb +79 -0
  22. data/spec/escapeElement_spec.rb +19 -0
  23. data/spec/escapeHTML_spec.rb +25 -0
  24. data/spec/escape_spec.rb +13 -0
  25. data/spec/header_spec.rb +7 -0
  26. data/spec/htmlextension/a_spec.rb +48 -0
  27. data/spec/htmlextension/base_spec.rb +32 -0
  28. data/spec/htmlextension/blockquote_spec.rb +32 -0
  29. data/spec/htmlextension/br_spec.rb +21 -0
  30. data/spec/htmlextension/caption_spec.rb +32 -0
  31. data/spec/htmlextension/checkbox_group_spec.rb +77 -0
  32. data/spec/htmlextension/checkbox_spec.rb +76 -0
  33. data/spec/htmlextension/doctype_spec.rb +26 -0
  34. data/spec/htmlextension/file_field_spec.rb +73 -0
  35. data/spec/htmlextension/fixtures/common.rb +16 -0
  36. data/spec/htmlextension/form_spec.rb +57 -0
  37. data/spec/htmlextension/frame_spec.rb +13 -0
  38. data/spec/htmlextension/frameset_spec.rb +13 -0
  39. data/spec/htmlextension/hidden_spec.rb +58 -0
  40. data/spec/htmlextension/html_spec.rb +65 -0
  41. data/spec/htmlextension/image_button_spec.rb +68 -0
  42. data/spec/htmlextension/img_spec.rb +84 -0
  43. data/spec/htmlextension/multipart_form_spec.rb +63 -0
  44. data/spec/htmlextension/password_field_spec.rb +83 -0
  45. data/spec/htmlextension/popup_menu_spec.rb +7 -0
  46. data/spec/htmlextension/radio_button_spec.rb +76 -0
  47. data/spec/htmlextension/radio_group_spec.rb +78 -0
  48. data/spec/htmlextension/reset_spec.rb +56 -0
  49. data/spec/htmlextension/scrolling_list_spec.rb +7 -0
  50. data/spec/htmlextension/shared/popup_menu.rb +94 -0
  51. data/spec/htmlextension/submit_spec.rb +56 -0
  52. data/spec/htmlextension/text_field_spec.rb +83 -0
  53. data/spec/htmlextension/textarea_spec.rb +72 -0
  54. data/spec/http_header_spec.rb +9 -0
  55. data/spec/initialize_spec.rb +171 -0
  56. data/spec/out_spec.rb +50 -0
  57. data/spec/parse_spec.rb +23 -0
  58. data/spec/pretty_spec.rb +23 -0
  59. data/spec/print_spec.rb +25 -0
  60. data/spec/queryextension/accept_charset_spec.rb +21 -0
  61. data/spec/queryextension/accept_encoding_spec.rb +21 -0
  62. data/spec/queryextension/accept_language_spec.rb +21 -0
  63. data/spec/queryextension/accept_spec.rb +21 -0
  64. data/spec/queryextension/auth_type_spec.rb +21 -0
  65. data/spec/queryextension/cache_control_spec.rb +21 -0
  66. data/spec/queryextension/content_length_spec.rb +25 -0
  67. data/spec/queryextension/content_type_spec.rb +21 -0
  68. data/spec/queryextension/cookies_spec.rb +9 -0
  69. data/spec/queryextension/element_reference_spec.rb +33 -0
  70. data/spec/queryextension/from_spec.rb +21 -0
  71. data/spec/queryextension/gateway_interface_spec.rb +21 -0
  72. data/spec/queryextension/has_key_spec.rb +6 -0
  73. data/spec/queryextension/host_spec.rb +21 -0
  74. data/spec/queryextension/include_spec.rb +6 -0
  75. data/spec/queryextension/key_spec.rb +6 -0
  76. data/spec/queryextension/keys_spec.rb +19 -0
  77. data/spec/queryextension/multipart_spec.rb +39 -0
  78. data/spec/queryextension/negotiate_spec.rb +21 -0
  79. data/spec/queryextension/params_spec.rb +44 -0
  80. data/spec/queryextension/path_info_spec.rb +21 -0
  81. data/spec/queryextension/path_translated_spec.rb +21 -0
  82. data/spec/queryextension/pragma_spec.rb +21 -0
  83. data/spec/queryextension/query_string_spec.rb +21 -0
  84. data/spec/queryextension/raw_cookie2_spec.rb +21 -0
  85. data/spec/queryextension/raw_cookie_spec.rb +21 -0
  86. data/spec/queryextension/referer_spec.rb +21 -0
  87. data/spec/queryextension/remote_addr_spec.rb +21 -0
  88. data/spec/queryextension/remote_host_spec.rb +21 -0
  89. data/spec/queryextension/remote_ident_spec.rb +21 -0
  90. data/spec/queryextension/remote_user_spec.rb +21 -0
  91. data/spec/queryextension/request_method_spec.rb +21 -0
  92. data/spec/queryextension/script_name_spec.rb +21 -0
  93. data/spec/queryextension/server_name_spec.rb +21 -0
  94. data/spec/queryextension/server_port_spec.rb +25 -0
  95. data/spec/queryextension/server_protocol_spec.rb +21 -0
  96. data/spec/queryextension/server_software_spec.rb +21 -0
  97. data/spec/queryextension/shared/has_key.rb +19 -0
  98. data/spec/queryextension/user_agent_spec.rb +21 -0
  99. data/spec/rfc1123_date_spec.rb +9 -0
  100. data/spec/shared/http_header.rb +111 -0
  101. data/spec/unescapeElement_spec.rb +19 -0
  102. data/spec/unescapeHTML_spec.rb +33 -0
  103. data/spec/unescape_spec.rb +14 -0
  104. metadata +293 -0
@@ -0,0 +1,83 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#password_field" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns an password-'input'-element without a name" do
11
+ output = @html.password_field
12
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.password_field { "test" }
17
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed name" do
22
+ it "returns an password-'input'-element with the passed name" do
23
+ output = @html.password_field("test")
24
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.password_field("test") { "test" }
29
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed name, value" do
34
+ it "returns an password-'input'-element with the passed name and value" do
35
+ output = @html.password_field("test", "some value")
36
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.password_field("test", "some value") { "test" }
41
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed name, value, size" do
46
+ it "returns an password-'input'-element with the passed name, value and size" do
47
+ output = @html.password_field("test", "some value", 60)
48
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", :not_closed => true)
49
+ end
50
+
51
+ it "ignores a passed block" do
52
+ output = @html.password_field("test", "some value", 60) { "test" }
53
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", :not_closed => true)
54
+ end
55
+ end
56
+
57
+ describe "when passed name, value, size, maxlength" do
58
+ it "returns an password-'input'-element with the passed name, value, size and maxlength" do
59
+ output = @html.password_field("test", "some value", 60, 12)
60
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", :not_closed => true)
61
+ end
62
+
63
+ it "ignores a passed block" do
64
+ output = @html.password_field("test", "some value", 60, 12) { "test" }
65
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", :not_closed => true)
66
+ end
67
+ end
68
+
69
+ describe "when passed Hash" do
70
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
71
+ output = @html.password_field("NAME" => "test", "VALUE" => "some value")
72
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", :not_closed => true)
73
+
74
+ output = @html.password_field("TYPE" => "hidden")
75
+ output.should equal_element("INPUT", {"TYPE" => "password"}, "", :not_closed => true)
76
+ end
77
+
78
+ it "ignores a passed block" do
79
+ output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" }
80
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", :not_closed => true)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+ require File.expand_path('../shared/popup_menu', __FILE__)
4
+
5
+ describe "CGI::HtmlExtension#popup_menu" do
6
+ it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu
7
+ end
@@ -0,0 +1,76 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#radio_button" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns a radio-'input'-element without a name" do
11
+ output = @html.radio_button
12
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.radio_button { "test" }
17
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed name" do
22
+ it "returns a radio-'input'-element with the passed name" do
23
+ output = @html.radio_button("test")
24
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.radio_button("test") { "test" }
29
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "CGI::HtmlExtension#checkbox when passed name, value" do
34
+ it "returns a radio-'input'-element with the passed name and value" do
35
+ output = @html.radio_button("test", "test-value")
36
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.radio_button("test", "test-value") { "test" }
41
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed name, value, checked" do
46
+ it "returns a checked radio-'input'-element with the passed name and value when checked is true" do
47
+ output = @html.radio_button("test", "test-value", true)
48
+ output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", :not_closed => true)
49
+
50
+ output = @html.radio_button("test", "test-value", false)
51
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", :not_closed => true)
52
+
53
+ output = @html.radio_button("test", "test-value", nil)
54
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", :not_closed => true)
55
+ end
56
+
57
+ it "ignores a passed block" do
58
+ output = @html.radio_button("test", "test-value", nil) { "test" }
59
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", :not_closed => true)
60
+ end
61
+ end
62
+
63
+ describe "when passed Hash" do
64
+ it "returns a radio-'input'-element using the passed Hash for attributes" do
65
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
66
+ output = @html.radio_button(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.radio_button(attributes) { "test" }
73
+ output.should equal_element("INPUT", attributes, "", :not_closed => true)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,78 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#radio_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 'radio'-elements with the passed name and the passed values" do
11
+ output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz"))
12
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
13
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
14
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", :not_closed => true)
15
+ end
16
+
17
+ it "allows passing a value inside an Array" do
18
+ output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"]))
19
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
20
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
21
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "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.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
26
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
27
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
28
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", :not_closed => true)
29
+ end
30
+
31
+ # TODO: CGI does not like passing false instead of true.
32
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/444", "1.8.7" do
33
+ it "allows passing a value as an Array containing the value, a label and the checked state" do
34
+ output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
35
+ output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", :not_closed => true)
36
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", :not_closed => true)
37
+ output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", :not_closed => true)
38
+ end
39
+ end
40
+
41
+ it "returns an empty String when passed no values" do
42
+ @html.radio_group("test").should == ""
43
+ end
44
+
45
+ it "ignores a passed block" do
46
+ output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" })
47
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
48
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
49
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", :not_closed => true)
50
+ end
51
+ end
52
+
53
+ describe "when passed Hash" do
54
+ it "uses the passed Hash to generate the radio sequence" do
55
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
56
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
57
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
58
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", :not_closed => true)
59
+
60
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
61
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
62
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
63
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", :not_closed => true)
64
+
65
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
66
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", :not_closed => true)
67
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", :not_closed => true)
68
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", :not_closed => true)
69
+ end
70
+
71
+ it "ignores a passed block" do
72
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
73
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", :not_closed => true)
74
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", :not_closed => true)
75
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", :not_closed => true)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,56 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#reset" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns a reset-'input'-element" do
11
+ output = @html.reset
12
+ output.should equal_element("INPUT", {"TYPE" => "reset"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.reset { "test" }
17
+ output.should equal_element("INPUT", {"TYPE" => "reset"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed value" do
22
+ it "returns a reset-'input'-element with the passed value" do
23
+ output = @html.reset("Example")
24
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.reset("Example") { "test" }
29
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed value, name" do
34
+ it "returns a reset-'input'-element with the passed value and the passed name" do
35
+ output = @html.reset("Example", "test-name")
36
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.reset("Example", "test-name") { "test" }
41
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed Hash" do
46
+ it "returns a reset-'input'-element with the passed value" do
47
+ output = @html.reset("Example")
48
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", :not_closed => true)
49
+ end
50
+
51
+ it "ignores a passed block" do
52
+ output = @html.reset("Example") { "test" }
53
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", :not_closed => true)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../fixtures/common', __FILE__)
2
+ require 'cgi'
3
+ require File.expand_path('../shared/popup_menu', __FILE__)
4
+
5
+ describe "CGI::HtmlExtension#scrolling_list" do
6
+ it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list
7
+ end
@@ -0,0 +1,94 @@
1
+ describe :cgi_htmlextension_popup_menu, :shared => true do
2
+ before(:each) do
3
+ @html = CGISpecs.cgi_new
4
+ end
5
+
6
+ describe "when passed no arguments" do
7
+ it "returns an empty 'select'-element without a name" do
8
+ output = @html.send(@method)
9
+ output.should equal_element("SELECT", {"NAME" => ""}, "")
10
+ end
11
+
12
+ it "ignores a passed block" do
13
+ output = @html.send(@method) { "test" }
14
+ output.should equal_element("SELECT", {"NAME" => ""}, "")
15
+ end
16
+ end
17
+
18
+ describe "when passed name, values ..." do
19
+ it "returns a 'select'-element with the passed name containing 'option'-elements based on the passed values" do
20
+ content = @html.option("VALUE" => "foo") { "foo" }
21
+ content << @html.option("VALUE" => "bar") { "bar" }
22
+ content << @html.option("VALUE" => "baz") { "baz" }
23
+
24
+ output = @html.send(@method, "test", "foo", "bar", "baz")
25
+ output.should equal_element("SELECT", {"NAME" => "test"}, content)
26
+ end
27
+
28
+ it "allows passing values inside of arrays" do
29
+ content = @html.option("VALUE" => "foo") { "foo" }
30
+ content << @html.option("VALUE" => "bar") { "bar" }
31
+ content << @html.option("VALUE" => "baz") { "baz" }
32
+
33
+ output = @html.send(@method, "test", ["foo"], ["bar"], ["baz"])
34
+ output.should equal_element("SELECT", {"NAME" => "test"}, content)
35
+ end
36
+
37
+ it "allows passing a value as an Array containing the value and the select state or a label" do
38
+ content = @html.option("VALUE" => "foo") { "foo" }
39
+ content << @html.option("VALUE" => "bar", "SELECTED" => true) { "bar" }
40
+ content << @html.option("VALUE" => "baz") { "baz" }
41
+
42
+ output = @html.send(@method, "test", ["foo"], ["bar", true], "baz")
43
+ output.should equal_element("SELECT", {"NAME" => "test"}, content)
44
+ end
45
+
46
+ it "allows passing a value as an Array containing the value, a label and the select state" do
47
+ content = @html.option("VALUE" => "1") { "Foo" }
48
+ content << @html.option("VALUE" => "2", "SELECTED" => true) { "Bar" }
49
+ content << @html.option("VALUE" => "Baz") { "Baz" }
50
+
51
+ output = @html.send(@method, "test", ["1", "Foo"], ["2", "Bar", true], "Baz")
52
+ output.should equal_element("SELECT", {"NAME" => "test"}, content)
53
+ end
54
+
55
+ it "ignores a passed block" do
56
+ content = @html.option("VALUE" => "foo") { "foo" }
57
+ content << @html.option("VALUE" => "bar") { "bar" }
58
+ content << @html.option("VALUE" => "baz") { "baz" }
59
+
60
+ output = @html.send(@method, "test", "foo", "bar", "baz") { "woot" }
61
+ output.should equal_element("SELECT", {"NAME" => "test"}, content)
62
+ end
63
+ end
64
+
65
+ describe "when passed a Hash" do
66
+ it "uses the passed Hash to generate the 'select'-element and the 'option'-elements" do
67
+ attributes = {
68
+ "NAME" => "test", "SIZE" => 2, "MULTIPLE" => true,
69
+ "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]
70
+ }
71
+
72
+ content = @html.option("VALUE" => "1") { "Foo" }
73
+ content << @html.option("VALUE" => "2", "SELECTED" => true) { "Bar" }
74
+ content << @html.option("VALUE" => "Baz") { "Baz" }
75
+
76
+ output = @html.send(@method, attributes)
77
+ output.should equal_element("SELECT", {"NAME" => "test", "SIZE" => 2, "MULTIPLE" => true}, content)
78
+ end
79
+
80
+ it "ignores a passed block" do
81
+ attributes = {
82
+ "NAME" => "test", "SIZE" => 2, "MULTIPLE" => true,
83
+ "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]
84
+ }
85
+
86
+ content = @html.option("VALUE" => "1") { "Foo" }
87
+ content << @html.option("VALUE" => "2", "SELECTED" => true) { "Bar" }
88
+ content << @html.option("VALUE" => "Baz") { "Baz" }
89
+
90
+ output = @html.send(@method, attributes) { "testing" }
91
+ output.should equal_element("SELECT", {"NAME" => "test", "SIZE" => 2, "MULTIPLE" => true}, content)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,56 @@
1
+ require 'cgi'
2
+ require File.expand_path('../fixtures/common', __FILE__)
3
+
4
+ describe "CGI::HtmlExtension#submit" do
5
+ before(:each) do
6
+ @html = CGISpecs.cgi_new
7
+ end
8
+
9
+ describe "when passed no arguments" do
10
+ it "returns a submit-'input'-element" do
11
+ output = @html.submit
12
+ output.should equal_element("INPUT", {"TYPE" => "submit"}, "", :not_closed => true)
13
+ end
14
+
15
+ it "ignores a passed block" do
16
+ output = @html.submit { "test" }
17
+ output.should equal_element("INPUT", {"TYPE" => "submit"}, "", :not_closed => true)
18
+ end
19
+ end
20
+
21
+ describe "when passed value" do
22
+ it "returns a submit-'input'-element with the passed value" do
23
+ output = @html.submit("Example")
24
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", :not_closed => true)
25
+ end
26
+
27
+ it "ignores a passed block" do
28
+ output = @html.submit("Example") { "test" }
29
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", :not_closed => true)
30
+ end
31
+ end
32
+
33
+ describe "when passed value, name" do
34
+ it "returns a submit-'input'-element with the passed value and the passed name" do
35
+ output = @html.submit("Example", "test-name")
36
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", :not_closed => true)
37
+ end
38
+
39
+ it "ignores a passed block" do
40
+ output = @html.submit("Example", "test-name") { "test" }
41
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", :not_closed => true)
42
+ end
43
+ end
44
+
45
+ describe "when passed Hash" do
46
+ it "returns a submit-'input'-element with the passed value" do
47
+ output = @html.submit("Example")
48
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", :not_closed => true)
49
+ end
50
+
51
+ it "ignores a passed block" do
52
+ output = @html.submit("Example") { "test" }
53
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", :not_closed => true)
54
+ end
55
+ end
56
+ end