cequel 1.10.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +93 -65
- data/README.md +26 -5
- data/Vagrantfile +2 -2
- data/lib/cequel/errors.rb +2 -0
- data/lib/cequel/instrumentation.rb +5 -4
- data/lib/cequel/metal/batch.rb +21 -18
- data/lib/cequel/metal/data_set.rb +17 -28
- data/lib/cequel/metal/inserter.rb +3 -2
- data/lib/cequel/metal/keyspace.rb +56 -33
- data/lib/cequel/metal/request_logger.rb +22 -8
- data/lib/cequel/metal/row_specification.rb +9 -8
- data/lib/cequel/metal/statement.rb +23 -7
- data/lib/cequel/metal/updater.rb +12 -10
- data/lib/cequel/metal/writer.rb +5 -13
- data/lib/cequel/record/association_collection.rb +6 -33
- data/lib/cequel/record/collection.rb +2 -1
- data/lib/cequel/record/errors.rb +6 -0
- data/lib/cequel/record/persistence.rb +2 -2
- data/lib/cequel/record/record_set.rb +3 -4
- data/lib/cequel/record/validations.rb +5 -5
- data/lib/cequel/schema/table.rb +3 -5
- data/lib/cequel/schema/table_reader.rb +73 -111
- data/lib/cequel/schema/table_updater.rb +9 -15
- data/lib/cequel/version.rb +1 -1
- data/spec/examples/metal/data_set_spec.rb +34 -46
- data/spec/examples/metal/keyspace_spec.rb +8 -6
- data/spec/examples/record/associations_spec.rb +8 -18
- data/spec/examples/record/persistence_spec.rb +6 -6
- data/spec/examples/record/record_set_spec.rb +39 -12
- data/spec/examples/record/timestamps_spec.rb +12 -5
- data/spec/examples/schema/keyspace_spec.rb +13 -37
- data/spec/examples/schema/table_reader_spec.rb +4 -1
- data/spec/examples/schema/table_updater_spec.rb +22 -7
- data/spec/examples/schema/table_writer_spec.rb +2 -3
- data/spec/examples/spec_helper.rb +1 -0
- data/spec/examples/spec_support/preparation_spec.rb +14 -7
- metadata +7 -8
@@ -100,7 +100,7 @@ module Cequel
|
|
100
100
|
# Altering column types is not recommended.
|
101
101
|
#
|
102
102
|
def change_column(name, type)
|
103
|
-
|
103
|
+
add_stmt %Q|ALTER TABLE "#{table_name}" ALTER "#{name}" TYPE #{type}|
|
104
104
|
end
|
105
105
|
|
106
106
|
#
|
@@ -111,7 +111,7 @@ module Cequel
|
|
111
111
|
# @return [void]
|
112
112
|
#
|
113
113
|
def rename_column(old_name, new_name)
|
114
|
-
|
114
|
+
add_stmt %Q|ALTER TABLE "#{table_name}" RENAME "#{old_name}" TO "#{new_name}"|
|
115
115
|
end
|
116
116
|
|
117
117
|
#
|
@@ -125,7 +125,7 @@ module Cequel
|
|
125
125
|
def change_properties(options)
|
126
126
|
properties = options
|
127
127
|
.map { |name, value| TableProperty.build(name, value).to_cql }
|
128
|
-
|
128
|
+
add_stmt %Q|ALTER TABLE "#{table_name}" WITH #{properties.join(' AND ')}|
|
129
129
|
end
|
130
130
|
|
131
131
|
#
|
@@ -136,10 +136,8 @@ module Cequel
|
|
136
136
|
# convention if nil
|
137
137
|
# @return [void]
|
138
138
|
#
|
139
|
-
def create_index(column_name, index_name =
|
140
|
-
index_name
|
141
|
-
statements <<
|
142
|
-
"CREATE INDEX #{index_name} ON #{table_name} (#{column_name})"
|
139
|
+
def create_index(column_name, index_name = "#{table_name}_#{column_name}_idx")
|
140
|
+
add_stmt %Q|CREATE INDEX "#{index_name}" ON "#{table_name}" ("#{column_name}")|
|
143
141
|
end
|
144
142
|
|
145
143
|
#
|
@@ -149,12 +147,12 @@ module Cequel
|
|
149
147
|
# @return [void]
|
150
148
|
#
|
151
149
|
def drop_index(index_name)
|
152
|
-
|
150
|
+
add_stmt %Q|DROP INDEX IF EXISTS "#{index_name}"|
|
153
151
|
end
|
154
152
|
|
155
153
|
# @!visibility protected
|
156
154
|
def add_data_column(column)
|
157
|
-
|
155
|
+
add_stmt(%Q|ALTER TABLE #{table_name} ADD #{column.to_cql}|)
|
158
156
|
end
|
159
157
|
|
160
158
|
protected
|
@@ -163,12 +161,8 @@ module Cequel
|
|
163
161
|
|
164
162
|
private
|
165
163
|
|
166
|
-
def
|
167
|
-
statements <<
|
168
|
-
end
|
169
|
-
|
170
|
-
def add_column_statement(column)
|
171
|
-
alter_table("ADD #{column.to_cql}")
|
164
|
+
def add_stmt(cql)
|
165
|
+
statements << Cequel::Metal::Statement.new(cql)
|
172
166
|
end
|
173
167
|
|
174
168
|
def type(type)
|
data/lib/cequel/version.rb
CHANGED
@@ -85,7 +85,7 @@ describe Cequel::Metal::DataSet do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should insert row with given consistency' do
|
88
|
-
expect_query_with_consistency(/INSERT
|
88
|
+
expect_query_with_consistency(->(s){/INSERT/ === s.cql}, :one) do
|
89
89
|
cequel[:posts].insert(row, consistency: :one)
|
90
90
|
end
|
91
91
|
end
|
@@ -125,7 +125,7 @@ describe Cequel::Metal::DataSet do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should send update statement with given consistency' do
|
128
|
-
expect_query_with_consistency(/UPDATE
|
128
|
+
expect_query_with_consistency(->(s){/UPDATE/ === s.cql}, :one) do
|
129
129
|
cequel[:posts].where(row_keys).update(
|
130
130
|
{title: 'Marshmallows'}, consistency: :one)
|
131
131
|
end
|
@@ -191,14 +191,21 @@ describe Cequel::Metal::DataSet do
|
|
191
191
|
)
|
192
192
|
end
|
193
193
|
|
194
|
+
# breaks in Cassandra 2.0.13+ or 2.1.3+ because reverse order bug was fixed:
|
195
|
+
# https://issues.apache.org/jira/browse/CASSANDRA-8733
|
194
196
|
it 'should prepend multiple elements to list column' do
|
195
197
|
cequel[:posts].insert(
|
196
198
|
row_keys.merge(categories: ['Big Data', 'Cassandra']))
|
197
199
|
cequel[:posts].where(row_keys).
|
198
200
|
list_prepend(:categories, ['Scalability', 'Partition Tolerance'])
|
199
|
-
|
201
|
+
|
202
|
+
expected = if cequel.bug8733_version?
|
200
203
|
['Partition Tolerance', 'Scalability', 'Big Data', 'Cassandra']
|
201
|
-
|
204
|
+
else
|
205
|
+
['Scalability', 'Partition Tolerance', 'Big Data', 'Cassandra']
|
206
|
+
end
|
207
|
+
|
208
|
+
expect(cequel[:posts].where(row_keys).first[:categories]).to eq(expected)
|
202
209
|
end
|
203
210
|
end
|
204
211
|
|
@@ -268,9 +275,9 @@ describe Cequel::Metal::DataSet do
|
|
268
275
|
end
|
269
276
|
|
270
277
|
it 'should add multiple elements to set' do
|
271
|
-
cequel[:posts].insert(
|
272
|
-
row_keys.merge(tags: Set['big-data', 'nosql']))
|
278
|
+
cequel[:posts].insert(row_keys.merge(tags: Set['big-data', 'nosql']))
|
273
279
|
cequel[:posts].where(row_keys).set_add(:tags, 'cassandra')
|
280
|
+
|
274
281
|
expect(cequel[:posts].where(row_keys).first[:tags]).
|
275
282
|
to eq(Set['big-data', 'nosql', 'cassandra'])
|
276
283
|
end
|
@@ -379,7 +386,7 @@ describe Cequel::Metal::DataSet do
|
|
379
386
|
end
|
380
387
|
|
381
388
|
it 'should send delete with specified consistency' do
|
382
|
-
expect_query_with_consistency(/DELETE
|
389
|
+
expect_query_with_consistency(->(s){/DELETE/ === s.cql}, :one) do
|
383
390
|
cequel[:posts].where(row_keys).delete(:body, :consistency => :one)
|
384
391
|
end
|
385
392
|
end
|
@@ -429,7 +436,7 @@ describe Cequel::Metal::DataSet do
|
|
429
436
|
|
430
437
|
describe '#cql' do
|
431
438
|
it 'should generate select statement with all columns' do
|
432
|
-
expect(cequel[:posts].cql).to eq(
|
439
|
+
expect(cequel[:posts].cql.to_s).to eq('SELECT * FROM posts')
|
433
440
|
end
|
434
441
|
end
|
435
442
|
|
@@ -504,8 +511,7 @@ describe Cequel::Metal::DataSet do
|
|
504
511
|
title: 'Bogus Post',
|
505
512
|
))
|
506
513
|
expect(cequel[:posts].where(
|
507
|
-
:blog_subdomain => %w(cassandra big-data-weekly)
|
508
|
-
:permalink => 'big-data'
|
514
|
+
:blog_subdomain => %w(cassandra big-data-weekly)
|
509
515
|
).map { |row| row[:title] }).to match_array(['Big Data', 'Cassandra'])
|
510
516
|
end
|
511
517
|
|
@@ -584,33 +590,29 @@ describe Cequel::Metal::DataSet do
|
|
584
590
|
let(:data_set) { cequel[:posts].consistency(:one) }
|
585
591
|
|
586
592
|
it 'should issue SELECT with scoped consistency' do
|
587
|
-
expect_query_with_consistency(
|
588
|
-
end
|
589
|
-
|
590
|
-
it 'should issue COUNT with scoped consistency' do
|
591
|
-
expect_query_with_consistency(/SELECT.*COUNT/, :one) { data_set.count }
|
593
|
+
expect_query_with_consistency(anything, :one) { data_set.to_a }
|
592
594
|
end
|
593
595
|
|
594
596
|
it 'should issue INSERT with scoped consistency' do
|
595
|
-
expect_query_with_consistency(
|
597
|
+
expect_query_with_consistency(anything, :one) do
|
596
598
|
data_set.insert(row_keys)
|
597
599
|
end
|
598
600
|
end
|
599
601
|
|
600
602
|
it 'should issue UPDATE with scoped consistency' do
|
601
|
-
expect_query_with_consistency(
|
603
|
+
expect_query_with_consistency(anything, :one) do
|
602
604
|
data_set.where(row_keys).update(title: 'Marshmallows')
|
603
605
|
end
|
604
606
|
end
|
605
607
|
|
606
608
|
it 'should issue DELETE with scoped consistency' do
|
607
|
-
expect_query_with_consistency(
|
609
|
+
expect_query_with_consistency(anything, :one) do
|
608
610
|
data_set.where(row_keys).delete
|
609
611
|
end
|
610
612
|
end
|
611
613
|
|
612
614
|
it 'should issue DELETE column with scoped consistency' do
|
613
|
-
expect_query_with_consistency(
|
615
|
+
expect_query_with_consistency(anything, :one) do
|
614
616
|
data_set.where(row_keys).delete(:title)
|
615
617
|
end
|
616
618
|
end
|
@@ -622,33 +624,29 @@ describe Cequel::Metal::DataSet do
|
|
622
624
|
let(:data_set) { cequel[:posts] }
|
623
625
|
|
624
626
|
it 'should issue SELECT with default consistency' do
|
625
|
-
expect_query_with_consistency(
|
626
|
-
end
|
627
|
-
|
628
|
-
it 'should issue COUNT with default consistency' do
|
629
|
-
expect_query_with_consistency(/SELECT.*COUNT/, :all) { data_set.count }
|
627
|
+
expect_query_with_consistency(anything, :all) { data_set.to_a }
|
630
628
|
end
|
631
629
|
|
632
630
|
it 'should issue INSERT with default consistency' do
|
633
|
-
expect_query_with_consistency(
|
631
|
+
expect_query_with_consistency(anything, :all) do
|
634
632
|
data_set.insert(row_keys)
|
635
633
|
end
|
636
634
|
end
|
637
635
|
|
638
636
|
it 'should issue UPDATE with default consistency' do
|
639
|
-
expect_query_with_consistency(
|
637
|
+
expect_query_with_consistency(anything, :all) do
|
640
638
|
data_set.where(row_keys).update(title: 'Marshmallows')
|
641
639
|
end
|
642
640
|
end
|
643
641
|
|
644
642
|
it 'should issue DELETE with default consistency' do
|
645
|
-
expect_query_with_consistency(
|
643
|
+
expect_query_with_consistency(anything, :all) do
|
646
644
|
data_set.where(row_keys).delete
|
647
645
|
end
|
648
646
|
end
|
649
647
|
|
650
648
|
it 'should issue DELETE column with default consistency' do
|
651
|
-
expect_query_with_consistency(
|
649
|
+
expect_query_with_consistency(anything, :all) do
|
652
650
|
data_set.where(row_keys).delete(:title)
|
653
651
|
end
|
654
652
|
end
|
@@ -658,11 +656,7 @@ describe Cequel::Metal::DataSet do
|
|
658
656
|
let(:data_set) { cequel[:posts].page_size(1) }
|
659
657
|
|
660
658
|
it 'should issue SELECT with scoped page size' do
|
661
|
-
expect_query_with_options(/SELECT
|
662
|
-
end
|
663
|
-
|
664
|
-
it 'should issue COUNT with scoped page size' do
|
665
|
-
expect_query_with_options(/SELECT.*COUNT/, :page_size => 1) { data_set.count }
|
659
|
+
expect_query_with_options(->(s){/SELECT/ === s.cql}, :page_size => 1) { data_set.to_a }
|
666
660
|
end
|
667
661
|
end
|
668
662
|
|
@@ -670,11 +664,7 @@ describe Cequel::Metal::DataSet do
|
|
670
664
|
let(:data_set) { cequel[:posts].paging_state(nil) }
|
671
665
|
|
672
666
|
it 'should issue SELECT with scoped paging state' do
|
673
|
-
expect_query_with_options(/SELECT
|
674
|
-
end
|
675
|
-
|
676
|
-
it 'should issue COUNT with scoped paging state' do
|
677
|
-
expect_query_with_options(/SELECT.*COUNT/, :paging_state => nil) { data_set.count }
|
667
|
+
expect_query_with_options(->(s){/SELECT/ === s.cql}, :paging_state => nil) { data_set.to_a }
|
678
668
|
end
|
679
669
|
end
|
680
670
|
|
@@ -728,18 +718,16 @@ describe Cequel::Metal::DataSet do
|
|
728
718
|
end
|
729
719
|
end
|
730
720
|
|
731
|
-
it 'should
|
732
|
-
expect
|
721
|
+
it 'should raise DangerousQueryError when attempting to count' do
|
722
|
+
expect{ cequel[:posts].count }.to raise_error(Cequel::Record::DangerousQueryError)
|
733
723
|
end
|
734
724
|
|
735
|
-
it 'should
|
736
|
-
expect
|
737
|
-
count).to eq(1)
|
725
|
+
it 'should raise DangerousQueryError when attempting to access size' do
|
726
|
+
expect{ cequel[:posts].size }.to raise_error(Cequel::Record::DangerousQueryError)
|
738
727
|
end
|
739
728
|
|
740
|
-
it 'should
|
741
|
-
expect
|
729
|
+
it 'should raise DangerousQueryError when attempting to access length' do
|
730
|
+
expect{ cequel[:posts].length }.to raise_error(Cequel::Record::DangerousQueryError)
|
742
731
|
end
|
743
732
|
end
|
744
|
-
|
745
733
|
end
|
@@ -35,9 +35,9 @@ describe Cequel::Metal::Keyspace do
|
|
35
35
|
it 'should auto-apply if option given' do
|
36
36
|
cequel.batch(auto_apply: 2) do
|
37
37
|
cequel[:posts].insert(id: 1, title: 'One')
|
38
|
-
expect(cequel[:posts].count).to be_zero
|
38
|
+
expect(cequel[:posts].to_a.count).to be_zero
|
39
39
|
cequel[:posts].insert(id: 2, title: 'Two')
|
40
|
-
expect(cequel[:posts].count).to be(2)
|
40
|
+
expect(cequel[:posts].to_a.count).to be(2)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -46,7 +46,7 @@ describe Cequel::Metal::Keyspace do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should execute unlogged batch if specified' do
|
49
|
-
expect_query_with_consistency(
|
49
|
+
expect_query_with_consistency(instance_of(Cassandra::Statements::Batch::Unlogged), anything) do
|
50
50
|
cequel.batch(unlogged: true) do
|
51
51
|
cequel[:posts].insert(id: 1, title: 'One')
|
52
52
|
cequel[:posts].insert(id: 2, title: 'Two')
|
@@ -55,7 +55,7 @@ describe Cequel::Metal::Keyspace do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should execute batch with given consistency' do
|
58
|
-
expect_query_with_consistency(
|
58
|
+
expect_query_with_consistency(instance_of(Cassandra::Statements::Batch::Logged), :one) do
|
59
59
|
cequel.batch(consistency: :one) do
|
60
60
|
cequel[:posts].insert(id: 1, title: 'One')
|
61
61
|
cequel[:posts].insert(id: 2, title: 'Two')
|
@@ -127,8 +127,10 @@ describe Cequel::Metal::Keyspace do
|
|
127
127
|
|
128
128
|
context "with a connection error" do
|
129
129
|
it "reconnects to cassandra with a new client after first failed connection" do
|
130
|
-
allow(cequel.client)
|
131
|
-
.
|
130
|
+
allow(cequel.client)
|
131
|
+
.to receive(:execute)
|
132
|
+
.with(->(s){ s.cql == statement},
|
133
|
+
hash_including(:consistency => cequel.default_consistency))
|
132
134
|
.and_raise(Ione::Io::ConnectionError)
|
133
135
|
.once
|
134
136
|
|
@@ -297,26 +297,16 @@ describe Cequel::Record::Associations do
|
|
297
297
|
expect(blog.posts.first.title).to eq('Post 0')
|
298
298
|
end
|
299
299
|
|
300
|
-
it 'should
|
301
|
-
blog.posts.
|
302
|
-
posts.first.destroy
|
303
|
-
expect(blog.posts.count).to eq(2)
|
300
|
+
it 'should raise DangerousQueryError for #count' do
|
301
|
+
expect{ blog.posts.count }.to raise_error(Cequel::Record::DangerousQueryError)
|
304
302
|
end
|
305
303
|
|
306
|
-
it 'should
|
307
|
-
expect
|
308
|
-
expect(blog.posts).to be_loaded
|
304
|
+
it 'should raise DangerousQueryError for #length' do
|
305
|
+
expect{ blog.posts.length }.to raise_error(Cequel::Record::DangerousQueryError)
|
309
306
|
end
|
310
307
|
|
311
|
-
it 'should
|
312
|
-
expect
|
313
|
-
expect(blog.posts).not_to be_loaded
|
314
|
-
end
|
315
|
-
|
316
|
-
it 'should count records in memory for #size if loaded' do
|
317
|
-
blog.posts.entries
|
318
|
-
disallow_queries!
|
319
|
-
expect(blog.posts.size).to eq(3)
|
308
|
+
it 'should raise DangerousQueryError for #size' do
|
309
|
+
expect{ blog.posts.size }.to raise_error(Cequel::Record::DangerousQueryError)
|
320
310
|
end
|
321
311
|
|
322
312
|
it "does not allow invalid :dependent options" do
|
@@ -350,7 +340,7 @@ describe Cequel::Record::Associations do
|
|
350
340
|
it "deletes all children when destroying the parent" do
|
351
341
|
expect {
|
352
342
|
post_with_comments.destroy
|
353
|
-
}.to change { Comment.count }.by(-2)
|
343
|
+
}.to change { Comment.all.to_a.count }.by(-2)
|
354
344
|
end
|
355
345
|
|
356
346
|
it "executes :destroy callbacks on the children" do
|
@@ -375,7 +365,7 @@ describe Cequel::Record::Associations do
|
|
375
365
|
it "deletes all children when destroying the parent" do
|
376
366
|
expect {
|
377
367
|
post_with_attachments.destroy
|
378
|
-
}.to change { Attachment.count }.by(-2)
|
368
|
+
}.to change { Attachment.all.to_a.count }.by(-2)
|
379
369
|
end
|
380
370
|
|
381
371
|
it "does not execute :destroy callbacks on the children" do
|
@@ -50,7 +50,7 @@ describe Cequel::Record::Persistence do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should save with specified consistency' do
|
53
|
-
expect_query_with_consistency(
|
53
|
+
expect_query_with_consistency(anything, :one) do
|
54
54
|
Blog.new do |blog|
|
55
55
|
blog.subdomain = 'cequel'
|
56
56
|
blog.name = 'Cequel'
|
@@ -119,7 +119,7 @@ describe Cequel::Record::Persistence do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'should save with specified consistency' do
|
122
|
-
expect_query_with_consistency(
|
122
|
+
expect_query_with_consistency(anything, :one) do
|
123
123
|
blog.name = 'Cequel'
|
124
124
|
blog.save(consistency: :one)
|
125
125
|
end
|
@@ -148,7 +148,7 @@ describe Cequel::Record::Persistence do
|
|
148
148
|
|
149
149
|
it 'should not mark itself as clean if save failed at Cassandra level' do
|
150
150
|
blog.name = 'Pizza'
|
151
|
-
with_client_error(Cassandra::Errors::InvalidError.new(
|
151
|
+
with_client_error(Cassandra::Errors::InvalidError.new(nil, nil, nil, nil, nil, nil, nil, nil, nil)) do
|
152
152
|
begin
|
153
153
|
blog.save
|
154
154
|
rescue Cassandra::Errors::InvalidError
|
@@ -243,14 +243,14 @@ describe Cequel::Record::Persistence do
|
|
243
243
|
|
244
244
|
it 'should destroy with specified consistency' do
|
245
245
|
blog = Blog.create(:subdomain => 'big-data', :name => 'Big Data')
|
246
|
-
expect_query_with_consistency(
|
246
|
+
expect_query_with_consistency(anything, :one) do
|
247
247
|
blog.destroy(consistency: :one)
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
|
-
it 'should destroy
|
251
|
+
it 'should not destroy records without specified timestamp' do
|
252
252
|
blog = Blog.create(subdomain: 'big-data', name: 'Big Data')
|
253
|
-
blog.destroy(timestamp: 1.
|
253
|
+
blog.destroy(timestamp: 1.hour.ago)
|
254
254
|
expect(cequel[Blog.table_name].where(subdomain: 'big-data').first).to be
|
255
255
|
end
|
256
256
|
end
|
@@ -674,7 +674,11 @@ describe Cequel::Record::RecordSet do
|
|
674
674
|
let(:records) { blogs }
|
675
675
|
|
676
676
|
it 'should return the number of records requested' do
|
677
|
-
expect(Blog.limit(2).length).to be(2)
|
677
|
+
expect(Blog.limit(2).to_a.length).to be(2)
|
678
|
+
end
|
679
|
+
|
680
|
+
it 'should return the minimum of the requested limit and the actual record count' do
|
681
|
+
expect(Blog.limit(5).to_a.length).to be(3)
|
678
682
|
end
|
679
683
|
end
|
680
684
|
|
@@ -805,7 +809,7 @@ describe Cequel::Record::RecordSet do
|
|
805
809
|
|
806
810
|
describe '#consistency' do
|
807
811
|
it 'should perform query with specified consistency' do
|
808
|
-
expect_query_with_consistency(
|
812
|
+
expect_query_with_consistency(anything, :one) do
|
809
813
|
Post.consistency(:one).to_a
|
810
814
|
end
|
811
815
|
end
|
@@ -847,10 +851,34 @@ describe Cequel::Record::RecordSet do
|
|
847
851
|
end
|
848
852
|
|
849
853
|
describe '#count' do
|
850
|
-
let(:records) {
|
854
|
+
let(:records) { posts }
|
851
855
|
|
852
|
-
|
853
|
-
|
856
|
+
context 'without scoping' do
|
857
|
+
it 'should raise DangerousQueryError when attempting to count' do
|
858
|
+
expect{ Post.count }.to raise_error(Cequel::Record::DangerousQueryError)
|
859
|
+
end
|
860
|
+
|
861
|
+
it 'should raise DangerousQueryError when attempting to access size' do
|
862
|
+
expect{ Post.size }.to raise_error(Cequel::Record::DangerousQueryError)
|
863
|
+
end
|
864
|
+
|
865
|
+
it 'should raise DangerousQueryError when attempting to access length' do
|
866
|
+
expect{ Post.length }.to raise_error(Cequel::Record::DangerousQueryError)
|
867
|
+
end
|
868
|
+
end
|
869
|
+
|
870
|
+
context 'with scoping' do
|
871
|
+
it 'should raise DangerousQueryError when attempting to count' do
|
872
|
+
expect{ Post['postgres'].count }.to raise_error(Cequel::Record::DangerousQueryError)
|
873
|
+
end
|
874
|
+
|
875
|
+
it 'should raise DangerousQueryError when attempting to access size' do
|
876
|
+
expect{ Post['postgres'].size }.to raise_error(Cequel::Record::DangerousQueryError)
|
877
|
+
end
|
878
|
+
|
879
|
+
it 'should raise DangerousQueryError when attempting to access length' do
|
880
|
+
expect{ Post['postgres'].length }.to raise_error(Cequel::Record::DangerousQueryError)
|
881
|
+
end
|
854
882
|
end
|
855
883
|
end
|
856
884
|
|
@@ -895,13 +923,13 @@ describe Cequel::Record::RecordSet do
|
|
895
923
|
|
896
924
|
it 'should be able to delete with no scoping' do
|
897
925
|
Post.delete_all
|
898
|
-
expect(Post.
|
926
|
+
expect(Post.first).to be_nil
|
899
927
|
end
|
900
928
|
|
901
929
|
it 'should be able to delete with scoping' do
|
902
930
|
Post['postgres'].delete_all
|
903
|
-
expect(Post['postgres'].
|
904
|
-
expect(Post['cassandra'].count).to eq(cassandra_posts.length)
|
931
|
+
expect(Post['postgres'].first).to be_nil
|
932
|
+
expect(Post['cassandra'].to_a.count).to eq(cassandra_posts.length)
|
905
933
|
end
|
906
934
|
|
907
935
|
it 'should be able to delete fully specified collection' do
|
@@ -916,13 +944,13 @@ describe Cequel::Record::RecordSet do
|
|
916
944
|
|
917
945
|
it 'should be able to delete with no scoping' do
|
918
946
|
Post.destroy_all
|
919
|
-
expect(Post.
|
947
|
+
expect(Post.first).to be_nil
|
920
948
|
end
|
921
949
|
|
922
950
|
it 'should be able to delete with scoping' do
|
923
951
|
Post['postgres'].destroy_all
|
924
|
-
expect(Post['postgres'].
|
925
|
-
expect(Post['cassandra'].count).to eq(cassandra_posts.length)
|
952
|
+
expect(Post['postgres'].first).to be_nil
|
953
|
+
expect(Post['cassandra'].to_a.count).to eq(cassandra_posts.length)
|
926
954
|
end
|
927
955
|
|
928
956
|
it 'should be able to delete fully specified collection' do
|
@@ -974,5 +1002,4 @@ describe Cequel::Record::RecordSet do
|
|
974
1002
|
.to yield_successive_args *blog_1_views
|
975
1003
|
end
|
976
1004
|
end
|
977
|
-
|
978
1005
|
end
|