whi-cassie 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,574 +1,596 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Cassie::Model do
4
-
5
4
  describe "definition" do
6
5
  it "should define the table name" do
7
- Cassie::Thing.table_name.should == "things"
8
- Cassie::Thing.keyspace.should == "cassie_specs"
9
- Cassie::Thing.full_table_name.should == "cassie_specs.things"
10
- Cassie::Thing.column_names.should =~ [:owner, :id, :val]
6
+ expect(Cassie::Thing.table_name).to eq("things")
7
+ expect(Cassie::Thing.keyspace).to eq("cassie_specs")
8
+ expect(Cassie::Thing.full_table_name).to eq("cassie_specs.things")
9
+ expect(Cassie::Thing.column_names).to match_array([:owner, :id, :val])
11
10
  end
12
-
11
+
13
12
  it "should define the primary key" do
14
- Cassie::Thing.primary_key.should == [:owner, :id]
13
+ expect(Cassie::Thing.primary_key).to eq([:owner, :id])
15
14
  end
16
-
15
+
17
16
  it "should alias abbreviated column names with human readable names" do
18
17
  m = Cassie::Thing.new
19
18
  m.id = 1
20
- m.identifier.should == 1
19
+ expect(m.identifier).to eq(1)
21
20
  m.identifier = 2
22
- m.id.should == 2
21
+ expect(m.id).to eq(2)
23
22
  end
24
-
23
+
25
24
  it "should allow null values" do
26
- Cassie::Thing.create!(:owner => 1, :id => 2)
27
- record = Cassie::Thing.find(:owner => 1, :id => 2)
28
- record.value.should == nil
25
+ Cassie::Thing.create!(owner: 1, id: 2)
26
+ record = Cassie::Thing.find(owner: 1, id: 2)
27
+ expect(record.value).to eq(nil)
29
28
  end
30
29
  end
31
-
30
+
32
31
  describe "create" do
33
32
  it "should create a record" do
34
- record = Cassie::Thing.create(:owner => 1, :identifier => 2, :value => 'foo')
35
- record.owner.should == 1
36
- Cassie::Thing.find(:owner => 1, :identifier => 2).value.should == 'foo'
33
+ record = Cassie::Thing.create(owner: 1, identifier: 2, value: "foo")
34
+ expect(record.owner).to eq(1)
35
+ expect(Cassie::Thing.find(owner: 1, identifier: 2).value).to eq("foo")
37
36
  end
38
-
37
+
39
38
  it "should not save an invalid record" do
40
- record = Cassie::Thing.create(:owner => 1, :value => 'foo')
41
- record.should_not be_valid
42
- Cassie::Thing.count(:owner => 1).should == 0
39
+ record = Cassie::Thing.create(owner: 1, value: "foo")
40
+ expect(record).not_to be_valid
41
+ expect(Cassie::Thing.count(owner: 1)).to eq(0)
43
42
  end
44
-
43
+
45
44
  it "should error on an invalid record using the bang version" do
46
- lambda{ Cassie::Thing.create!(:owner => 1, :value => 'foo') }.should raise_error(Cassie::RecordInvalid)
45
+ expect { Cassie::Thing.create!(owner: 1, value: "foo") }.to raise_error(Cassie::RecordInvalid)
47
46
  end
48
47
  end
49
-
48
+
50
49
  describe "delete_all" do
51
50
  it "should delete all records matching the key" do
52
- Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo')
53
- Cassie::Thing.create(:owner => 1, :id => 3, :val => 'bar')
54
- Cassie::Thing.count(:owner => 1).should == 2
55
- Cassie::Thing.delete_all(:owner => 1, :id => 2)
56
- Cassie::Thing.count(:owner => 1).should == 1
57
- Cassie::Thing.find(:owner => 1, :id => 2).should == nil
58
- Cassie::Thing.find(:owner => 1, :id => 3).should_not == nil
51
+ Cassie::Thing.create(owner: 1, id: 2, val: "foo")
52
+ Cassie::Thing.create(owner: 1, id: 3, val: "bar")
53
+ expect(Cassie::Thing.count(owner: 1)).to eq(2)
54
+ Cassie::Thing.delete_all(owner: 1, id: 2)
55
+ expect(Cassie::Thing.count(owner: 1)).to eq(1)
56
+ expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(nil)
57
+ expect(Cassie::Thing.find(owner: 1, id: 3)).not_to eq(nil)
59
58
  end
60
59
  end
61
-
60
+
62
61
  describe "finding" do
63
- let!(:r1){ Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo') }
64
- let!(:r2){ Cassie::Thing.create(:owner => 1, :id => 3, :val => 'bar') }
65
- let!(:r3){ Cassie::Thing.create(:owner => 2, :id => 3, :val => 'blah') }
66
-
62
+ let!(:r1) { Cassie::Thing.create(owner: 1, id: 2, val: "foo") }
63
+ let!(:r2) { Cassie::Thing.create(owner: 1, id: 3, val: "bar") }
64
+ let!(:r3) { Cassie::Thing.create(owner: 2, id: 3, val: "blah") }
65
+
67
66
  it "should find all records using a variety of syntaxes" do
68
- Cassie::Thing.find_all(where: {:owner => 1}, order: "id ASC").should == [r1, r2]
69
- Cassie::Thing.find_all(where: {:owner => 1}, order: "id DESC").should == [r2, r1]
70
- Cassie::Thing.find_all(where: {:owner => 1}, order: "id ASC", limit: 1).should == [r1]
71
- Cassie::Thing.find_all(where: "owner = 1", order: "id ASC").should == [r1, r2]
72
- Cassie::Thing.find_all(where: ["owner = ?", 1], order: "id ASC").should == [r1, r2]
73
- Cassie::Thing.find_all(where: {:owner => 0}, order: "id ASC").should == []
74
- Cassie::Thing.find_all(where: {:owner => 1, :id => 2}).should == [r1]
75
- Cassie::Thing.find_all(where: {:owner => [1, 2]}).should =~ [r1, r2, r3]
76
- Cassie::Thing.find_all(where: {:owner => [1, 2]}, options: {:page_size => 1}).should =~ [r1, r2, r3]
77
- end
78
-
67
+ expect(Cassie::Thing.find_all(where: {owner: 1}, order: "id ASC")).to eq([r1, r2])
68
+ expect(Cassie::Thing.find_all(where: {owner: 1}, order: "id DESC")).to eq([r2, r1])
69
+ expect(Cassie::Thing.find_all(where: {owner: 1}, order: "id ASC", limit: 1)).to eq([r1])
70
+ expect(Cassie::Thing.find_all(where: "owner = 1", order: "id ASC")).to eq([r1, r2])
71
+ expect(Cassie::Thing.find_all(where: ["owner = ?", 1], order: "id ASC")).to eq([r1, r2])
72
+ expect(Cassie::Thing.find_all(where: {owner: 0}, order: "id ASC")).to eq([])
73
+ expect(Cassie::Thing.find_all(where: {owner: 1, id: 2})).to eq([r1])
74
+ expect(Cassie::Thing.find_all(where: {owner: [1, 2]})).to match_array([r1, r2, r3])
75
+ expect(Cassie::Thing.find_all(where: {owner: [1, 2]}, options: {page_size: 1})).to match_array([r1, r2, r3])
76
+ end
77
+
79
78
  it "should find one record" do
80
- Cassie::Thing.find(:owner => 1, :id => 2).should == r1
81
- Cassie::Thing.find(:owner => 1, :id => 3).should == r2
82
- Cassie::Thing.find(:owner => 1, :id => 0).should == nil
79
+ expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(r1)
80
+ expect(Cassie::Thing.find(owner: 1, id: 3)).to eq(r2)
81
+ expect(Cassie::Thing.find(owner: 1, id: 0)).to eq(nil)
83
82
  end
84
-
83
+
85
84
  it "should raise an error if the record can't be found and called as find!" do
86
- Cassie::Thing.find!(:owner => 1, :id => 2).should == r1
87
- lambda{ Cassie::Thing.find!(:owner => 1, :id => 0) }.should raise_error(Cassie::RecordNotFound)
85
+ expect(Cassie::Thing.find!(owner: 1, id: 2)).to eq(r1)
86
+ expect { Cassie::Thing.find!(owner: 1, id: 0) }.to raise_error(Cassie::RecordNotFound)
88
87
  end
89
-
88
+
90
89
  it "should mark found records as persisted" do
91
- Cassie::Thing.find(:owner => 1, :id => 2).persisted?.should == true
90
+ expect(Cassie::Thing.find(owner: 1, id: 2).persisted?).to eq(true)
92
91
  end
93
-
92
+
94
93
  it "should count records" do
95
- Cassie::Thing.count(:owner => 1).should == 2
96
- Cassie::Thing.count(:owner => 1, :id => 2).should == 1
94
+ expect(Cassie::Thing.count(owner: 1)).to eq(2)
95
+ expect(Cassie::Thing.count(owner: 1, id: 2)).to eq(1)
97
96
  end
98
-
97
+
99
98
  it "won't find all records with a blank where clause" do
100
- expect{ Cassie::Thing.find_all(where: {}) }.to raise_error(ArgumentError)
101
- Cassie::Thing.find_all(where: :all).size.should == 3
99
+ expect { Cassie::Thing.find_all(where: {}) }.to raise_error(ArgumentError)
100
+ expect(Cassie::Thing.find_all(where: :all).size).to eq(3)
102
101
  end
103
-
102
+
104
103
  it "should be able to add subscribers" do
105
104
  global = nil
106
105
  local = nil
107
- Cassie::Model.find_subscribers << lambda{|info| global = info.rows}
108
- Cassie::Thing.find_subscribers << lambda{|info| local = info.rows}
109
- Cassie::Thing.find_all(where: {:owner => 1}).size.should == 2
110
- global.should == 2
111
- local.should == 2
106
+ Cassie::Model.find_subscribers << lambda { |info| global = info.rows }
107
+ Cassie::Thing.find_subscribers << lambda { |info| local = info.rows }
108
+ expect(Cassie::Thing.find_all(where: {owner: 1}).size).to eq(2)
109
+ expect(global).to eq(2)
110
+ expect(local).to eq(2)
112
111
  end
113
112
  end
114
-
113
+
115
114
  describe "offset_to_id" do
116
- let!(:r1){ Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo') }
117
- let!(:r2){ Cassie::Thing.create(:owner => 1, :id => 3, :val => 'bar') }
118
- let!(:r3){ Cassie::Thing.create(:owner => 1, :id => 4, :val => 'blah') }
119
- let!(:r4){ Cassie::Thing.create(:owner => 1, :id => 5, :val => 'mip') }
120
- let!(:r5){ Cassie::Thing.create(:owner => 2, :id => 2, :val => 'grl') }
121
-
115
+ let!(:r1) { Cassie::Thing.create(owner: 1, id: 2, val: "foo") }
116
+ let!(:r2) { Cassie::Thing.create(owner: 1, id: 3, val: "bar") }
117
+ let!(:r3) { Cassie::Thing.create(owner: 1, id: 4, val: "blah") }
118
+ let!(:r4) { Cassie::Thing.create(owner: 1, id: 5, val: "mip") }
119
+ let!(:r5) { Cassie::Thing.create(owner: 2, id: 2, val: "grl") }
120
+
122
121
  it "should calculate the ordering key at a specified offset" do
123
- Cassie::Thing.offset_to_id({:owner => 1}, 2).should == 3
124
- Cassie::Thing.offset_to_id({:owner => 1}, 2, order: :asc).should == 4
125
- Cassie::Thing.offset_to_id({:owner => 1}, 2, batch_size: 1).should == 3
126
- Cassie::Thing.offset_to_id({:owner => 1}, 3, batch_size: 1).should == 2
127
- Cassie::Thing.offset_to_id({:owner => 1}, 4, batch_size: 1).should == nil
128
- Cassie::Thing.offset_to_id({:owner => 1}, 4, batch_size: 100).should == nil
129
- Cassie::Thing.offset_to_id({:owner => 1}, 1, batch_size: 1, min: 3).should == 4
130
- Cassie::Thing.offset_to_id({:owner => 1}, 1, order: :desc, batch_size: 1, max: 5).should == 3
122
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 2)).to eq(3)
123
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 2, order: :asc)).to eq(4)
124
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 2, batch_size: 1)).to eq(3)
125
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 3, batch_size: 1)).to eq(2)
126
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 4, batch_size: 1)).to eq(nil)
127
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 4, batch_size: 100)).to eq(nil)
128
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 1, batch_size: 1, min: 3)).to eq(4)
129
+ expect(Cassie::Thing.offset_to_id({owner: 1}, 1, order: :desc, batch_size: 1, max: 5)).to eq(3)
131
130
  end
132
131
  end
133
-
132
+
134
133
  describe "batch" do
135
134
  it "should delegate to Cassie.batch using the write consistency" do
136
- Cassie::Thing.connection.should be_a(Cassie)
137
- expect(Cassie::Thing.connection).to receive(:batch).with(:consistency => :quorum).and_call_original
138
- Cassie::Thing.batch{}
135
+ expect(Cassie::Thing.connection).to be_a(Cassie)
136
+ expect(Cassie::Thing.connection).to receive(:batch).with(consistency: :quorum).and_call_original
137
+ Cassie::Thing.batch {}
139
138
  end
140
139
  end
141
-
140
+
142
141
  describe "attributes" do
143
142
  it "should get and set attributes" do
144
- record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
145
- record.attributes.should == {:owner => 1, :id => 2, :val => 'foo'}
143
+ record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
144
+ expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
145
+ record.attributes = {owner: 2, id: 3, val: "bar"}
146
+ expect(record.attributes).to eq({owner: 2, id: 3, val: "bar"})
146
147
  end
147
-
148
+
148
149
  it "should get and set attributes using human readable names" do
149
- record = Cassie::Thing.new(:owner => 1, :identifier => 2, :value => 'foo')
150
- record.attributes.should == {:owner => 1, :id => 2, :val => 'foo'}
150
+ record = Cassie::Thing.new(owner: 1, identifier: 2, value: "foo")
151
+ expect(record.attributes).to eq({owner: 1, id: 2, val: "foo"})
152
+ record.attributes = {owner: 2, identifier: 3, val: "bar"}
153
+ expect(record.attributes).to eq({owner: 2, id: 3, val: "bar"})
151
154
  end
152
155
  end
153
-
156
+
154
157
  describe "save" do
155
158
  it "should not save an invalid record" do
156
- record = Cassie::Thing.new(:owner => 1, :val => 'foo')
157
- record.save.should == false
158
- Cassie::Thing.count(:owner => 1).should == 0
159
+ record = Cassie::Thing.new(owner: 1, val: "foo")
160
+ expect(record.save).to eq(false)
161
+ expect(Cassie::Thing.count(owner: 1)).to eq(0)
159
162
  end
160
-
163
+
161
164
  it "should raise an error on the bang version on an invalid record" do
162
- record = Cassie::Thing.new(:owner => 1, :val => 'foo')
163
- lambda{ record.save! }.should raise_error(Cassie::RecordInvalid)
164
- Cassie::Thing.count(:owner => 1).should == 0
165
+ record = Cassie::Thing.new(owner: 1, val: "foo")
166
+ expect { record.save! }.to raise_error(Cassie::RecordInvalid)
167
+ expect(Cassie::Thing.count(owner: 1)).to eq(0)
165
168
  end
166
-
169
+
167
170
  it "should save new records and invoke the create callbacks" do
168
- record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
169
- record.persisted?.should == false
170
- record.save.should == true
171
- record.persisted?.should == true
172
- record.callbacks.should == [:save, :create]
173
- Cassie::Thing.find(:owner => 1, :id => 2).should == record
174
- end
175
-
171
+ record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
172
+ expect(record.persisted?).to eq(false)
173
+ expect(record.save).to eq(true)
174
+ expect(record.persisted?).to eq(true)
175
+ expect(record.callbacks).to eq([:save, :create])
176
+ expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(record)
177
+ end
178
+
176
179
  it "should save existing records and invoke the update callbacks" do
177
- Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo')
178
- record = Cassie::Thing.find(:owner => 1, :id => 2)
179
- record.persisted?.should == true
180
- record.value = 'bar'
181
- record.save.should == true
182
- record.persisted?.should == true
183
- record.callbacks.should == [:save, :update]
184
- Cassie::Thing.find(:owner => 1, :id => 2).value.should == 'bar'
185
- end
186
-
180
+ Cassie::Thing.create(owner: 1, id: 2, val: "foo")
181
+ record = Cassie::Thing.find(owner: 1, id: 2)
182
+ expect(record.persisted?).to eq(true)
183
+ record.value = "bar"
184
+ expect(record.save).to eq(true)
185
+ expect(record.persisted?).to eq(true)
186
+ expect(record.callbacks).to eq([:save, :update])
187
+ expect(Cassie::Thing.find(owner: 1, id: 2).value).to eq("bar")
188
+ end
189
+
187
190
  it "should save new records with a ttl" do
188
- expect(Cassie::Thing.connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>'foo'}, {:consistency=>:quorum, :ttl=>10}).and_call_original
189
- record = Cassie::Thing.new(:owner => 1, :id => 2, :val => 'foo')
190
- record.persisted?.should == false
191
- record.save(ttl: 10).should == true
192
- record.persisted?.should == true
193
- record.callbacks.should == [:save, :create]
194
- Cassie::Thing.find(:owner => 1, :id => 2).should == record
191
+ expect(Cassie::Thing.connection).to receive(:insert).with("cassie_specs.things", {owner: 1, id: 2, val: "foo"}, {consistency: :quorum, ttl: 10}).and_call_original
192
+ record = Cassie::Thing.new(owner: 1, id: 2, val: "foo")
193
+ expect(record.persisted?).to eq(false)
194
+ expect(record.save(ttl: 10)).to eq(true)
195
+ expect(record.persisted?).to eq(true)
196
+ expect(record.callbacks).to eq([:save, :create])
197
+ expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(record)
198
+ end
199
+ end
200
+
201
+ describe "update" do
202
+ it "should set attributes and save" do
203
+ record = Cassie::Thing.create(owner: 1, id: 2, val: "foo")
204
+ record.update(owner: 2)
205
+ record.reload
206
+ expect(record.owner).to eq 2
207
+ record.update!(owner: 3)
208
+ record.reload
209
+ expect(record.owner).to eq 3
210
+ end
211
+ end
212
+
213
+ describe "primary_key" do
214
+ it "should return the primary key as a hash" do
215
+ record = Cassie::Thing.create(owner: 1, id: 2, val: "foo")
216
+ expect(record.primary_key).to eq({owner: 1, id: 2})
195
217
  end
196
218
  end
197
-
219
+
198
220
  describe "destroy" do
199
221
  it "should delete a record from Cassandra calling any destroy callbacks" do
200
- Cassie::Thing.create(:owner => 1, :id => 2, :val => 'foo')
201
- record = Cassie::Thing.find(:owner => 1, :id => 2)
222
+ Cassie::Thing.create(owner: 1, id: 2, val: "foo")
223
+ record = Cassie::Thing.find(owner: 1, id: 2)
202
224
  record.destroy
203
- Cassie::Thing.find(:owner => 1, :id => 2).should == nil
204
- record.callbacks.should =~ [:destroy]
225
+ expect(Cassie::Thing.find(owner: 1, id: 2)).to eq(nil)
226
+ expect(record.callbacks).to match_array([:destroy])
205
227
  end
206
228
  end
207
-
229
+
208
230
  describe "consistency" do
209
- let(:connection){ Cassie::Thing.connection }
231
+ let(:connection) { Cassie::Thing.connection }
210
232
 
211
233
  it "should be able to set a model level read consistency" do
212
- expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {:consistency => :one}).and_call_original
213
- Cassie::Thing.find_all(where: {:owner => 0})
234
+ expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {consistency: :one}).and_call_original
235
+ Cassie::Thing.find_all(where: {owner: 0})
214
236
  end
215
-
237
+
216
238
  it "should be able to override the model level read consistency" do
217
239
  save_val = Cassie::Thing.read_consistency
218
240
  begin
219
241
  Cassie::Thing.read_consistency = :quorum
220
- expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {:consistency => :quorum}).and_call_original
221
- Cassie::Thing.find_all(where: {:owner => 0})
242
+ expect(connection).to receive(:find).with("SELECT owner, id, val FROM cassie_specs.things WHERE owner = ?", [0], {consistency: :quorum}).and_call_original
243
+ Cassie::Thing.find_all(where: {owner: 0})
222
244
  ensure
223
245
  Cassie::Thing.read_consistency = save_val
224
246
  end
225
247
  end
226
-
248
+
227
249
  it "should be able to set a model level write consistency" do
228
- thing = Cassie::Thing.new(:owner => 1, :id => 2)
229
- expect(connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>nil}, {:consistency=>:quorum, :ttl=>nil}).and_call_original
250
+ thing = Cassie::Thing.new(owner: 1, id: 2)
251
+ expect(connection).to receive(:insert).with("cassie_specs.things", {owner: 1, id: 2, val: nil}, {consistency: :quorum, ttl: nil}).and_call_original
230
252
  thing.save
231
-
253
+
232
254
  thing.val = "foo"
233
- expect(connection).to receive(:update).with("cassie_specs.things", {:val=>"foo"}, {:owner=>1, :id=>2}, {:consistency=>:quorum, :ttl=>nil}).and_call_original
255
+ expect(connection).to receive(:update).with("cassie_specs.things", {val: "foo"}, {owner: 1, id: 2}, {consistency: :quorum, ttl: nil}).and_call_original
234
256
  thing.save
235
-
236
- expect(connection).to receive(:delete).with("cassie_specs.things", {:owner=>1, :id=>2}, {:consistency=>:quorum}).and_call_original
257
+
258
+ expect(connection).to receive(:delete).with("cassie_specs.things", {owner: 1, id: 2}, {consistency: :quorum}).and_call_original
237
259
  thing.destroy
238
260
  end
239
-
261
+
240
262
  it "should be able to override the model level write consistency" do
241
- thing = Cassie::Thing.new(:owner => 1, :id => 2)
263
+ thing = Cassie::Thing.new(owner: 1, id: 2)
242
264
  thing.write_consistency = :local_quorum
243
-
244
- expect(connection).to receive(:insert).with("cassie_specs.things", {:owner=>1, :id=>2, :val=>nil}, {:consistency=>:local_quorum, :ttl=>nil}).and_call_original
265
+
266
+ expect(connection).to receive(:insert).with("cassie_specs.things", {owner: 1, id: 2, val: nil}, {consistency: :local_quorum, ttl: nil}).and_call_original
245
267
  thing.save
246
-
268
+
247
269
  thing.val = "foo"
248
- expect(connection).to receive(:update).with("cassie_specs.things", {:val=>"foo"}, {:owner=>1, :id=>2}, {:consistency=>:local_quorum, :ttl=>nil}).and_call_original
270
+ expect(connection).to receive(:update).with("cassie_specs.things", {val: "foo"}, {owner: 1, id: 2}, {consistency: :local_quorum, ttl: nil}).and_call_original
249
271
  thing.save
250
-
251
- expect(connection).to receive(:delete).with("cassie_specs.things", {:owner=>1, :id=>2}, {:consistency=>:local_quorum}).and_call_original
272
+
273
+ expect(connection).to receive(:delete).with("cassie_specs.things", {owner: 1, id: 2}, {consistency: :local_quorum}).and_call_original
252
274
  thing.destroy
253
275
  end
254
276
  end
255
-
277
+
256
278
  describe "type conversion" do
257
- let(:model){ Cassie::TypeTester.new }
258
-
279
+ let(:model) { Cassie::TypeTester.new }
280
+
259
281
  it "should work with varchar columns" do
260
282
  model.varchar_value = "foo"
261
- model.varchar_value.should == "foo"
283
+ expect(model.varchar_value).to eq("foo")
262
284
  model.save
263
285
  id = model.id
264
- model = Cassie::TypeTester.find(:id => id)
265
- model.varchar_value.should == "foo"
266
-
286
+ model = Cassie::TypeTester.find(id: id)
287
+ expect(model.varchar_value).to eq("foo")
288
+
267
289
  model.varchar_value = nil
268
- model.varchar_value.should == nil
290
+ expect(model.varchar_value).to eq(nil)
269
291
  model.save
270
- model = Cassie::TypeTester.find(:id => id)
271
- model.varchar_value.should == nil
292
+ model = Cassie::TypeTester.find(id: id)
293
+ expect(model.varchar_value).to eq(nil)
272
294
  end
273
-
295
+
274
296
  it "should work with ascii columns" do
275
297
  model.ascii_value = "foo"
276
- model.ascii_value.should == "foo"
298
+ expect(model.ascii_value).to eq("foo")
277
299
  model.save
278
300
  id = model.id
279
- model = Cassie::TypeTester.find(:id => id)
280
- model.ascii_value.should == "foo"
301
+ model = Cassie::TypeTester.find(id: id)
302
+ expect(model.ascii_value).to eq("foo")
281
303
 
282
304
  model.ascii_value = nil
283
- model.ascii_value.should == nil
305
+ expect(model.ascii_value).to eq(nil)
284
306
  model.save
285
- model = Cassie::TypeTester.find(:id => id)
286
- model.ascii_value.should == nil
307
+ model = Cassie::TypeTester.find(id: id)
308
+ expect(model.ascii_value).to eq(nil)
287
309
  end
288
-
310
+
289
311
  it "should work with text columns" do
290
312
  model.text_value = "foo"
291
- model.text_value.should == "foo"
313
+ expect(model.text_value).to eq("foo")
292
314
  model.save
293
315
  id = model.id
294
- model = Cassie::TypeTester.find(:id => id)
295
- model.text_value.should == "foo"
316
+ model = Cassie::TypeTester.find(id: id)
317
+ expect(model.text_value).to eq("foo")
296
318
 
297
319
  model.text_value = nil
298
- model.text_value.should == nil
320
+ expect(model.text_value).to eq(nil)
299
321
  model.save
300
- model = Cassie::TypeTester.find(:id => id)
301
- model.text_value.should == nil
322
+ model = Cassie::TypeTester.find(id: id)
323
+ expect(model.text_value).to eq(nil)
302
324
  end
303
-
325
+
304
326
  it "should work with blob columns" do
305
327
  model.blob_value = "foo"
306
- model.blob_value.should == "foo"
328
+ expect(model.blob_value).to eq("foo")
307
329
  model.save
308
330
  id = model.id
309
- model = Cassie::TypeTester.find(:id => id)
310
- model.blob_value.should == "foo"
331
+ model = Cassie::TypeTester.find(id: id)
332
+ expect(model.blob_value).to eq("foo")
311
333
 
312
334
  model.blob_value = nil
313
- model.blob_value.should == nil
335
+ expect(model.blob_value).to eq(nil)
314
336
  model.save
315
- model = Cassie::TypeTester.find(:id => id)
316
- model.blob_value.should == nil
337
+ model = Cassie::TypeTester.find(id: id)
338
+ expect(model.blob_value).to eq(nil)
317
339
  end
318
-
340
+
319
341
  it "should work with int columns" do
320
342
  model.int_value = "1"
321
- model.int_value.should == 1
343
+ expect(model.int_value).to eq(1)
322
344
  model.int_value = 2
323
- model.int_value.should == 2
345
+ expect(model.int_value).to eq(2)
324
346
  model.save
325
347
  id = model.id
326
- model = Cassie::TypeTester.find(:id => id)
327
- model.int_value.should == 2
348
+ model = Cassie::TypeTester.find(id: id)
349
+ expect(model.int_value).to eq(2)
328
350
 
329
351
  model.int_value = nil
330
- model.int_value.should == nil
352
+ expect(model.int_value).to eq(nil)
331
353
  model.save
332
- model = Cassie::TypeTester.find(:id => id)
333
- model.int_value.should == nil
354
+ model = Cassie::TypeTester.find(id: id)
355
+ expect(model.int_value).to eq(nil)
334
356
  end
335
-
357
+
336
358
  it "should work with bigint columns" do
337
359
  model.bigint_value = "1"
338
- model.bigint_value.should == 1
360
+ expect(model.bigint_value).to eq(1)
339
361
  model.bigint_value = 2
340
- model.bigint_value.should == 2
362
+ expect(model.bigint_value).to eq(2)
341
363
  model.save
342
364
  id = model.id
343
- model = Cassie::TypeTester.find(:id => id)
344
- model.bigint_value.should == 2
365
+ model = Cassie::TypeTester.find(id: id)
366
+ expect(model.bigint_value).to eq(2)
345
367
 
346
368
  model.bigint_value = nil
347
- model.bigint_value.should == nil
369
+ expect(model.bigint_value).to eq(nil)
348
370
  model.save
349
- model = Cassie::TypeTester.find(:id => id)
350
- model.bigint_value.should == nil
371
+ model = Cassie::TypeTester.find(id: id)
372
+ expect(model.bigint_value).to eq(nil)
351
373
  end
352
-
374
+
353
375
  it "should work with varint columns" do
354
376
  model.varint_value = "1"
355
- model.varint_value.should == 1
377
+ expect(model.varint_value).to eq(1)
356
378
  model.varint_value = 2
357
- model.varint_value.should == 2
379
+ expect(model.varint_value).to eq(2)
358
380
  model.save
359
381
  id = model.id
360
- model = Cassie::TypeTester.find(:id => id)
361
- model.varint_value.should == 2
382
+ model = Cassie::TypeTester.find(id: id)
383
+ expect(model.varint_value).to eq(2)
362
384
 
363
385
  model.varint_value = nil
364
- model.varint_value.should == nil
386
+ expect(model.varint_value).to eq(nil)
365
387
  model.save
366
- model = Cassie::TypeTester.find(:id => id)
367
- model.varint_value.should == nil
388
+ model = Cassie::TypeTester.find(id: id)
389
+ expect(model.varint_value).to eq(nil)
368
390
  end
369
-
391
+
370
392
  it "should work with float columns" do
371
393
  model.float_value = "1.1"
372
- model.float_value.should == 1.1
394
+ expect(model.float_value).to eq(1.1)
373
395
  model.float_value = 2.2
374
- model.float_value.should == 2.2
396
+ expect(model.float_value).to eq(2.2)
375
397
  model.save
376
398
  id = model.id
377
- model = Cassie::TypeTester.find(:id => id)
378
- model.float_value.round(4).should == 2.2
399
+ model = Cassie::TypeTester.find(id: id)
400
+ expect(model.float_value.round(4)).to eq(2.2)
379
401
 
380
402
  model.float_value = nil
381
- model.float_value.should == nil
403
+ expect(model.float_value).to eq(nil)
382
404
  model.save
383
- model = Cassie::TypeTester.find(:id => id)
384
- model.float_value.should == nil
405
+ model = Cassie::TypeTester.find(id: id)
406
+ expect(model.float_value).to eq(nil)
385
407
  end
386
-
408
+
387
409
  it "should work with double columns" do
388
410
  model.double_value = "1.1"
389
- model.double_value.should == 1.1
411
+ expect(model.double_value).to eq(1.1)
390
412
  model.double_value = 2.2
391
- model.double_value.should == 2.2
413
+ expect(model.double_value).to eq(2.2)
392
414
  model.save
393
415
  id = model.id
394
- model = Cassie::TypeTester.find(:id => id)
395
- model.double_value.should == 2.2
416
+ model = Cassie::TypeTester.find(id: id)
417
+ expect(model.double_value).to eq(2.2)
396
418
 
397
419
  model.double_value = nil
398
- model.double_value.should == nil
420
+ expect(model.double_value).to eq(nil)
399
421
  model.save
400
- model = Cassie::TypeTester.find(:id => id)
401
- model.double_value.should == nil
422
+ model = Cassie::TypeTester.find(id: id)
423
+ expect(model.double_value).to eq(nil)
402
424
  end
403
-
425
+
404
426
  it "should work with decimal columns" do
405
427
  model.decimal_value = "1.1"
406
- model.decimal_value.should == 1.1
407
- model.decimal_value.should be_a(BigDecimal)
408
- model.decimal_value = BigDecimal.new("3.3", 2)
409
- model.decimal_value.should == BigDecimal.new("3.3", 2)
428
+ expect(model.decimal_value).to eq(1.1)
429
+ expect(model.decimal_value).to be_a(BigDecimal)
430
+ model.decimal_value = BigDecimal("3.3", 2)
431
+ expect(model.decimal_value).to eq(BigDecimal("3.3", 2))
410
432
  model.save
411
433
  id = model.id
412
- model = Cassie::TypeTester.find(:id => id)
413
- model.decimal_value.should == BigDecimal.new("3.3", 2)
434
+ model = Cassie::TypeTester.find(id: id)
435
+ expect(model.decimal_value).to eq(BigDecimal("3.3", 2))
414
436
 
415
437
  model.decimal_value = nil
416
- model.decimal_value.should == nil
438
+ expect(model.decimal_value).to eq(nil)
417
439
  model.save
418
- model = Cassie::TypeTester.find(:id => id)
419
- model.decimal_value.should == nil
440
+ model = Cassie::TypeTester.find(id: id)
441
+ expect(model.decimal_value).to eq(nil)
420
442
  end
421
-
443
+
422
444
  it "should work with timestamp columns" do
423
445
  model.timestamp_value = "2015-04-23T15:23:30"
424
- model.timestamp_value.should == Time.new(2015, 4, 23, 15, 23, 30)
446
+ expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 23, 30))
425
447
  model.timestamp_value = Time.new(2015, 4, 23, 15, 25, 30)
426
- model.timestamp_value.should == Time.new(2015, 4, 23, 15, 25, 30)
448
+ expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 25, 30))
427
449
  model.save
428
450
  id = model.id
429
- model = Cassie::TypeTester.find(:id => id)
430
- model.timestamp_value.should == Time.new(2015, 4, 23, 15, 25, 30)
451
+ model = Cassie::TypeTester.find(id: id)
452
+ expect(model.timestamp_value).to eq(Time.new(2015, 4, 23, 15, 25, 30))
431
453
 
432
454
  model.timestamp_value = nil
433
- model.timestamp_value.should == nil
455
+ expect(model.timestamp_value).to eq(nil)
434
456
  model.save
435
- model = Cassie::TypeTester.find(:id => id)
436
- model.timestamp_value.should == nil
457
+ model = Cassie::TypeTester.find(id: id)
458
+ expect(model.timestamp_value).to eq(nil)
437
459
  end
438
-
460
+
439
461
  it "should work with boolean columns" do
440
462
  model.boolean_value = true
441
- model.boolean_value.should == true
463
+ expect(model.boolean_value).to eq(true)
442
464
  model.boolean_value = false
443
- model.boolean_value.should == false
465
+ expect(model.boolean_value).to eq(false)
444
466
  model.save
445
467
  id = model.id
446
- model = Cassie::TypeTester.find(:id => id)
447
- model.boolean_value.should == false
468
+ model = Cassie::TypeTester.find(id: id)
469
+ expect(model.boolean_value).to eq(false)
448
470
 
449
471
  model.boolean_value = nil
450
- model.boolean_value.should == nil
472
+ expect(model.boolean_value).to eq(nil)
451
473
  model.save
452
- model = Cassie::TypeTester.find(:id => id)
453
- model.boolean_value.should == nil
474
+ model = Cassie::TypeTester.find(id: id)
475
+ expect(model.boolean_value).to eq(nil)
454
476
  end
455
-
477
+
456
478
  it "should work with inet columns" do
457
479
  model.inet_value = "127.0.0.1"
458
- model.inet_value.should == IPAddr.new("127.0.0.1")
480
+ expect(model.inet_value).to eq(IPAddr.new("127.0.0.1"))
459
481
  model.inet_value = IPAddr.new("10.1.0.1")
460
- model.inet_value.should == IPAddr.new("10.1.0.1")
482
+ expect(model.inet_value).to eq(IPAddr.new("10.1.0.1"))
461
483
  model.save
462
484
  id = model.id
463
- model = Cassie::TypeTester.find(:id => id)
464
- model.inet_value.should == IPAddr.new("10.1.0.1")
465
-
485
+ model = Cassie::TypeTester.find(id: id)
486
+ expect(model.inet_value).to eq(IPAddr.new("10.1.0.1"))
487
+
466
488
  model.inet_value = nil
467
- model.inet_value.should == nil
489
+ expect(model.inet_value).to eq(nil)
468
490
  model.save
469
- model = Cassie::TypeTester.find(:id => id)
470
- model.inet_value.should == nil
491
+ model = Cassie::TypeTester.find(id: id)
492
+ expect(model.inet_value).to eq(nil)
471
493
  end
472
-
494
+
473
495
  it "should work with uuid columns" do
474
496
  model.uuid_value = "eed6d678-ea0b-11e4-8772-793f91a64daf"
475
- model.uuid_value.should == Cassandra::Uuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf")
497
+ expect(model.uuid_value).to eq(Cassandra::Uuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf"))
476
498
  model.uuid_value = Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
477
- model.uuid_value.should == Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
499
+ expect(model.uuid_value).to eq(Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
478
500
  model.save
479
501
  id = model.id
480
- model = Cassie::TypeTester.find(:id => id)
481
- model.uuid_value.should == Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
502
+ model = Cassie::TypeTester.find(id: id)
503
+ expect(model.uuid_value).to eq(Cassandra::Uuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
482
504
 
483
505
  model.uuid_value = nil
484
- model.uuid_value.should == nil
506
+ expect(model.uuid_value).to eq(nil)
485
507
  model.save
486
- model = Cassie::TypeTester.find(:id => id)
487
- model.uuid_value.should == nil
508
+ model = Cassie::TypeTester.find(id: id)
509
+ expect(model.uuid_value).to eq(nil)
488
510
  end
489
-
511
+
490
512
  it "should work with timeuuid columns" do
491
513
  model.timeuuid_value = "eed6d678-ea0b-11e4-8772-793f91a64daf"
492
- model.timeuuid_value.should == Cassandra::TimeUuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf")
514
+ expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("eed6d678-ea0b-11e4-8772-793f91a64daf"))
493
515
  model.timeuuid_value = Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
494
- model.timeuuid_value.should == Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
516
+ expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
495
517
  model.save
496
518
  id = model.id
497
- model = Cassie::TypeTester.find(:id => id)
498
- model.timeuuid_value.should == Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf")
519
+ model = Cassie::TypeTester.find(id: id)
520
+ expect(model.timeuuid_value).to eq(Cassandra::TimeUuid.new("fed6d678-ea0b-11e4-8772-793f91a64daf"))
499
521
 
500
522
  model.timeuuid_value = nil
501
- model.timeuuid_value.should == nil
523
+ expect(model.timeuuid_value).to eq(nil)
502
524
  model.save
503
- model = Cassie::TypeTester.find(:id => id)
504
- model.timeuuid_value.should == nil
525
+ model = Cassie::TypeTester.find(id: id)
526
+ expect(model.timeuuid_value).to eq(nil)
505
527
  end
506
-
528
+
507
529
  it "should work with list columns" do
508
530
  model.list_value = ["a", "b", "c"]
509
- model.list_value.should == ["a", "b", "c"]
531
+ expect(model.list_value).to eq(["a", "b", "c"])
510
532
  model.save
511
533
  id = model.id
512
- model = Cassie::TypeTester.find(:id => id)
513
- model.list_value.should == ["a", "b", "c"]
534
+ model = Cassie::TypeTester.find(id: id)
535
+ expect(model.list_value).to eq(["a", "b", "c"])
514
536
 
515
537
  model.list_value = nil
516
- model.list_value.should == nil
538
+ expect(model.list_value).to eq(nil)
517
539
  model.save
518
- model = Cassie::TypeTester.find(:id => id)
519
- model.list_value.should == nil
540
+ model = Cassie::TypeTester.find(id: id)
541
+ expect(model.list_value).to eq(nil)
520
542
  end
521
-
543
+
522
544
  it "should work with set columns" do
523
545
  model.set_value = ["a", "b", "c", "a"]
524
- model.set_value.should == ["a", "b", "c"].to_set
546
+ expect(model.set_value).to eq(["a", "b", "c"].to_set)
525
547
  model.save
526
548
  id = model.id
527
- model = Cassie::TypeTester.find(:id => id)
528
- model.set_value.should == ["a", "b", "c"].to_set
549
+ model = Cassie::TypeTester.find(id: id)
550
+ expect(model.set_value).to eq(["a", "b", "c"].to_set)
529
551
 
530
552
  model.set_value = nil
531
- model.set_value.should == nil
553
+ expect(model.set_value).to eq(nil)
532
554
  model.save
533
- model = Cassie::TypeTester.find(:id => id)
534
- model.set_value.should == nil
555
+ model = Cassie::TypeTester.find(id: id)
556
+ expect(model.set_value).to eq(nil)
535
557
  end
536
-
558
+
537
559
  it "should work with map columns" do
538
560
  model.map_value = [["a", "b"], ["c", "d"]]
539
- model.map_value.should == {"a" => "b", "c" => "d"}
561
+ expect(model.map_value).to eq({"a" => "b", "c" => "d"})
540
562
  model.map_value = {"e" => "f", "g" => "h"}
541
- model.map_value.should == {"e" => "f", "g" => "h"}
563
+ expect(model.map_value).to eq({"e" => "f", "g" => "h"})
542
564
  model.save
543
565
  id = model.id
544
- model = Cassie::TypeTester.find(:id => id)
545
- model.map_value.should == {"e" => "f", "g" => "h"}
566
+ model = Cassie::TypeTester.find(id: id)
567
+ expect(model.map_value).to eq({"e" => "f", "g" => "h"})
546
568
 
547
569
  model.map_value = nil
548
- model.map_value.should == nil
570
+ expect(model.map_value).to eq(nil)
549
571
  model.save
550
- model = Cassie::TypeTester.find(:id => id)
551
- model.map_value.should == nil
572
+ model = Cassie::TypeTester.find(id: id)
573
+ expect(model.map_value).to eq(nil)
552
574
  end
553
-
575
+
554
576
  it "should work with counter columns" do
555
577
  id = SecureRandom.uuid
556
- model = Cassie::TypeTesterCounter.new(:id => id)
557
- model.counter_value.should == 0
578
+ model = Cassie::TypeTesterCounter.new(id: id)
579
+ expect(model.counter_value).to eq(0)
558
580
  model.increment_counter_value!
559
- model.counter_value.should == 1
560
- model = Cassie::TypeTesterCounter.find(:id => id)
561
- model.counter_value.should == 1
581
+ expect(model.counter_value).to eq(1)
582
+ model = Cassie::TypeTesterCounter.find(id: id)
583
+ expect(model.counter_value).to eq(1)
562
584
 
563
585
  model.increment_counter_value!
564
- model.counter_value.should == 2
565
- model = Cassie::TypeTesterCounter.find(:id => id)
566
- model.counter_value.should == 2
567
-
586
+ expect(model.counter_value).to eq(2)
587
+ model = Cassie::TypeTesterCounter.find(id: id)
588
+ expect(model.counter_value).to eq(2)
589
+
568
590
  model.decrement_counter_value!
569
- model.counter_value.should == 1
570
- model = Cassie::TypeTesterCounter.find(:id => id)
571
- model.counter_value.should == 1
591
+ expect(model.counter_value).to eq(1)
592
+ model = Cassie::TypeTesterCounter.find(id: id)
593
+ expect(model.counter_value).to eq(1)
572
594
  end
573
595
  end
574
596
  end