spec/integration/riak/encodings/crdt_spec.rb in riak-client-2.4.0 vs spec/integration/riak/encodings/crdt_spec.rb in riak-client-2.4.1

- old
+ new

@@ -1,8 +1,9 @@ # coding: utf-8 require 'spec_helper' require 'riak' +require 'riak/util/string' describe 'Encoding and CRDTs', integration: true, search_config: true do shared_examples 'CRDTs with weird names' do let(:counter_bucket) do test_client.bucket_type('counters').bucket(random_string) @@ -14,62 +15,81 @@ test_client.bucket_type('sets').bucket(random_string) end it 'creates counters' do counter = nil + expect{ counter = Riak::Crdt::Counter.new counter_bucket, random_string }. to_not raise_error expect(counter).to be_a Riak::Crdt::Counter expect(value = counter.value).to be_a Numeric expect{ counter.increment }.to_not raise_error + expect(counter.value).to eq value + 1 end it 'updates registers in maps' do map = nil + + expect(random_string.encoding.name).to eq expected_encoding + expect{ map = Riak::Crdt::Map.new map_bucket, random_string }. to_not raise_error expect(map).to be_a Riak::Crdt::Map expect(map.registers[random_string]).to be_nil + expect{ map.registers[random_string] = random_string }. to_not raise_error - expect(map.registers[random_string]).to eq random_string + expect(map.registers.length).to eq 1 + + expect(map.registers[random_string]).to_not be_nil + + expect(Riak::Util::String.equal_bytes?(map.registers[random_string], random_string)).to be + + expect(random_string.encoding.name).to eq expected_encoding end it 'updates sets' do set = nil + + expect(random_string.encoding.name).to eq expected_encoding + expect{ set = Riak::Crdt::Set.new set_bucket, random_string }. to_not raise_error expect(set).to be_a Riak::Crdt::Set - expect(set.members).to_not include random_string + expect(set.include?(random_string)).to_not be set.add random_string - expect(set.members).to include random_string + expect(set.include?(random_string)).to be set.remove random_string - expect(set.members).to_not include random_string + expect(set.include?(random_string)).to_not be + + expect(random_string.encoding.name).to eq expected_encoding end end describe 'with utf-8 strings' do let(:string){ "\xF0\x9F\x9A\xB4こんにちはสวัสดี" } + let(:expected_encoding){ 'UTF-8' } let(:random_string){ string + random_key } include_examples 'CRDTs with weird names' end describe 'with binary strings' do let(:string){ "\xff\xff".force_encoding('binary') } + let(:expected_encoding){ 'ASCII-8BIT' } let(:random_string){ string + random_key } include_examples 'CRDTs with weird names' end end