Sha256: a10cb5686c50c1bdb9fb4b7dc2e7e95e2e10381c33a19e784b7da787cc3b0a8d

Contents?: true

Size: 1.84 KB

Versions: 7

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'
require_relative 'shared_examples'

describe Riak::Crdt::Set do
  let(:bucket) do
    double('bucket').tap do |b|
      allow(b).to receive(:name).and_return('bucket')
      allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true)
      allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false)
    end
  end

  it 'initializes with bucket, key, and optional bucket-type' do
    expect{described_class.new bucket, 'key', 'optional bucket type'}.
      to_not raise_error
  end

  subject{ described_class.new bucket, 'key' }

  describe 'with a client' do
    let(:response){ double 'response', key: nil }
    let(:operator){ double 'operator' }
    let(:loader){ double 'loader', get_loader_for_value: nil }
    let(:backend){ double 'backend' }
    let(:client){ double 'client' }

    before(:each) do
      allow(bucket).to receive(:client).and_return(client)
      allow(client).to receive(:backend).and_yield(backend)
      allow(backend).to receive(:crdt_operator).and_return(operator)
      allow(backend).to receive(:crdt_loader).and_return(loader)
    end

    include_examples 'Set CRDT'

    it 'batches properly' do
      expect(operator).
        to receive(:operate) { |bucket, key, type, operations|

        expect(bucket).to eq bucket
        expect(key).to eq 'key'
        expect(type).to eq subject.bucket_type

        expect(operations).to be_a Riak::Crdt::Operation::Update
        expect(operations.value).to eq({
                                         add: %w{alpha bravo},
                                         remove: %w{foxtrot}
                                       })
      }.
        and_return(response)

      subject.instance_variable_set :@context, 'placeholder'

      subject.batch do |s|
        s.add 'alpha'
        s.add 'bravo'
        s.remove 'foxtrot'
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
riak-client-2.5.0 spec/riak/crdt/set_spec.rb
riak-client-2.3.0 spec/riak/crdt/set_spec.rb
riak-client-2.2.2 spec/riak/crdt/set_spec.rb
riak-client-2.2.1 spec/riak/crdt/set_spec.rb
riak-client-noenc-1.0.0 spec/riak/crdt/set_spec.rb
riak-client-2.2.0 spec/riak/crdt/set_spec.rb
riak-client-2.2.0.pre1 spec/riak/crdt/set_spec.rb