This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
/
test_default_scopes.rb
52 lines (44 loc) · 1.72 KB
/
test_default_scopes.rb
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
require 'test_helper'
class MultipleDefaultScopesTest < ParanoidBaseTest
def setup
setup_db
# Naturally, the default scope for humans is male. Sexism++
ParanoidHuman.create! :gender => 'male'
ParanoidHuman.create! :gender => 'male'
ParanoidHuman.create! :gender => 'male'
ParanoidHuman.create! :gender => 'female'
assert_equal 3, ParanoidHuman.count
assert_equal 4, ParanoidHuman.unscoped.count
end
def test_fake_removal_with_multiple_default_scope
ParanoidHuman.first.destroy
assert_equal 2, ParanoidHuman.count
assert_equal 3, ParanoidHuman.with_deleted.count
assert_equal 1, ParanoidHuman.only_deleted.count
assert_equal 4, ParanoidHuman.unscoped.count
ParanoidHuman.destroy_all
assert_equal 0, ParanoidHuman.count
assert_equal 3, ParanoidHuman.with_deleted.count
assert_equal 3, ParanoidHuman.with_deleted.count
assert_equal 4, ParanoidHuman.unscoped.count
end
def test_real_removal_with_multiple_default_scope
# two-step
ParanoidHuman.first.destroy
ParanoidHuman.only_deleted.first.destroy
assert_equal 2, ParanoidHuman.count
assert_equal 2, ParanoidHuman.with_deleted.count
assert_equal 0, ParanoidHuman.only_deleted.count
assert_equal 3, ParanoidHuman.unscoped.count
ParanoidHuman.first.destroy!
assert_equal 1, ParanoidHuman.count
assert_equal 1, ParanoidHuman.with_deleted.count
assert_equal 0, ParanoidHuman.only_deleted.count
assert_equal 2, ParanoidHuman.unscoped.count
ParanoidHuman.delete_all!
assert_equal 0, ParanoidHuman.count
assert_equal 0, ParanoidHuman.with_deleted.count
assert_equal 0, ParanoidHuman.only_deleted.count
assert_equal 1, ParanoidHuman.unscoped.count
end
end