resque-status 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,153 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestResqueStatus < Test::Unit::TestCase
4
-
5
- context "Resque::Status" do
6
- setup do
7
- Resque.redis.flushall
8
- Resque::Status.expire_in = nil
9
- @uuid = Resque::Status.create
10
- Resque::Status.set(@uuid, "my status")
11
- @uuid_with_json = Resque::Status.create({"im" => "json"})
12
- end
13
-
14
- context ".get" do
15
- should "return the status as a Resque::Status for the uuid" do
16
- status = Resque::Status.get(@uuid)
17
- assert status.is_a?(Resque::Status)
18
- assert_equal 'my status', status.message
19
- end
20
-
21
- should "return false if the status is not set" do
22
- assert !Resque::Status.get('whu')
23
- end
24
-
25
- should "decode encoded json" do
26
- assert_equal("json", Resque::Status.get(@uuid_with_json)['im'])
27
- end
28
- end
29
-
30
- context ".set" do
31
-
32
- should "set the status for the uuid" do
33
- assert Resque::Status.set(@uuid, "updated")
34
- assert_equal "updated", Resque::Status.get(@uuid).message
35
- end
36
-
37
- should "return the status" do
38
- assert Resque::Status.set(@uuid, "updated").is_a?(Resque::Status)
39
- end
40
-
41
- end
42
-
43
- context ".create" do
44
- should "add an item to a key set" do
45
- before = Resque::Status.status_ids.length
46
- Resque::Status.create
47
- after = Resque::Status.status_ids.length
48
- assert_equal 1, after - before
49
- end
50
-
51
- should "return a uuid" do
52
- assert_match(/^\w{32}$/, Resque::Status.create)
53
- end
54
-
55
- should "store any status passed" do
56
- uuid = Resque::Status.create("initial status")
57
- status = Resque::Status.get(uuid)
58
- assert status.is_a?(Resque::Status)
59
- assert_equal "initial status", status.message
60
- end
61
-
62
- should "expire keys if expire_in is set" do
63
- Resque::Status.expire_in = 1
64
- uuid = Resque::Status.create("new status")
65
- assert_contains Resque::Status.status_ids, uuid
66
- assert_equal "new status", Resque::Status.get(uuid).message
67
- sleep 2
68
- Resque::Status.create
69
- assert_does_not_contain Resque::Status.status_ids, uuid
70
- assert_nil Resque::Status.get(uuid)
71
- end
72
-
73
- should "store the options for the job created" do
74
- uuid = Resque::Status.create("new", :options => {'test' => '123'})
75
- assert uuid
76
- status = Resque::Status.get(uuid)
77
- assert status.is_a?(Resque::Status)
78
- assert_equal '123', status.options['test']
79
- end
80
- end
81
-
82
- context ".clear" do
83
- setup do
84
- Resque::Status.clear
85
- end
86
-
87
- should "clear any statuses" do
88
- assert_nil Resque::Status.get(@uuid)
89
- end
90
-
91
- should "clear any recent statuses" do
92
- assert Resque::Status.status_ids.empty?
93
- end
94
-
95
- end
96
-
97
- context ".status_ids" do
98
-
99
- setup do
100
- @uuids = []
101
- 30.times{ Resque::Status.create }
102
- end
103
-
104
- should "return an array of job ids" do
105
- assert Resque::Status.status_ids.is_a?(Array)
106
- assert_equal 32, Resque::Status.status_ids.size # 30 + 2
107
- end
108
-
109
- should "let you paginate through the statuses" do
110
- assert_equal Resque::Status.status_ids[0, 10], Resque::Status.status_ids(0, 9)
111
- assert_equal Resque::Status.status_ids[10, 10], Resque::Status.status_ids(10, 19)
112
- # assert_equal Resque::Status.status_ids.reverse[0, 10], Resque::Status.status_ids(0, 10)
113
- end
114
- end
115
-
116
- context ".statuses" do
117
-
118
- should "return an array status objects" do
119
- statuses = Resque::Status.statuses
120
- assert statuses.is_a?(Array)
121
- assert_same_elements [@uuid_with_json, @uuid], statuses.collect {|s| s.uuid }
122
- end
123
-
124
- end
125
-
126
- # context ".count" do
127
- #
128
- # should "return a count of statuses" do
129
- # statuses = Resque::Status.statuses
130
- # assert_equal 2, statuses.size
131
- # assert_equal statuses.size, Resque::Status.count
132
- # end
133
- #
134
- # end
135
-
136
- context ".logger" do
137
- setup do
138
- @logger = Resque::Status.logger(@uuid)
139
- end
140
-
141
- should "return a redisk logger" do
142
- assert @logger.is_a?(Redisk::Logger)
143
- end
144
-
145
- should "scope the logger to a key" do
146
- assert_match(/#{@uuid}/, @logger.name)
147
- end
148
-
149
- end
150
-
151
- end
152
-
153
- end