aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindex.cgi43
-rw-r--r--test.rb55
2 files changed, 79 insertions, 19 deletions
diff --git a/index.cgi b/index.cgi
index 5271d87..b59cfe3 100755
--- a/index.cgi
+++ b/index.cgi
@@ -10,12 +10,8 @@ class Poll
@data = {}
@comment = []
end
- def to_html
- ret = "<div id='polltable'>\n"
- ret += "<form method='post' action=''>\n"
- ret += "<table border='1'><tr>\n"
-
- ret += "<td></td>\n"
+ def head_to_html
+ ret = "<td></td>\n"
@head.each{|columntitle|
ret += "<th>#{columntitle}</th>\n"
}
@@ -28,6 +24,14 @@ class Poll
# ret += "</div>"
# ret += "</form>\n"
# ret += "</th>\n"
+ ret
+ end
+ def to_html
+ ret = "<div id='polltable'>\n"
+ ret += "<form method='post' action=''>\n"
+ ret += "<table border='1'><tr>\n"
+
+ ret += head_to_html
@data.sort{|x,y| x[1]["timestamp"] <=> y[1]["timestamp"]}.each{|participant,poll|
ret += "</tr><tr>\n"
@@ -126,7 +130,10 @@ class Poll
store
end
def add_remove_column name
- columntitle = CGI.escapeHTML(name.strip)
+ add_remove_parsed_column CGI.escapeHTML(name.strip)
+ end
+ def add_remove_parsed_column name
+ columntitle = name
if @head.include?(columntitle)
@head.delete(columntitle)
else
@@ -136,6 +143,10 @@ class Poll
store
end
end
+class DatePoll < Poll
+end
+
+if __FILE__ == $0
#Content-type: application/xhtml+xml; charset=utf-8
puts <<HEAD
@@ -171,21 +182,13 @@ HEAD
table = Poll.new
end
- if cgi.include?("__add_participant")
- table.add_participant(cgi["__add_participant"],cgi.params["__add_participant_checked"])
- end
+ table.add_participant(cgi["__add_participant"],cgi.params["__add_participant_checked"]) if cgi.include?("__add_participant")
- if cgi.include?("__delete")
- table.delete(cgi["__delete"])
- end
+ table.delete(cgi["__delete"]) if cgi.include?("__delete")
- if cgi.include?("__add_remove_column")
- table.add_remove_column(cgi["__add_remove_column"])
- end
+ table.add_remove_column(cgi["__add_remove_column"]) if cgi.include?("__add_remove_column")
- if cgi.include?("__comment")
- table.add_comment(cgi["__commentname"],cgi.params["__comment"][0])
- end
+ table.add_comment(cgi["__commentname"],cgi.params["__comment"][0]) if cgi.include?("__comment")
puts table.to_html
@@ -252,3 +255,5 @@ HEAD
end
puts "</body></html>"
+
+end
diff --git a/test.rb b/test.rb
new file mode 100644
index 0000000..64fb0c4
--- /dev/null
+++ b/test.rb
@@ -0,0 +1,55 @@
+require 'test/unit'
+require 'yaml'
+
+load "index.cgi"
+SITE = "glvhc_8nuv_8fchi09bb12a-23_uvc"
+class Poll
+ attr_accessor :head, :data, :comment
+end
+
+class Test_dudle < Test::Unit::TestCase
+ def setup
+ @poll = StringPoll.new
+ end
+
+ def teardown
+ File.delete("#{SITE}.yaml") if File.exists?("#{SITE}.yaml")
+ end
+
+ def test_init
+ assert(@poll.head.empty?)
+ end
+ def test_add_participant
+ @poll.head << "Item 2"
+ @poll.add_participant("bla",{"Item 2" => true})
+ assert_equal(Time, @poll.data["bla"]["timestamp"].class)
+ assert(@poll.data["bla"]["Item 2"])
+ end
+ def test_delete
+ @poll.data["bla"] = {}
+ @poll.delete(" bla ")
+ assert(@poll.data.empty?)
+ end
+ def test_store
+ @poll.add_remove_column("uaie")
+ @poll.add_remove_column("gfia")
+ @poll.add_participant("bla",{"uaie"=>true, "gfia"=>true})
+ @poll.add_comment("blabla","commentblubb")
+ @poll.store
+ assert_equal(@poll.data,YAML::load_file("#{SITE}.yaml").data)
+ assert_equal(@poll.head,YAML::load_file("#{SITE}.yaml").head)
+ assert_equal(@poll.comment,YAML::load_file("#{SITE}.yaml").comment)
+ end
+ def test_add_comment
+ @poll.add_comment("blabla","commentblubb")
+ assert_equal(Time, @poll.comment[0][0].class)
+ assert_equal("blabla", @poll.comment[0][1])
+ end
+ def test_add_remove_column
+ @poll.add_remove_column(" bla ")
+ assert_equal("bla",@poll.head[0])
+ @poll.add_remove_column(" bla ")
+ assert(@poll.head.empty?)
+ end
+end
+