aboutsummaryrefslogtreecommitdiff
path: root/test.rb
blob: 64fb0c4a8cb96e7274e3d5b87aa2119c5771a19f (plain)
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
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