-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeletion_spec.rb
More file actions
96 lines (78 loc) · 2.57 KB
/
deletion_spec.rb
File metadata and controls
96 lines (78 loc) · 2.57 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require 'redis'
require 'database_cleaner/redis/deletion'
require 'yaml'
RSpec.describe DatabaseCleaner::Redis::Deletion do
around do |example|
config = YAML::load(File.open("spec/support/redis.yml"))
@redis = ::Redis.new :url => config['test']['url']
example.run
@redis.flushdb
end
before do
@redis.set 'Widget', 1
@redis.set 'Gadget', 1
end
context "by default" do
it "deletes all keys" do
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(0)
end
end
context "with the :only option" do
context "with concrete keys" do
subject { described_class.new(only: ['Widget']) }
it "only deletes the specified keys" do
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(1)
expect(@redis.get('Gadget')).to eq '1'
end
end
context "with wildcard keys" do
subject { described_class.new(only: ['Widge*']) }
it "only deletes the specified keys" do
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(1)
expect(@redis.get('Gadget')).to eq '1'
end
end
context "with wildcard keys and no matches in Redis DB" do
subject { described_class.new(only: ["test*"]) }
it "only deletes the specified keys" do
subject.clean
expect(@redis.keys).to match_array(["Widget", "Gadget"])
end
end
end
context "with the :except option" do
context "with concrete keys" do
subject { described_class.new(except: ['Widget']) }
it "deletes all but the specified keys" do
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(1)
expect(@redis.get('Widget')).to eq '1'
end
end
context "with wildcard keys" do
subject { described_class.new(except: ['Widg*']) }
it "deletes all but the specified keys" do
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(1)
expect(@redis.get('Widget')).to eq '1'
end
end
end
context "when passing url" do
it "still works" do
url = @redis.connection[:id]
subject.db = url
expect(subject.db).to eq url
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(0)
end
end
context "when passing connection" do
it "still works" do
connection = Redis.new(url: @redis.connection[:id])
subject.db = connection
expect(subject.db).to eq connection
expect { subject.clean }.to change { @redis.keys.size }.from(2).to(0)
end
end
it "should default to :default" do
expect(subject.db).to eq :default
end
end