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
|
# File 'lib/ripple/conflict/test_helper.rb', line 4
def create_conflict(main_record, *modifiers)
orig_hooks = Riak::RObject.on_conflict_hooks.dup
Riak::RObject.on_conflict_hooks.clear
begin
klass, key = main_record.class, main_record.key
raise "#{klass.bucket.name} allow_mult property is false!" unless klass.bucket.allow_mult
records = modifiers.map { |_| klass.find!(key) }
records.zip(modifiers).each do |(record, modifier)|
Ripple.client.client_id += 1
modifier.call(record)
record.save! unless record.deleted?
end
robject = klass.bucket.get(key)
raise "#{robject} is not in conflict as expected." unless robject.conflict?
ensure
orig_hooks.each do |hook|
Riak::RObject.on_conflict(&hook)
end
end
end
|