goz 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module Goz
5
5
  #
6
6
  # Goz version
7
7
  #
8
- VERSION = '0.0.2'
8
+ VERSION = '0.0.3'
9
9
 
10
10
  end
11
11
 
@@ -0,0 +1,189 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'goz/group'
7
+ require 'goz/test_case'
8
+ require 'goz/user'
9
+
10
+
11
+ class TestAdmins < Goz::TestCase
12
+
13
+ def setup
14
+ super
15
+
16
+ @u1 = Goz::User.create( :email => 'u1', :login => 'u1', :identifier => 'u1', :name => 'u1' )
17
+ @u2 = Goz::User.create( :email => 'u2', :login => 'u2', :identifier => 'u2', :name => 'u2' )
18
+ @g1 = Goz::Group.create( :display_name => 'g1', :identifier => 'g1', :name => 'g1' )
19
+ @g2 = Goz::Group.create( :display_name => 'g2', :identifier => 'g2', :name => 'g2' )
20
+ end
21
+
22
+
23
+ def test_no_admins_or_groups
24
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
25
+ [ @u1, @u2 ].each do |u|
26
+ assert_not_nil u.groups
27
+ assert_kind_of Array, u.groups
28
+ assert_equal 0, u.groups.size
29
+ end
30
+ [ @g1, @g2 ].each do |g|
31
+ assert_not_nil g.admins
32
+ assert_kind_of Array, g.admins
33
+ assert_equal 0, g.admins.size
34
+ end
35
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
36
+ end
37
+
38
+ def test_add_admin_to_group
39
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
40
+ @g1.add_admin(@u1)
41
+ @g1.save
42
+ assert_equal 1, @g1.admins.size
43
+ assert_equal 0, @g2.admins.size
44
+ assert_equal @u1, @g1.admins.first
45
+ assert_nil @g2.admins.first
46
+ assert_equal 1, @u1.groups.size
47
+ assert_equal 0, @u2.groups.size
48
+ assert_equal @g1, @u1.groups.first
49
+ assert_nil @u2.groups.first
50
+ Goz::Database.instance do |db|
51
+ assert_equal 1, db[:admins].count
52
+ first = db[:admins].first
53
+ assert_equal @g1.id, first[:group_id]
54
+ assert_equal @u1.id, first[:user_id]
55
+ end
56
+ end
57
+
58
+ def test_add_group_to_admin
59
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
60
+ @u1.add_group(@g1)
61
+ @u1.save
62
+ assert_equal 1, @g1.admins.size
63
+ assert_equal 0, @g2.admins.size
64
+ assert_equal @u1, @g1.admins.first
65
+ assert_nil @g2.admins.first
66
+ assert_equal 1, @u1.groups.size
67
+ assert_equal 0, @u2.groups.size
68
+ assert_equal @g1, @u1.groups.first
69
+ assert_nil @u2.groups.first
70
+ Goz::Database.instance do |db|
71
+ assert_equal 1, db[:admins].count
72
+ first = db[:admins].first
73
+ assert_equal @g1.id, first[:group_id]
74
+ assert_equal @u1.id, first[:user_id]
75
+ end
76
+ end
77
+
78
+ def test_remove_admin_from_group
79
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
80
+ @g1.add_admin(@u1)
81
+ @g1.add_admin(@u2)
82
+ @g1.save
83
+ assert_equal 2, @g1.admins.size
84
+ assert_equal [ @u1, @u2 ], @g1.admins
85
+
86
+ @g1.remove_admin(@u2)
87
+ @g1.save
88
+ assert_equal 1, @g1.admins.size
89
+ assert_equal [ @u1 ], @g1.admins
90
+
91
+ Goz::Database.instance do |db|
92
+ assert_equal 1, db[:admins].count
93
+ first = db[:admins].first
94
+ assert_equal @g1.id, first[:group_id]
95
+ assert_equal @u1.id, first[:user_id]
96
+ end
97
+ end
98
+
99
+ def test_remove_group_from_admin
100
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
101
+ @u1.add_group(@g1)
102
+ @u1.add_group(@g2)
103
+ @u1.save
104
+ assert_equal 2, @u1.groups.size
105
+ assert_equal [ @g1, @g2 ], @u1.groups
106
+
107
+ @u1.remove_group(@g2)
108
+ @u1.save
109
+ assert_equal 1, @u1.groups.size
110
+ assert_equal [ @g1 ], @u1.groups
111
+
112
+ Goz::Database.instance do |db|
113
+ assert_equal 1, db[:admins].count
114
+ first = db[:admins].first
115
+ assert_equal @g1.id, first[:group_id]
116
+ assert_equal @u1.id, first[:user_id]
117
+ end
118
+ end
119
+
120
+ def test_add_duplicate_admin_to_group
121
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
122
+ @g1.add_admin(@u1)
123
+ @g1.save
124
+ assert_equal 1, @g1.admins.size
125
+ assert_equal [ @u1 ], @g1.admins
126
+
127
+ assert_raise(Sequel::DatabaseError) { @g1.add_admin(@u1) }
128
+ assert_equal 1, @g1.admins.size
129
+ assert_equal [ @u1 ], @g1.admins
130
+
131
+ Goz::Database.instance do |db|
132
+ assert_equal 1, db[:admins].count
133
+ first = db[:admins].first
134
+ assert_equal @g1.id, first[:group_id]
135
+ assert_equal @u1.id, first[:user_id]
136
+ end
137
+ end
138
+
139
+ def test_add_duplicate_group_to_admin
140
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
141
+ @u1.add_group(@g1)
142
+ @u1.save
143
+ assert_equal 1, @u1.groups.size
144
+ assert_equal [ @g1 ], @u1.groups
145
+
146
+ assert_raise(Sequel::DatabaseError) { @u1.add_group(@g1) }
147
+ assert_equal 1, @u1.groups.size
148
+ assert_equal [ @g1 ], @u1.groups
149
+
150
+ Goz::Database.instance do |db|
151
+ assert_equal 1, db[:admins].count
152
+ first = db[:admins].first
153
+ assert_equal @g1.id, first[:group_id]
154
+ assert_equal @u1.id, first[:user_id]
155
+ end
156
+ end
157
+
158
+ def test_delete_group
159
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
160
+ @g1.add_admin(@u1)
161
+ @g1.save
162
+ assert_equal 1, @g1.admins.size
163
+ assert_equal [ @u1 ], @g1.admins
164
+
165
+ @g1.destroy
166
+ assert_nil Goz::Group.find_by_name( @g1.name )
167
+
168
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
169
+
170
+ assert_equal [], @u1.groups
171
+ end
172
+
173
+ def test_delete_user
174
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
175
+ @u1.add_group(@g1)
176
+ @u1.save
177
+ assert_equal 1, @u1.groups.size
178
+ assert_equal [ @g1 ], @u1.groups
179
+
180
+ @u1.destroy
181
+ assert_nil Goz::User.find_by_login( @u1.login )
182
+
183
+ Goz::Database.instance { |db| assert_equal 0, db[:admins].count }
184
+
185
+ assert_equal [], @g1.admins
186
+ end
187
+
188
+ end
189
+
@@ -4,15 +4,17 @@ require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
6
  require 'goz/cache'
7
- require 'test/unit'
7
+ require 'goz/test_case'
8
8
 
9
9
 
10
- class TestGozCache < Test::Unit::TestCase
10
+ class TestCache < Goz::TestCase
11
11
 
12
12
  def setup
13
+ super
13
14
  @cache = Goz::Cache.new
14
15
  end
15
16
 
17
+
16
18
  def test_default_initialization
17
19
  blockable = false
18
20
  cache = Goz::Cache.new do |cache|
@@ -0,0 +1,576 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'goz/event'
7
+ require 'goz/test_case'
8
+ require 'goz/user'
9
+
10
+
11
+ class TestEvent < Goz::TestCase
12
+
13
+ def setup
14
+ super
15
+ end
16
+
17
+
18
+ def test_no_events
19
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
20
+ end
21
+
22
+ def test_group_add
23
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
24
+
25
+ t = Time.now
26
+ g = Goz::Group.create( @groups[:a] )
27
+
28
+ Goz::Database.instance do |db|
29
+ assert_equal 1, db[:events].count
30
+ first = db[:events].first
31
+ assert_not_nil first
32
+ assert_not_nil first[:event_type_id]
33
+ assert_equal Goz::EventType::GROUP_ADD, first[:event_type_id]
34
+ assert_not_nil first[:created_at]
35
+ assert first[:created_at] > t
36
+ assert_not_nil first[:group_id]
37
+ assert_equal g.id, first[:group_id]
38
+ assert_nil first[:service_id]
39
+ assert_nil first[:user_id]
40
+ end
41
+ end
42
+
43
+ def test_group_remove
44
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
45
+
46
+ g = Goz::Group.create( @groups[:a] )
47
+ t = Time.now
48
+ g.destroy
49
+
50
+ Goz::Database.instance do |db|
51
+ assert_equal 2, db[:events].order(:id).count
52
+ last = db[:events].order(:id).last
53
+ assert_not_nil last
54
+ assert_not_nil last[:event_type_id]
55
+ assert_equal Goz::EventType::GROUP_REMOVE, last[:event_type_id]
56
+ assert_not_nil last[:created_at]
57
+ assert last[:created_at] > t
58
+ assert_not_nil last[:group_id]
59
+ assert_equal g.id, last[:group_id]
60
+ assert_nil last[:service_id]
61
+ assert_nil last[:user_id]
62
+ end
63
+ end
64
+
65
+ def test_group_sync
66
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
67
+
68
+ t = Time.now
69
+ g = Goz::Group.create( @groups[:a] )
70
+ g.sync(true)
71
+
72
+ Goz::Database.instance do |db|
73
+ assert_equal 2, db[:events].count
74
+ last = db[:events].order(:id).last
75
+ assert_not_nil last
76
+ assert_not_nil last[:event_type_id]
77
+ assert_equal Goz::EventType::GROUP_SYNC, last[:event_type_id]
78
+ assert_not_nil last[:created_at]
79
+ assert last[:created_at] > t
80
+ assert_not_nil last[:group_id]
81
+ assert_equal g.id, last[:group_id]
82
+ assert_nil last[:service_id]
83
+ assert_nil last[:user_id]
84
+ end
85
+ end
86
+
87
+ def test_group_service_sync
88
+ #skip("TODO")
89
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
90
+
91
+ g = Goz::Group.create( @groups[:a] )
92
+ g.sync(true)
93
+ Goz::Database.instance { |db| assert_equal 2, db[:events].count }
94
+
95
+ t = Time.now
96
+ s = Goz::Service.create( @services[:a] )
97
+ g.add_service(s)
98
+ g.sync(true)
99
+ Goz::Database.instance do |db|
100
+ assert_equal 6, db[:events].count
101
+ last = db[:events].order(:id).all[-2]
102
+ assert_not_nil last
103
+ assert_not_nil last[:event_type_id]
104
+ assert_equal Goz::EventType::GROUP_SERVICE_SYNC, last[:event_type_id]
105
+ assert_not_nil last[:created_at]
106
+ assert last[:created_at] > t
107
+ assert_not_nil last[:group_id]
108
+ assert_equal g.id, last[:group_id]
109
+ assert_not_nil last[:service_id]
110
+ assert_equal s.id, last[:service_id]
111
+ assert_nil last[:user_id]
112
+ end
113
+ end
114
+
115
+ def test_service_add
116
+ Goz::Database.instance { |db| assert_equal 0, db[:services].count }
117
+
118
+ t = Time.now
119
+ s = Goz::Service.create( @services[:a] )
120
+
121
+ Goz::Database.instance do |db|
122
+ assert_equal 1, db[:services].count
123
+ first = db[:events].first
124
+ assert_not_nil first
125
+ assert_not_nil first[:event_type_id]
126
+ assert_equal Goz::EventType::SERVICE_ADD, first[:event_type_id]
127
+ assert_not_nil first[:created_at]
128
+ assert first[:created_at] > t
129
+ assert_nil first[:group_id]
130
+ assert_not_nil first[:service_id]
131
+ assert_equal s.id, first[:service_id]
132
+ assert_nil first[:user_id]
133
+ end
134
+ end
135
+
136
+ def test_service_remove
137
+ Goz::Database.instance { |db| assert_equal 0, db[:services].count }
138
+
139
+ s = Goz::Service.create( @services[:a] )
140
+ t = Time.now
141
+ s.destroy
142
+
143
+ Goz::Database.instance do |db|
144
+ assert_equal 2, db[:events].order(:id).count
145
+ last = db[:events].order(:id).last
146
+ assert_not_nil last
147
+ assert_not_nil last[:event_type_id]
148
+ assert_equal Goz::EventType::SERVICE_REMOVE, last[:event_type_id]
149
+ assert_not_nil last[:created_at]
150
+ assert last[:created_at] > t
151
+ assert_nil last[:group_id]
152
+ assert_not_nil last[:service_id]
153
+ assert_equal s.id, last[:service_id]
154
+ assert_nil last[:user_id]
155
+ end
156
+ end
157
+
158
+ def test_service_sync
159
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
160
+
161
+ t = Time.now
162
+ s = Goz::Service.create( @services[:a] )
163
+ s.sync(true)
164
+
165
+ Goz::Database.instance do |db|
166
+ assert_equal 2, db[:events].count
167
+ last = db[:events].order(:id).last
168
+ assert_not_nil last
169
+ assert_not_nil last[:event_type_id]
170
+ assert_equal Goz::EventType::SERVICE_SYNC, last[:event_type_id]
171
+ assert_not_nil last[:created_at]
172
+ assert last[:created_at] > t
173
+ assert_nil last[:group_id]
174
+ assert_not_nil last[:service_id]
175
+ assert_equal s.id, last[:service_id]
176
+ assert_nil last[:user_id]
177
+ end
178
+ end
179
+
180
+ def test_user_add
181
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
182
+
183
+ t = Time.now
184
+ u = Goz::User.create( @users[:a] )
185
+
186
+ Goz::Database.instance do |db|
187
+ assert_equal 1, db[:events].count
188
+ first = db[:events].first
189
+ assert_not_nil first
190
+ assert_not_nil first[:event_type_id]
191
+ assert_equal Goz::EventType::USER_ADD, first[:event_type_id]
192
+ assert_not_nil first[:created_at]
193
+ assert first[:created_at] > t
194
+ assert_nil first[:group_id]
195
+ assert_nil first[:service_id]
196
+ assert_not_nil first[:user_id]
197
+ assert_equal u.id, first[:user_id]
198
+ end
199
+ end
200
+
201
+ def test_user_sync
202
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
203
+
204
+ t = Time.now
205
+ u = Goz::User.create( @users[:a] )
206
+ u.sync(true)
207
+
208
+ Goz::Database.instance do |db|
209
+ assert_equal 2, db[:events].count
210
+ last = db[:events].order(:id).last
211
+ assert_not_nil last
212
+ assert_not_nil last[:event_type_id]
213
+ assert_equal Goz::EventType::USER_SYNC, last[:event_type_id]
214
+ assert_not_nil last[:created_at]
215
+ assert last[:created_at] > t
216
+ assert_nil last[:group_id]
217
+ assert_nil last[:service_id]
218
+ assert_not_nil last[:user_id]
219
+ assert_equal u.id, last[:user_id]
220
+ end
221
+ end
222
+
223
+ def test_user_remove
224
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
225
+
226
+ u = Goz::User.create( @users[:a] )
227
+ t = Time.now
228
+ u.destroy
229
+
230
+ Goz::Database.instance do |db|
231
+ assert_equal 2, db[:events].order(:id).count
232
+ last = db[:events].order(:id).last
233
+ assert_not_nil last
234
+ assert_not_nil last[:event_type_id]
235
+ assert_equal Goz::EventType::USER_REMOVE, last[:event_type_id]
236
+ assert_not_nil last[:created_at]
237
+ assert last[:created_at] > t
238
+ assert_nil last[:group_id]
239
+ assert_nil last[:service_id]
240
+ assert_not_nil last[:user_id]
241
+ assert_equal u.id, last[:user_id]
242
+ end
243
+ end
244
+
245
+ def test_add_admin_to_group
246
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
247
+
248
+ g = Goz::Group.create( @groups[:a] )
249
+ u = Goz::User.create( @users[:a] )
250
+
251
+ t = Time.now
252
+ g.add_admin(u)
253
+ g.save
254
+
255
+ Goz::Database.instance do |db|
256
+ assert_equal 3, db[:events].count
257
+ last = db[:events].order(:id).last
258
+ assert_not_nil last
259
+ assert_not_nil last[:event_type_id]
260
+ assert_equal Goz::EventType::ADMIN_ADD, last[:event_type_id]
261
+ assert_not_nil last[:created_at]
262
+ assert last[:created_at] > t
263
+ assert_not_nil last[:group_id]
264
+ assert_equal g.id, last[:group_id]
265
+ assert_nil last[:service_id]
266
+ assert_not_nil last[:user_id]
267
+ assert_equal u.id, last[:user_id]
268
+ end
269
+ end
270
+
271
+ def test_add_group_to_admin
272
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
273
+
274
+ g = Goz::Group.create( @groups[:a] )
275
+ u = Goz::User.create( @users[:a] )
276
+
277
+ t = Time.now
278
+ u.add_group(g)
279
+ u.save
280
+
281
+ Goz::Database.instance do |db|
282
+ assert_equal 3, db[:events].count
283
+ last = db[:events].order(:id).last
284
+ assert_not_nil last
285
+ assert_not_nil last[:event_type_id]
286
+ assert_equal Goz::EventType::ADMIN_ADD, last[:event_type_id]
287
+ assert_not_nil last[:created_at]
288
+ assert last[:created_at] > t
289
+ assert_not_nil last[:group_id]
290
+ assert_equal g.id, last[:group_id]
291
+ assert_nil last[:service_id]
292
+ assert_not_nil last[:user_id]
293
+ assert_equal u.id, last[:user_id]
294
+ end
295
+ end
296
+
297
+ def test_remove_admin_from_group
298
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
299
+
300
+ g = Goz::Group.create( @groups[:a] )
301
+ u = Goz::User.create( @users[:a] )
302
+
303
+ g.add_admin(u)
304
+ g.save
305
+
306
+ t = Time.now
307
+ g.remove_admin(u)
308
+ g.save
309
+
310
+ Goz::Database.instance do |db|
311
+ assert_equal 4, db[:events].count
312
+ last = db[:events].order(:id).last
313
+ assert_not_nil last
314
+ assert_not_nil last[:event_type_id]
315
+ assert_equal Goz::EventType::ADMIN_REMOVE, last[:event_type_id]
316
+ assert_not_nil last[:created_at]
317
+ assert last[:created_at] > t
318
+ assert_not_nil last[:group_id]
319
+ assert_equal g.id, last[:group_id]
320
+ assert_nil last[:service_id]
321
+ assert_not_nil last[:user_id]
322
+ assert_equal u.id, last[:user_id]
323
+ end
324
+ end
325
+
326
+ def test_remove_group_from_admin
327
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
328
+
329
+ g = Goz::Group.create( @groups[:a] )
330
+ u = Goz::User.create( @users[:a] )
331
+
332
+ u.add_group(g)
333
+ u.save
334
+
335
+ t = Time.now
336
+ u.remove_group(g)
337
+ u.save
338
+
339
+ Goz::Database.instance do |db|
340
+ assert_equal 4, db[:events].count
341
+ last = db[:events].order(:id).last
342
+ assert_not_nil last
343
+ assert_not_nil last[:event_type_id]
344
+ assert_equal Goz::EventType::ADMIN_REMOVE, last[:event_type_id]
345
+ assert_not_nil last[:created_at]
346
+ assert last[:created_at] > t
347
+ assert_not_nil last[:group_id]
348
+ assert_equal g.id, last[:group_id]
349
+ assert_nil last[:service_id]
350
+ assert_not_nil last[:user_id]
351
+ assert_equal u.id, last[:user_id]
352
+ end
353
+ end
354
+
355
+ def test_add_group_to_member
356
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
357
+
358
+ g = Goz::Group.create( @groups[:a] )
359
+ u = Goz::User.create( @users[:a] )
360
+
361
+ t = Time.now
362
+ u.add_membership(g)
363
+ u.save
364
+
365
+ Goz::Database.instance do |db|
366
+ assert_equal 3, db[:events].count
367
+ last = db[:events].order(:id).last
368
+ assert_not_nil last
369
+ assert_not_nil last[:event_type_id]
370
+ assert_equal Goz::EventType::MEMBER_ADD, last[:event_type_id]
371
+ assert_not_nil last[:created_at]
372
+ assert last[:created_at] > t
373
+ assert_not_nil last[:group_id]
374
+ assert_equal g.id, last[:group_id]
375
+ assert_nil last[:service_id]
376
+ assert_not_nil last[:user_id]
377
+ assert_equal u.id, last[:user_id]
378
+ end
379
+ end
380
+
381
+ def test_add_member_to_group
382
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
383
+
384
+ g = Goz::Group.create( @groups[:a] )
385
+ u = Goz::User.create( @users[:a] )
386
+
387
+ t = Time.now
388
+ g.add_member(u)
389
+ g.save
390
+
391
+ Goz::Database.instance do |db|
392
+ assert_equal 3, db[:events].count
393
+ last = db[:events].order(:id).last
394
+ assert_not_nil last
395
+ assert_not_nil last[:event_type_id]
396
+ assert_equal Goz::EventType::MEMBER_ADD, last[:event_type_id]
397
+ assert_not_nil last[:created_at]
398
+ assert last[:created_at] > t
399
+ assert_not_nil last[:group_id]
400
+ assert_equal g.id, last[:group_id]
401
+ assert_nil last[:service_id]
402
+ assert_not_nil last[:user_id]
403
+ assert_equal u.id, last[:user_id]
404
+ end
405
+ end
406
+
407
+ def test_remove_group_from_member
408
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
409
+
410
+ g = Goz::Group.create( @groups[:a] )
411
+ u = Goz::User.create( @users[:a] )
412
+
413
+ u.add_membership(g)
414
+ u.save
415
+
416
+ t = Time.now
417
+ u.remove_membership(g)
418
+ u.save
419
+
420
+ Goz::Database.instance do |db|
421
+ assert_equal 4, db[:events].count
422
+ last = db[:events].order(:id).last
423
+ assert_not_nil last
424
+ assert_not_nil last[:event_type_id]
425
+ assert_equal Goz::EventType::MEMBER_REMOVE, last[:event_type_id]
426
+ assert_not_nil last[:created_at]
427
+ assert last[:created_at] > t
428
+ assert_not_nil last[:group_id]
429
+ assert_equal g.id, last[:group_id]
430
+ assert_nil last[:service_id]
431
+ assert_not_nil last[:user_id]
432
+ assert_equal u.id, last[:user_id]
433
+ end
434
+ end
435
+
436
+ def test_remove_member_from_group
437
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
438
+
439
+ g = Goz::Group.create( @groups[:a] )
440
+ u = Goz::User.create( @users[:a] )
441
+
442
+ g.add_member(u)
443
+ g.save
444
+
445
+ t = Time.now
446
+ g.remove_member(u)
447
+ g.save
448
+
449
+ Goz::Database.instance do |db|
450
+ assert_equal 4, db[:events].count
451
+ last = db[:events].order(:id).last
452
+ assert_not_nil last
453
+ assert_not_nil last[:event_type_id]
454
+ assert_equal Goz::EventType::MEMBER_REMOVE, last[:event_type_id]
455
+ assert_not_nil last[:created_at]
456
+ assert last[:created_at] > t
457
+ assert_not_nil last[:group_id]
458
+ assert_equal g.id, last[:group_id]
459
+ assert_nil last[:service_id]
460
+ assert_not_nil last[:user_id]
461
+ assert_equal u.id, last[:user_id]
462
+ end
463
+ end
464
+
465
+ def test_add_group_to_service
466
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
467
+
468
+ g = Goz::Group.create( @groups[:a] )
469
+ s = Goz::Service.create( @services[:a] )
470
+
471
+ t = Time.now
472
+ s.add_group(g)
473
+ s.save
474
+
475
+ Goz::Database.instance do |db|
476
+ assert_equal 3, db[:events].count
477
+ last = db[:events].order(:id).last
478
+ assert_not_nil last
479
+ assert_not_nil last[:event_type_id]
480
+ assert_equal Goz::EventType::GROUP_SERVICE_ADD, last[:event_type_id]
481
+ assert_not_nil last[:created_at]
482
+ assert last[:created_at] > t
483
+ assert_not_nil last[:group_id]
484
+ assert_equal g.id, last[:group_id]
485
+ assert_not_nil last[:service_id]
486
+ assert_equal s.id, last[:service_id]
487
+ assert_nil last[:user_id]
488
+ end
489
+ end
490
+
491
+ def test_add_service_to_group
492
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
493
+
494
+ g = Goz::Group.create( @groups[:a] )
495
+ s = Goz::Service.create( @services[:a] )
496
+
497
+ t = Time.now
498
+ g.add_service(s)
499
+ g.save
500
+
501
+ Goz::Database.instance do |db|
502
+ assert_equal 3, db[:events].count
503
+ last = db[:events].order(:id).last
504
+ assert_not_nil last
505
+ assert_not_nil last[:event_type_id]
506
+ assert_equal Goz::EventType::GROUP_SERVICE_ADD, last[:event_type_id]
507
+ assert_not_nil last[:created_at]
508
+ assert last[:created_at] > t
509
+ assert_not_nil last[:group_id]
510
+ assert_equal g.id, last[:group_id]
511
+ assert_not_nil last[:service_id]
512
+ assert_equal s.id, last[:service_id]
513
+ assert_nil last[:user_id]
514
+ end
515
+ end
516
+
517
+ def test_remove_group_from_service
518
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
519
+
520
+ g = Goz::Group.create( @groups[:a] )
521
+ s = Goz::Service.create( @services[:a] )
522
+
523
+ s.add_group(g)
524
+ s.save
525
+
526
+ t = Time.now
527
+ s.remove_group(g)
528
+ s.save
529
+
530
+ Goz::Database.instance do |db|
531
+ assert_equal 4, db[:events].count
532
+ last = db[:events].order(:id).last
533
+ assert_not_nil last
534
+ assert_not_nil last[:event_type_id]
535
+ assert_equal Goz::EventType::GROUP_SERVICE_REMOVE, last[:event_type_id]
536
+ assert_not_nil last[:created_at]
537
+ assert last[:created_at] > t
538
+ assert_not_nil last[:group_id]
539
+ assert_equal g.id, last[:group_id]
540
+ assert_not_nil last[:service_id]
541
+ assert_equal s.id, last[:service_id]
542
+ assert_nil last[:user_id]
543
+ end
544
+ end
545
+
546
+ def test_remove_service_from_group
547
+ Goz::Database.instance { |db| assert_equal 0, db[:events].count }
548
+
549
+ g = Goz::Group.create( @groups[:a] )
550
+ s = Goz::Service.create( @services[:a] )
551
+
552
+ g.add_service(s)
553
+ g.save
554
+
555
+ t = Time.now
556
+ g.remove_service(s)
557
+ g.save
558
+
559
+ Goz::Database.instance do |db|
560
+ assert_equal 4, db[:events].count
561
+ last = db[:events].order(:id).last
562
+ assert_not_nil last
563
+ assert_not_nil last[:event_type_id]
564
+ assert_equal Goz::EventType::GROUP_SERVICE_REMOVE, last[:event_type_id]
565
+ assert_not_nil last[:created_at]
566
+ assert last[:created_at] > t
567
+ assert_not_nil last[:group_id]
568
+ assert_equal g.id, last[:group_id]
569
+ assert_not_nil last[:service_id]
570
+ assert_equal s.id, last[:service_id]
571
+ assert_nil last[:user_id]
572
+ end
573
+ end
574
+
575
+ end
576
+