1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
describe :cgi_htmlextension_popup_menu, :shared => true do
before(:each) do
@html = CGISpecs.cgi_new
end
describe "when passed no arguments" do
it "returns an empty 'select'-element without a name" do
output = @html.send(@method)
output.should equal_element("SELECT", {"NAME" => ""}, "")
end
it "ignores a passed block" do
output = @html.send(@method) { "test" }
output.should equal_element("SELECT", {"NAME" => ""}, "")
end
end
describe "when passed name, values ..." do
it "returns a 'select'-element with the passed name containing 'option'-elements based on the passed values" do
content = @html.option("VALUE" => "foo") { "foo" }
content << @html.option("VALUE" => "bar") { "bar" }
content << @html.option("VALUE" => "baz") { "baz" }
output = @html.send(@method, "test", "foo", "bar", "baz")
output.should equal_element("SELECT", {"NAME" => "test"}, content)
end
it "allows passing values inside of arrays" do
content = @html.option("VALUE" => "foo") { "foo" }
content << @html.option("VALUE" => "bar") { "bar" }
content << @html.option("VALUE" => "baz") { "baz" }
output = @html.send(@method, "test", ["foo"], ["bar"], ["baz"])
output.should equal_element("SELECT", {"NAME" => "test"}, content)
end
it "allows passing a value as an Array containing the value and the select state or a label" do
content = @html.option("VALUE" => "foo") { "foo" }
content << @html.option("VALUE" => "bar", "SELECTED" => true) { "bar" }
content << @html.option("VALUE" => "baz") { "baz" }
output = @html.send(@method, "test", ["foo"], ["bar", true], "baz")
output.should equal_element("SELECT", {"NAME" => "test"}, content)
end
it "allows passing a value as an Array containing the value, a label and the select state" do
content = @html.option("VALUE" => "1") { "Foo" }
content << @html.option("VALUE" => "2", "SELECTED" => true) { "Bar" }
content << @html.option("VALUE" => "Baz") { "Baz" }
output = @html.send(@method, "test", ["1", "Foo"], ["2", "Bar", true], "Baz")
output.should equal_element("SELECT", {"NAME" => "test"}, content)
end
it "ignores a passed block" do
content = @html.option("VALUE" => "foo") { "foo" }
content << @html.option("VALUE" => "bar") { "bar" }
content << @html.option("VALUE" => "baz") { "baz" }
output = @html.send(@method, "test", "foo", "bar", "baz") { "woot" }
output.should equal_element("SELECT", {"NAME" => "test"}, content)
end
end
describe "when passed a Hash" do
it "uses the passed Hash to generate the 'select'-element and the 'option'-elements" do
attributes = {
"NAME" => "test", "SIZE" => 2, "MULTIPLE" => true,
"VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]
}
content = @html.option("VALUE" => "1") { "Foo" }
content << @html.option("VALUE" => "2", "SELECTED" => true) { "Bar" }
content << @html.option("VALUE" => "Baz") { "Baz" }
output = @html.send(@method, attributes)
output.should equal_element("SELECT", {"NAME" => "test", "SIZE" => 2, "MULTIPLE" => true}, content)
end
it "ignores a passed block" do
attributes = {
"NAME" => "test", "SIZE" => 2, "MULTIPLE" => true,
"VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]
}
content = @html.option("VALUE" => "1") { "Foo" }
content << @html.option("VALUE" => "2", "SELECTED" => true) { "Bar" }
content << @html.option("VALUE" => "Baz") { "Baz" }
output = @html.send(@method, attributes) { "testing" }
output.should equal_element("SELECT", {"NAME" => "test", "SIZE" => 2, "MULTIPLE" => true}, content)
end
end
end
|