riak-client 2.2.0.pre1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +0 -2
  4. data/README.markdown +11 -7
  5. data/RELEASE_NOTES.md +29 -2
  6. data/Rakefile +5 -3
  7. data/lib/riak/bucket.rb +55 -23
  8. data/lib/riak/bucket_properties.rb +8 -1
  9. data/lib/riak/bucket_type.rb +29 -0
  10. data/lib/riak/bucket_typed/bucket.rb +15 -7
  11. data/lib/riak/client.rb +24 -8
  12. data/lib/riak/client/beefcake/bucket_properties_operator.rb +8 -8
  13. data/lib/riak/client/beefcake/crdt/set_loader.rb +1 -1
  14. data/lib/riak/client/beefcake/crdt_loader.rb +1 -1
  15. data/lib/riak/client/beefcake/crdt_operator.rb +9 -9
  16. data/lib/riak/client/beefcake/message_codes.rb +4 -0
  17. data/lib/riak/client/beefcake/message_overlay.rb +4 -0
  18. data/lib/riak/client/beefcake/messages.rb +35 -5
  19. data/lib/riak/client/beefcake/object_methods.rb +21 -13
  20. data/lib/riak/client/beefcake/protocol.rb +7 -7
  21. data/lib/riak/client/beefcake/socket.rb +2 -2
  22. data/lib/riak/client/beefcake_protobuffs_backend.rb +58 -33
  23. data/lib/riak/client/protobuffs_backend.rb +5 -5
  24. data/lib/riak/client/yokozuna.rb +3 -3
  25. data/lib/riak/core_ext/deep_dup.rb +1 -1
  26. data/lib/riak/counter.rb +10 -10
  27. data/lib/riak/crdt/base.rb +39 -21
  28. data/lib/riak/crdt/batch_counter.rb +5 -5
  29. data/lib/riak/crdt/batch_map.rb +2 -2
  30. data/lib/riak/crdt/counter.rb +7 -7
  31. data/lib/riak/crdt/inner_counter.rb +4 -4
  32. data/lib/riak/crdt/inner_flag.rb +3 -3
  33. data/lib/riak/crdt/inner_map.rb +1 -1
  34. data/lib/riak/crdt/inner_register.rb +1 -1
  35. data/lib/riak/crdt/inner_set.rb +5 -5
  36. data/lib/riak/crdt/map.rb +9 -9
  37. data/lib/riak/crdt/set.rb +10 -10
  38. data/lib/riak/crdt/typed_collection.rb +39 -36
  39. data/lib/riak/errors/base.rb +1 -1
  40. data/lib/riak/errors/crdt_error.rb +20 -0
  41. data/lib/riak/errors/search_error.rb +6 -0
  42. data/lib/riak/index_collection.rb +1 -1
  43. data/lib/riak/link.rb +5 -3
  44. data/lib/riak/locale/en.yml +5 -1
  45. data/lib/riak/map_reduce.rb +7 -7
  46. data/lib/riak/map_reduce/filter_builder.rb +2 -2
  47. data/lib/riak/map_reduce/phase.rb +2 -2
  48. data/lib/riak/preflist_item.rb +7 -0
  49. data/lib/riak/rcontent.rb +8 -8
  50. data/lib/riak/robject.rb +27 -14
  51. data/lib/riak/search.rb +1 -0
  52. data/lib/riak/search/index.rb +17 -3
  53. data/lib/riak/search/query.rb +14 -6
  54. data/lib/riak/search/result_collection.rb +56 -3
  55. data/lib/riak/search/result_document.rb +71 -1
  56. data/lib/riak/search/schema.rb +6 -6
  57. data/lib/riak/secondary_index.rb +20 -12
  58. data/lib/riak/serializers.rb +0 -1
  59. data/lib/riak/util/escape.rb +2 -2
  60. data/lib/riak/util/translation.rb +1 -2
  61. data/lib/riak/version.rb +1 -1
  62. data/lib/riak/walk_spec.rb +67 -32
  63. data/riak-client.gemspec +5 -4
  64. data/spec/integration/riak/bucket_types_spec.rb +35 -5
  65. data/spec/integration/riak/conflict_resolution_spec.rb +1 -1
  66. data/spec/integration/riak/counters_spec.rb +1 -1
  67. data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
  68. data/spec/integration/riak/crdt_search_spec.rb +176 -0
  69. data/spec/integration/riak/crdt_spec.rb +9 -33
  70. data/spec/integration/riak/crdt_validation/map_spec.rb +4 -4
  71. data/spec/integration/riak/crdt_validation/set_spec.rb +13 -13
  72. data/spec/integration/riak/preflist_spec.rb +31 -0
  73. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +2 -2
  74. data/spec/integration/riak/protobuffs_backends_spec.rb +9 -2
  75. data/spec/integration/riak/search_spec.rb +3 -3
  76. data/spec/integration/riak/secondary_index_spec.rb +3 -3
  77. data/spec/integration/riak/security_spec.rb +7 -7
  78. data/spec/integration/yokozuna/queries_spec.rb +1 -1
  79. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +9 -9
  80. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +9 -9
  81. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +5 -5
  82. data/spec/riak/beefcake_protobuffs_backend_spec.rb +8 -8
  83. data/spec/riak/bucket_properties_spec.rb +27 -6
  84. data/spec/riak/bucket_spec.rb +5 -5
  85. data/spec/riak/bucket_type_spec.rb +21 -5
  86. data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
  87. data/spec/riak/client_spec.rb +36 -18
  88. data/spec/riak/counter_spec.rb +4 -4
  89. data/spec/riak/crdt/counter_spec.rb +2 -2
  90. data/spec/riak/crdt/inner_flag_spec.rb +2 -2
  91. data/spec/riak/crdt/inner_map_spec.rb +4 -4
  92. data/spec/riak/crdt/inner_register_spec.rb +1 -1
  93. data/spec/riak/crdt/map_spec.rb +4 -4
  94. data/spec/riak/crdt/shared_examples.rb +5 -5
  95. data/spec/riak/crdt/typed_collection_spec.rb +21 -21
  96. data/spec/riak/map_reduce/filter_builder_spec.rb +2 -2
  97. data/spec/riak/map_reduce/phase_spec.rb +4 -4
  98. data/spec/riak/map_reduce_spec.rb +60 -42
  99. data/spec/riak/multiget_spec.rb +2 -2
  100. data/spec/riak/robject_spec.rb +55 -14
  101. data/spec/riak/search/index_spec.rb +12 -2
  102. data/spec/riak/search/query_spec.rb +4 -4
  103. data/spec/riak/search/result_collection_spec.rb +6 -4
  104. data/spec/riak/search/result_document_spec.rb +52 -9
  105. data/spec/riak/search/schema_spec.rb +2 -2
  106. data/spec/riak/secondary_index_spec.rb +6 -6
  107. data/spec/riak/serializers_spec.rb +27 -10
  108. data/spec/riak/walk_spec_spec.rb +10 -6
  109. data/spec/spec_helper.rb +11 -2
  110. data/spec/support/crdt_search_config.rb +112 -0
  111. data/spec/support/crdt_search_fixtures.rb +42 -0
  112. data/spec/support/search_config.rb +7 -5
  113. data/spec/support/search_corpus_setup.rb +2 -2
  114. data/spec/support/test_client.rb +2 -2
  115. data/spec/support/unified_backend_examples.rb +5 -5
  116. data/spec/support/version_filter.rb +5 -3
  117. data/spec/support/wait_until.rb +9 -3
  118. metadata +36 -13
  119. data/spec/riak/bucket_typed/bucket.rb +0 -43
@@ -38,7 +38,7 @@ describe Riak::Bucket do
38
38
  @bucket.keys do |list|
39
39
  all_keys.concat(list)
40
40
  end
41
- expect(all_keys).to eq(["bar", "baz"])
41
+ expect(all_keys).to eq(%w(bar baz))
42
42
  end
43
43
 
44
44
  it "fetches a fresh list of keys" do
@@ -66,7 +66,7 @@ describe Riak::Bucket do
66
66
  describe "accessing a counter" do
67
67
  it "returns a counter object" do
68
68
  expect(Riak::Counter).to receive(:new).with(@bucket, 'asdf').and_return('example counter')
69
-
69
+
70
70
  new_counter = @bucket.counter 'asdf'
71
71
 
72
72
  expect(new_counter).to eq('example counter')
@@ -146,7 +146,7 @@ describe Riak::Bucket do
146
146
 
147
147
  it "returns the existing object if present" do
148
148
  @object = double("RObject")
149
- expect(@backend).to receive(:fetch_object).with(@bucket,"db", {}).and_return(@object)
149
+ expect(@backend).to receive(:fetch_object).with(@bucket, "db", {}).and_return(@object)
150
150
  expect(@bucket.get_or_new('db')).to eq(@object)
151
151
  end
152
152
 
@@ -164,7 +164,7 @@ describe Riak::Bucket do
164
164
 
165
165
  it "passes the given R quorum parameter to the backend" do
166
166
  @object = double("RObject")
167
- expect(@backend).to receive(:fetch_object).with(@bucket,"db", {:r => "all"}).and_return(@object)
167
+ expect(@backend).to receive(:fetch_object).with(@bucket, "db", {:r => "all"}).and_return(@object)
168
168
  expect(@bucket.get_or_new('db', :r => "all")).to eq(@object)
169
169
  end
170
170
  end
@@ -243,7 +243,7 @@ describe Riak::Bucket do
243
243
 
244
244
  it "sets the #{q} quorum" do
245
245
  expect(@bucket).to receive(:props=).with(hash_including("#{q}" => 1))
246
- @bucket.send("#{q}=",1)
246
+ @bucket.send("#{q}=", 1)
247
247
  end
248
248
  end
249
249
  end
@@ -24,11 +24,27 @@ describe Riak::BucketType do
24
24
  expect(typed_bucket.type).to eq subject
25
25
  end
26
26
 
27
- let(:sample_props){ { allow_mult: true } }
27
+ describe 'equality' do
28
+ let(:same){ described_class.new client, name }
29
+ let(:different_client){ described_class.new Riak::Client.allocate, name }
30
+ let(:different_name){ described_class.new client, 'different name' }
31
+ it { is_expected.to eq same }
32
+ it { is_expected.to_not eq different_client }
33
+ it { is_expected.to_not eq different_name }
34
+ end
35
+
36
+ describe 'properties' do
37
+ let(:props_expectation){ expect(backend).to receive(:get_bucket_type_props).with(name) }
28
38
 
29
- it 'has properties' do
30
- expect(backend).to receive(:get_bucket_type_props).with(name).and_return(sample_props)
31
- expect(props = subject.properties).to be_a Hash
32
- expect(props[:allow_mult]).to be
39
+ it 'is queryable' do
40
+ props_expectation.and_return(allow_mult: true)
41
+ expect(props = subject.properties).to be_a Hash
42
+ expect(props[:allow_mult]).to be
43
+ end
44
+
45
+ it 'asks for data type' do
46
+ props_expectation.and_return(datatype: 'set')
47
+ expect(subject.data_type_class).to eq Riak::Crdt::Set
48
+ end
33
49
  end
34
50
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'riak/bucket_typed/bucket'
3
+
4
+ describe Riak::BucketTyped::Bucket do
5
+ let(:client){ Riak::Client.allocate }
6
+ let(:type){ client.bucket_type 'type' }
7
+ let(:name){ 'bucket_typed_bucket_spec' }
8
+
9
+ subject{ described_class.new client, name, type }
10
+
11
+ it 'initializes a typed RObject' do
12
+ typed_robject = subject.new 'panther'
13
+ expect(typed_robject).to be_a Riak::RObject
14
+ expect(typed_robject.key).to eq 'panther'
15
+ expect(typed_robject.bucket.type).to eq type
16
+ end
17
+
18
+ it 'has a bucket type' do
19
+ expect(subject.type).to eq type
20
+ expect(subject.type.name).to eq 'type'
21
+ end
22
+
23
+ describe 'equality' do
24
+ let(:same){ described_class.new client, name, type }
25
+ let(:different){ described_class.new client, 'other', type }
26
+ let(:untyped){ Riak::Bucket.new client, name }
27
+ it { is_expected.to eq subject }
28
+ it { is_expected.to eq same }
29
+ it { is_expected.to_not eq untyped }
30
+ it { is_expected.to_not eq different }
31
+ end
32
+
33
+ describe 'bucket properties' do
34
+ it 'returns properties scoped by bucket and type' do
35
+ expect(client).to receive(:get_bucket_props).
36
+ with(subject, { type: subject.type.name }).
37
+ and_return('allow_mult' => true)
38
+
39
+ expect(props = subject.props).to be_a Hash
40
+ expect(props['allow_mult']).to be
41
+ end
42
+
43
+ it 'clears properties scoped by bucket and type' do
44
+ expect(client).to receive(:clear_bucket_props).
45
+ with(subject, { type: subject.type.name })
46
+
47
+ expect{ subject.clear_props }.to_not raise_error
48
+ end
49
+
50
+ it 'sets properties scoped by bucket and type' do
51
+ expect(client).to receive(:get_bucket_props).
52
+ with(subject, { type: subject.type.name }).
53
+ and_return('allow_mult' => false)
54
+ expect(client).to receive(:set_bucket_props).
55
+ with(subject,
56
+ { 'allow_mult' => true },
57
+ subject.type.name)
58
+
59
+ expect{ subject.props = { 'allow_mult' => true } }.to_not raise_error
60
+ end
61
+ end
62
+ end
@@ -26,15 +26,16 @@ describe Riak::Client, test_client: true do
26
26
  end
27
27
 
28
28
  it "creates a client ID if not specified" do
29
- expect(Riak::Client.new(pb_port: test_client.nodes.first.pb_port).client_id).not_to be_nil
29
+ expect(Riak::Client.new(pb_port: test_client.nodes.first.pb_port).
30
+ client_id).to_not be_nil
30
31
  end
31
32
 
32
33
  it "accepts multiple nodes" do
33
- client = Riak::Client.new :nodes => [
34
- {:host => 'riak1.basho.com'},
35
- {:host => 'riak2.basho.com', :pb_port => 1234},
36
- {:host => 'riak3.basho.com', :pb_port => 5678}
37
- ]
34
+ client = Riak::Client.new nodes: [
35
+ {host: 'riak1.basho.com'},
36
+ {host: 'riak2.basho.com', pb_port: 1234},
37
+ {host: 'riak3.basho.com', pb_port: 5678}
38
+ ]
38
39
  expect(client.nodes.size).to eq(3)
39
40
  expect(client.nodes.first.host).to eq("riak1.basho.com")
40
41
  end
@@ -64,11 +65,15 @@ describe Riak::Client, test_client: true do
64
65
  end
65
66
 
66
67
  it "rejects an integer equal to the maximum client id" do
67
- expect { @client.client_id = Riak::Client::MAX_CLIENT_ID }.to raise_error(ArgumentError)
68
+ expect do
69
+ @client.client_id = Riak::Client::MAX_CLIENT_ID
70
+ end.to raise_error(ArgumentError)
68
71
  end
69
72
 
70
73
  it "rejects an integer larger than the maximum client id" do
71
- expect { @client.client_id = Riak::Client::MAX_CLIENT_ID + 1 }.to raise_error(ArgumentError)
74
+ expect do
75
+ @client.client_id = Riak::Client::MAX_CLIENT_ID + 1
76
+ end.to raise_error(ArgumentError)
72
77
  end
73
78
  end
74
79
  end
@@ -91,8 +96,11 @@ describe Riak::Client, test_client: true do
91
96
  end
92
97
 
93
98
  it "raises an error when the chosen backend is not valid" do
94
- expect(Riak::Client::BeefcakeProtobuffsBackend).to receive(:configured?).and_return(false)
95
- expect { @client.protobuffs { |x| } }.to raise_error Riak::BackendCreationError
99
+ expect(Riak::Client::BeefcakeProtobuffsBackend).to receive(:configured?).
100
+ and_return(false)
101
+ expect do
102
+ @client.protobuffs { |x| }
103
+ end.to raise_error Riak::BackendCreationError
96
104
  end
97
105
  end
98
106
 
@@ -112,8 +120,12 @@ describe Riak::Client, test_client: true do
112
120
  before :each do
113
121
  @client = Riak::Client.new
114
122
  @bucket = @client.bucket('foo')
115
- expect(@bucket).to receive(:[]).with('value1').and_return(double('robject'))
116
- expect(@bucket).to receive(:[]).with('value2').and_return(double('robject'))
123
+ expect(@bucket).to receive(:[]).
124
+ with('value1').
125
+ and_return(double('robject'))
126
+ expect(@bucket).to receive(:[]).
127
+ with('value2').
128
+ and_return(double('robject'))
117
129
  @pairs = [
118
130
  [@bucket, 'value1'],
119
131
  [@bucket, 'value2']
@@ -143,13 +155,19 @@ describe Riak::Client, test_client: true do
143
155
  end
144
156
 
145
157
  it "fetches bucket properties if asked" do
146
- expect(@backend).to receive(:get_bucket_props) {|b| expect(b.name).to eq("foo"); {} }
158
+ expect(@backend).to receive(:get_bucket_props) do |b|
159
+ expect(b.name).to eq("foo")
160
+ {}
161
+ end
147
162
  @client.bucket("foo", :props => true)
148
163
  end
149
164
 
150
165
  it "memoizes bucket parameters" do
151
166
  @bucket = double("Bucket")
152
- expect(Riak::Bucket).to receive(:new).with(@client, "baz").once.and_return(@bucket)
167
+ expect(Riak::Bucket).to receive(:new).
168
+ with(@client, "baz").
169
+ once.
170
+ and_return(@bucket)
153
171
  expect(@client.bucket("baz")).to eq(@bucket)
154
172
  expect(@client.bucket("baz")).to eq(@bucket)
155
173
  end
@@ -194,14 +212,14 @@ describe Riak::Client, test_client: true do
194
212
 
195
213
  describe "when receiving errors from the backend" do
196
214
  before do
197
- @client = Riak::Client.new
215
+ @client = Riak::Client.new
198
216
  end
199
217
 
200
218
  it "retries on recoverable errors" do
201
219
  call_count = 0
202
-
220
+
203
221
  begin
204
- @client.backend do |b|
222
+ @client.backend do |b|
205
223
  call_count += 1
206
224
  raise Riak::ProtobuffsFailedHeader
207
225
  end
@@ -214,7 +232,7 @@ describe Riak::Client, test_client: true do
214
232
  it "throws a RuntimeError if it runs out of retries" do
215
233
  error = nil
216
234
  begin
217
- @client.backend do |b|
235
+ @client.backend do |b|
218
236
  raise Riak::ProtobuffsFailedHeader
219
237
  end
220
238
  rescue RuntimeError => e
@@ -22,10 +22,10 @@ describe Riak::Counter do
22
22
  allow(@bad_bucket).to receive(:client).and_return(double('client'))
23
23
 
24
24
  expect{ctr = Riak::Counter.new @bad_bucket, @key}.to raise_error(ArgumentError)
25
-
25
+
26
26
  end
27
27
  end
28
-
28
+
29
29
  describe "incrementing and decrementing" do
30
30
  before :each do
31
31
  @backend = double 'backend'
@@ -92,7 +92,7 @@ describe Riak::Counter do
92
92
 
93
93
  @fake_pool = double 'pool'
94
94
  @backend = double 'backend'
95
-
95
+
96
96
  @client = Riak::Client.new nodes: @nodes
97
97
  @client.instance_variable_set :@protobuffs_pool, @fake_pool
98
98
 
@@ -113,7 +113,7 @@ describe Riak::Counter do
113
113
  @expect_post.once.and_raise('timeout')
114
114
  expect(proc { @ctr.increment }).to raise_error
115
115
  end
116
-
116
+
117
117
  it "doesn't retry on quorum failure" do
118
118
  @expect_post.once.and_raise('quorum not satisfied')
119
119
  expect(proc { @ctr.increment }).to raise_error
@@ -22,14 +22,14 @@ describe Riak::Crdt::Counter do
22
22
  let(:loader){ double 'loader', get_loader_for_value: nil }
23
23
  let(:backend){ double 'backend' }
24
24
  let(:client){ double 'client' }
25
-
25
+
26
26
  before(:each) do
27
27
  allow(bucket).to receive(:client).and_return(client)
28
28
  allow(client).to receive(:backend).and_yield(backend)
29
29
  allow(backend).to receive(:crdt_operator).and_return(operator)
30
30
  allow(backend).to receive(:crdt_loader).and_return(loader)
31
31
  end
32
-
32
+
33
33
  include_examples 'Counter CRDT'
34
34
 
35
35
  it 'batches properly' do
@@ -9,7 +9,7 @@ describe Riak::Crdt::InnerFlag do
9
9
  expect(subject).to be
10
10
  end
11
11
  end
12
-
12
+
13
13
  describe 'a falsey flag' do
14
14
  subject { described_class.new parent, false }
15
15
 
@@ -20,7 +20,7 @@ describe Riak::Crdt::InnerFlag do
20
20
 
21
21
  describe 'updating' do
22
22
  let(:new_value){ false }
23
-
23
+
24
24
  it '\asks the class for an update operation' do
25
25
  operation = described_class.update(new_value)
26
26
 
@@ -13,10 +13,10 @@ describe Riak::Crdt::InnerMap do
13
13
  flags: {bravo: true},
14
14
  maps: {},
15
15
  registers: {delta: 'the expendables' },
16
- sets: {echo: %w{stallone statham li lundgren}}
16
+ sets: {echo: %w{stallone statham li lundgren}}
17
17
  }
18
18
  end
19
-
19
+
20
20
  it 'is initializable with a nested hash of maps' do
21
21
  expect{described_class.new parent, populated_contents}.
22
22
  to_not raise_error
@@ -34,13 +34,13 @@ describe Riak::Crdt::InnerMap do
34
34
  let(:inner_operation){ double 'inner operation' }
35
35
  it 'wraps the operation in an update operation and pass it to the parent' do
36
36
  subject.name = 'name'
37
-
37
+
38
38
  expect(parent).to receive(:operate) do |name, op|
39
39
  expect(name).to eq 'name'
40
40
  expect(op.type).to eq :map
41
41
  expect(op.value).to eq inner_operation
42
42
  end
43
-
43
+
44
44
  subject.operate inner_operation
45
45
  end
46
46
  end
@@ -9,7 +9,7 @@ describe Riak::Crdt::InnerRegister do
9
9
  expect{ subject.gsub('s', 'x') }.to_not raise_error
10
10
  expect(subject.gsub('s', 'x')).to eq 'exprexxox'
11
11
  end
12
-
12
+
13
13
  describe 'immutability' do
14
14
  it 'is frozen' do
15
15
  expect(subject.frozen?).to be
@@ -15,7 +15,7 @@ describe Riak::Crdt::Map do
15
15
  let(:backend){ double 'backend' }
16
16
  let(:client){ double 'client' }
17
17
  let(:key){ 'map' }
18
-
18
+
19
19
  before(:each) do
20
20
  allow(client).to receive(:backend).and_yield(backend)
21
21
  allow(backend).to receive(:crdt_operator).and_return(operator)
@@ -23,9 +23,9 @@ describe Riak::Crdt::Map do
23
23
  allow(loader).to receive(:load).and_return({})
24
24
  allow(loader).to receive(:context).and_return('context')
25
25
  end
26
-
26
+
27
27
  subject{ described_class.new bucket, key }
28
-
28
+
29
29
  include_examples 'Map CRDT'
30
30
 
31
31
  describe 'batch mode' do
@@ -38,7 +38,7 @@ describe Riak::Crdt::Map do
38
38
  expect(type).to eq subject.bucket_type
39
39
 
40
40
  expect(operations.length).to eq 2
41
-
41
+
42
42
  expect(operations.first).to be_a Riak::Crdt::Operation::Update
43
43
 
44
44
  expect(operations.first.value).to be_a Riak::Crdt::Operation::Update
@@ -5,22 +5,22 @@ shared_examples_for "Map CRDT" do
5
5
  expect(subject).to respond_to(:counters)
6
6
  expect(subject.counters).to be_an_instance_of typed_collection
7
7
  end
8
-
8
+
9
9
  it 'contains flags' do
10
10
  expect(subject).to respond_to(:flags)
11
11
  expect(subject.counters).to be_an_instance_of typed_collection
12
12
  end
13
-
13
+
14
14
  it 'contains maps' do
15
15
  expect(subject).to respond_to(:maps)
16
16
  expect(subject.counters).to be_an_instance_of typed_collection
17
17
  end
18
-
18
+
19
19
  it 'contains registers' do
20
20
  expect(subject).to respond_to(:registers)
21
21
  expect(subject.counters).to be_an_instance_of typed_collection
22
22
  end
23
-
23
+
24
24
  it 'contains sets' do
25
25
  expect(subject).to respond_to(:sets)
26
26
  expect(subject.counters).to be_an_instance_of typed_collection
@@ -35,7 +35,7 @@ shared_examples_for "Counter CRDT" do
35
35
  it 'has a value' do
36
36
  expect(subject).to respond_to :value
37
37
  end
38
-
38
+
39
39
  it 'has an increment method' do
40
40
  expect(subject).to respond_to :increment
41
41
  end
@@ -16,7 +16,7 @@ describe Riak::Crdt::TypedCollection do
16
16
  subject do
17
17
  described_class.new register_class, parent, existing: 'existing'
18
18
  end
19
-
19
+
20
20
  it 'exposes them as frozen strings that are really Registers' do
21
21
  expect(subject[:existing]).to eq 'existing'
22
22
  expect(subject['existing']).to eq 'existing'
@@ -28,7 +28,7 @@ describe Riak::Crdt::TypedCollection do
28
28
  describe 'creating and updating' do
29
29
 
30
30
  let(:new_value){ 'the new value' }
31
-
31
+
32
32
  it 'asks the register class for an operation' do
33
33
  expect(register_class).to receive(:update).
34
34
  with(new_value).
@@ -70,7 +70,7 @@ describe Riak::Crdt::TypedCollection do
70
70
  subject do
71
71
  described_class.new flag_class, parent, truthy: true, falsey: false
72
72
  end
73
-
73
+
74
74
  it 'exposes them as booleans' do
75
75
  expect(subject[:truthy]).to eq true
76
76
  expect(subject['falsey']).to eq false
@@ -92,7 +92,7 @@ describe Riak::Crdt::TypedCollection do
92
92
 
93
93
  subject['become_truthy'] = true
94
94
  end
95
-
95
+
96
96
  it 'deletes them' do
97
97
  expect(flag_class).
98
98
  to receive(:delete).
@@ -113,22 +113,22 @@ describe Riak::Crdt::TypedCollection do
113
113
  let(:counter_class){ Riak::Crdt::InnerCounter }
114
114
 
115
115
  subject{ described_class.new counter_class, parent, zero: 0, one: 1 }
116
-
116
+
117
117
  it 'exposes existing ones as Counter instances' do
118
118
  expect(subject['zero']).to be_an_instance_of counter_class
119
119
  expect(subject['zero'].to_i).to eq 0
120
-
120
+
121
121
  expect(subject['one'].to_i).to eq 1
122
122
  end
123
-
123
+
124
124
  it 'exposes new ones as Counter instances' do
125
125
  expect(subject['new_zero']).to be_an_instance_of counter_class
126
126
  expect(subject['new_zero'].to_i).to eq 0
127
127
  end
128
-
128
+
129
129
  it 'allows incrementing and decrementing' do
130
130
  counter_name = 'counter'
131
-
131
+
132
132
  expect(parent).to receive(:operate) do |op|
133
133
  expect(op.name).to eq counter_name
134
134
  expect(op.type).to eq :counter
@@ -141,7 +141,7 @@ describe Riak::Crdt::TypedCollection do
141
141
  expect(op.type).to eq :counter
142
142
  expect(op.value).to eq -5
143
143
  end
144
-
144
+
145
145
  subject[counter_name].decrement 5
146
146
  end
147
147
  end
@@ -149,17 +149,17 @@ describe Riak::Crdt::TypedCollection do
149
149
  let(:set_class){ Riak::Crdt::InnerSet }
150
150
 
151
151
  subject{ described_class.new set_class, parent, brewers: %w{aeropress clever v60}}
152
-
152
+
153
153
  it 'exposes existing ones as Set instances' do
154
154
  expect(subject['brewers']).to be_an_instance_of set_class
155
155
  expect(subject['brewers']).to include 'aeropress'
156
156
  end
157
-
157
+
158
158
  it 'exposes new ones as empty Set instances' do
159
159
  expect(subject['filters']).to be_an_instance_of set_class
160
160
  expect(subject['filters']).to be_empty
161
161
  end
162
-
162
+
163
163
  it 'allows adding and removing' do
164
164
  set_name = 'brewers'
165
165
 
@@ -180,7 +180,7 @@ describe Riak::Crdt::TypedCollection do
180
180
  subject[set_name].remove 'aeropress'
181
181
  end
182
182
  end
183
-
183
+
184
184
  describe 'maps' do
185
185
  let(:map_class){ Riak::Crdt::InnerMap }
186
186
 
@@ -192,32 +192,32 @@ describe Riak::Crdt::TypedCollection do
192
192
  sets: {}
193
193
  }}
194
194
  end
195
-
195
+
196
196
  let(:inner_map_name){ 'inner map' }
197
-
197
+
198
198
  subject do
199
199
  described_class.new map_class, parent, contents
200
200
  end
201
-
201
+
202
202
  it 'exposes existing ones as populated Map instances' do
203
203
  expect(subject['a']).to be_an_instance_of map_class
204
204
  expect(subject['a'].registers['hello']).to eq 'world'
205
205
  end
206
-
206
+
207
207
  it 'exposes new ones as empty Map instances' do
208
208
  expect(subject['b']).to be_an_instance_of map_class
209
209
  expect(subject['b'].registers['hello']).to be_nil
210
210
  end
211
-
211
+
212
212
  it 'cascades operations to a parent map' do
213
213
  expect(operation).
214
214
  to receive(:name=).
215
215
  with(inner_map_name)
216
-
216
+
217
217
  expect(parent).
218
218
  to receive(:operate).
219
219
  with(operation)
220
-
220
+
221
221
  subject.operate inner_map_name, operation
222
222
  end
223
223
  end