Sha256: 0bb40348fa2b52144dcb729b246092a1e7b9e67e688bff66196ddf3cfc437bac

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

module Ripple
  module Conflict
    module TestHelper
      def create_conflict(main_record, *modifiers)
        # We have to disable all on conflict resolvers while we create conflict
        # so that they don't auto-resolve it.
        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)|
            # necessary to get conflict on 0.14 and earlier, so riak thinks they are being saved by different clients
            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
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/conflict/test_helper.rb
better-ripple-1.0.0 lib/ripple/conflict/test_helper.rb
ripple-1.0.0.beta2 lib/ripple/conflict/test_helper.rb