diff options
Diffstat (limited to '')
-rw-r--r-- | poll.rb | 38 | ||||
-rw-r--r-- | timepollhead.rb | 18 |
2 files changed, 32 insertions, 24 deletions
@@ -379,30 +379,38 @@ end class PollTest < Test::Unit::TestCase Y,N,M = Poll::YESVAL, Poll::NOVAL, Poll::MAYBEVAL A,B,C,D = "Alice", "Bob", "Carol", "Dave" - Q,W,E,R = "2009-05-05 ", "2009-05-23 10:00 ", "2009-05-23 11:00 ", "2009-05-23 foo " + Q,W,E,R = "2009-05-05", "2009-05-23 10:00", "2009-05-23 11:00", "2009-05-23 foo" def setup - def add_participant(user,votearray) + def add_participant(type,user,votearray) h = { Q => votearray[0], W => votearray[1], E => votearray[2], R => votearray[3]} - @poll.add_participant("",user,h) + @polls[type].add_participant("",user,h) end - @poll = Poll.new(SITE, "time") + @polls = {} + ["time","normal"].each{|type| + @polls[type] = Poll.new(SITE, type) - @poll.edit_column("","2009-05-05", {}) - 2.times{|t| - @poll.edit_column("","2009-05-23", {"columntime" => "#{t+10}:00"}) - } - @poll.edit_column("","2009-05-23", {"columntime" => "foo"}) + @polls[type].edit_column("","2009-05-05", {"columndescription" => ""}) + 2.times{|t| + @polls[type].edit_column("","2009-05-23 #{t+10}:00", {"columntime" => "#{t+10}:00","columndescription" => ""}) + } + @polls[type].edit_column("","2009-05-23", {"columntime" => "foo","columndescription" => ""}) - add_participant(A,[Y,N,Y,N]) - add_participant(B,[Y,Y,N,M]) - add_participant(D,[N,M,Y,Y]) - add_participant(C,[Y,Y,M,N]) + add_participant(type,A,[Y,N,Y,N]) + add_participant(type,B,[Y,Y,N,M]) + add_participant(type,D,[N,M,Y,Y]) + add_participant(type,C,[Y,Y,M,N]) + } end def test_sort - assert_equal([A,B,C,D],@poll.sort_data("name").collect{|a| a[0]}) - assert_equal([B,C,D,A],@poll.sort_data(W).collect{|a| a[0]}) + ["normal","time"].each{|type| + comment = "Test Type: #{type}" + assert_equal([A,B,C,D],@polls[type].sort_data("name").collect{|a| a[0]},comment) + assert_equal([A,B,D,C],@polls[type].sort_data("timestamp").collect{|a| a[0]},comment) + assert_equal([B,C,D,A],@polls[type].sort_data([W,"name"]).collect{|a| a[0]},comment) + assert_equal([B,A,C,D],@polls[type].sort_data([Q,R,E]).collect{|a| a[0]},comment) + } end end diff --git a/timepollhead.rb b/timepollhead.rb index 8648024..4b4d619 100644 --- a/timepollhead.rb +++ b/timepollhead.rb @@ -37,6 +37,11 @@ class TimePollHead @time = time end end + def TimeString.from_s(string) + date = string.scan(/^(\d\d\d\d-\d\d-\d\d).*$/).flatten[0] + time = string.scan(/^\d\d\d\d-\d\d-\d\d (.*)$/).flatten[0] + TimeString.new(date,time) + end def TimeString.now TimeString.new(Date.today,Time.now) end @@ -78,9 +83,6 @@ class TimePollHead def col_size @data.size end - def get_id(columntitle) - columntitle - end def get_title(columnid) columnid end @@ -116,16 +118,14 @@ class TimePollHead # returns internal representation of cgi-string def cgi_to_id(field) - date = field.scan(/^(\d\d\d\d-\d\d-\d\d).*$/).flatten[0] - time = field.scan(/^\d\d\d\d-\d\d-\d\d (.*)$/).flatten[0] - TimeString.new(date,time) + field end # returns true if deletion sucessfull def delete_column(columnid) - col = cgi_to_id(columnid) + col = TimeString.from_s(columnid) if col.time - ret = @data.delete(cgi_to_id(columnid)) != nil + ret = @data.delete(TimeString.from_s(columnid)) != nil @data << TimeString.new(col.date,nil) unless date_included?(col.date) return ret else @@ -185,7 +185,7 @@ class TimePollHead } ret += "</tr><tr><th><a href='?sort=name'>Name #{NOSORT}</a></th>" @data.sort.each{|date| - ret += "<th><a title='#{date}' href='?sort=#{CGI.escape(date.to_s)}'>#{date.time_to_s} #{NOSORT}</a></th>\n" + ret += "<th><a title='#{date}' href='?sort=#{CGI.escape(date.to_s + " ")}'>#{date.time_to_s} #{NOSORT}</a></th>\n" } ret += "<th><a href='.'>Last Edit #{NOSORT}</a></th>\n</tr>\n" ret |