cequel 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +19 -12
- data/Rakefile +5 -1
- data/lib/cequel/record/data_set_builder.rb +9 -2
- data/lib/cequel/record/record_set.rb +16 -2
- data/lib/cequel/record/tasks.rb +6 -2
- data/lib/cequel/version.rb +1 -1
- data/spec/examples/metal/data_set_spec.rb +113 -106
- data/spec/examples/metal/keyspace_spec.rb +7 -15
- data/spec/examples/record/associations_spec.rb +30 -30
- data/spec/examples/record/callbacks_spec.rb +25 -25
- data/spec/examples/record/dirty_spec.rb +11 -10
- data/spec/examples/record/list_spec.rb +33 -33
- data/spec/examples/record/map_spec.rb +57 -41
- data/spec/examples/record/mass_assignment_spec.rb +5 -5
- data/spec/examples/record/naming_spec.rb +2 -2
- data/spec/examples/record/persistence_spec.rb +23 -23
- data/spec/examples/record/properties_spec.rb +19 -19
- data/spec/examples/record/record_set_spec.rb +155 -151
- data/spec/examples/record/schema_spec.rb +7 -7
- data/spec/examples/record/scoped_spec.rb +2 -2
- data/spec/examples/record/serialization_spec.rb +2 -2
- data/spec/examples/record/set_spec.rb +27 -23
- data/spec/examples/record/validations_spec.rb +13 -13
- data/spec/examples/schema/table_reader_spec.rb +85 -79
- data/spec/examples/schema/table_synchronizer_spec.rb +9 -9
- data/spec/examples/schema/table_updater_spec.rb +17 -17
- data/spec/examples/schema/table_writer_spec.rb +33 -33
- data/spec/examples/type_spec.rb +55 -55
- data/spec/support/helpers.rb +18 -10
- metadata +18 -5
- data/spec/shared/readable_dictionary.rb +0 -192
data/spec/support/helpers.rb
CHANGED
@@ -65,7 +65,7 @@ module Cequel
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.host
|
68
|
-
'127.0.0.1'
|
68
|
+
ENV['CEQUEL_TEST_HOST'] || '127.0.0.1'
|
69
69
|
end
|
70
70
|
|
71
71
|
def self.port
|
@@ -77,7 +77,14 @@ module Cequel
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def self.keyspace_name
|
80
|
-
ENV
|
80
|
+
ENV.fetch('CEQUEL_TEST_KEYSPACE') do
|
81
|
+
test_env_number = ENV['TEST_ENV_NUMBER']
|
82
|
+
if test_env_number.present?
|
83
|
+
"cequel_test_#{test_env_number}"
|
84
|
+
else
|
85
|
+
'cequel_test'
|
86
|
+
end
|
87
|
+
end
|
81
88
|
end
|
82
89
|
|
83
90
|
def self.legacy_connection
|
@@ -106,28 +113,29 @@ module Cequel
|
|
106
113
|
Helpers.legacy_connection
|
107
114
|
end
|
108
115
|
|
109
|
-
def
|
110
|
-
cequel.client.
|
116
|
+
def expect_statement_count(number)
|
117
|
+
allow(cequel.client).to receive(:execute).and_call_original
|
118
|
+
yield
|
119
|
+
expect(cequel.client).to have_received(:execute).exactly(number).times
|
111
120
|
end
|
112
121
|
|
113
122
|
def disallow_queries!
|
114
|
-
cequel.client.
|
123
|
+
expect(cequel.client).to_not receive(:execute)
|
115
124
|
end
|
116
125
|
|
117
126
|
def with_client_error(error)
|
118
|
-
cequel.client.
|
127
|
+
allow(cequel.client).to receive(:execute).once.and_raise(error)
|
119
128
|
begin
|
120
129
|
yield
|
121
130
|
ensure
|
122
|
-
cequel.client.
|
131
|
+
allow(cequel.client).to receive(:execute).and_call_original
|
123
132
|
end
|
124
133
|
end
|
125
134
|
|
126
135
|
def expect_query_with_consistency(matcher, consistency)
|
127
|
-
|
128
|
-
.and_call_original
|
136
|
+
allow(cequel.client).to receive(:execute).and_call_original
|
129
137
|
yield
|
130
|
-
|
138
|
+
expect(cequel.client).to have_received(:execute).with(matcher, consistency)
|
131
139
|
end
|
132
140
|
end
|
133
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -20,7 +20,7 @@ authors:
|
|
20
20
|
autorequire:
|
21
21
|
bindir: bin
|
22
22
|
cert_chain: []
|
23
|
-
date: 2014-
|
23
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
@@ -110,14 +110,28 @@ dependencies:
|
|
110
110
|
requirements:
|
111
111
|
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: '
|
113
|
+
version: '3.1'
|
114
114
|
type: :development
|
115
115
|
prerelease: false
|
116
116
|
version_requirements: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
118
|
- - "~>"
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version: '
|
120
|
+
version: '3.1'
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: rspec-its
|
123
|
+
requirement: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '1.0'
|
128
|
+
type: :development
|
129
|
+
prerelease: false
|
130
|
+
version_requirements: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - "~>"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '1.0'
|
121
135
|
- !ruby/object:Gem::Dependency
|
122
136
|
name: rubocop
|
123
137
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,7 +287,6 @@ files:
|
|
273
287
|
- spec/examples/spec_support/preparation_spec.rb
|
274
288
|
- spec/examples/type_spec.rb
|
275
289
|
- spec/examples/uuids_spec.rb
|
276
|
-
- spec/shared/readable_dictionary.rb
|
277
290
|
- spec/support/helpers.rb
|
278
291
|
- spec/support/result_stub.rb
|
279
292
|
- templates/config/cequel.yml
|
@@ -1,192 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
shared_examples 'readable dictionary' do
|
3
|
-
let(:uuid1) { uuid }
|
4
|
-
let(:uuid2) { uuid }
|
5
|
-
let(:uuid3) { uuid }
|
6
|
-
let(:cf) { dictionary.class.column_family.column_family }
|
7
|
-
|
8
|
-
context 'without row in memory' do
|
9
|
-
|
10
|
-
describe '#each_pair' do
|
11
|
-
|
12
|
-
it 'should load columns in batches and yield them' do
|
13
|
-
connection.should_receive(:execute).
|
14
|
-
with("SELECT FIRST 2 * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
|
15
|
-
and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
|
16
|
-
connection.should_receive(:execute).
|
17
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid2, '', :blog_id, 1).
|
18
|
-
and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
|
19
|
-
connection.should_receive(:execute).
|
20
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid3, '', :blog_id, 1).
|
21
|
-
and_return result_stub({'blog_id' => 1})
|
22
|
-
hash = {}
|
23
|
-
dictionary.each_pair do |key, value|
|
24
|
-
hash[key] = value
|
25
|
-
end
|
26
|
-
hash.should == {uuid1 => 1, uuid2 => 2, uuid3 => 3}
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#[]' do
|
32
|
-
|
33
|
-
it 'should load column from cassandra' do
|
34
|
-
connection.stub(:execute).
|
35
|
-
with("SELECT ? FROM #{cf} WHERE ? = ? LIMIT 1", [uuid1], :blog_id, 1).
|
36
|
-
and_return result_stub(uuid1 => 1)
|
37
|
-
dictionary[uuid1].should == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#slice' do
|
43
|
-
it 'should load columns from data store' do
|
44
|
-
connection.stub(:execute).
|
45
|
-
with("SELECT ? FROM #{cf} WHERE ? = ? LIMIT 1", [uuid1,uuid2], :blog_id, 1).
|
46
|
-
and_return result_stub(uuid1 => 1, uuid2 => 2)
|
47
|
-
dictionary.slice(uuid1, uuid2).should == {uuid1 => 1, uuid2 => 2}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#keys' do
|
52
|
-
it 'should load keys from data store' do
|
53
|
-
connection.should_receive(:execute).
|
54
|
-
with("SELECT FIRST 2 * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
|
55
|
-
and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
|
56
|
-
connection.should_receive(:execute).
|
57
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid2, '', :blog_id, 1).
|
58
|
-
and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
|
59
|
-
connection.should_receive(:execute).
|
60
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid3, '', :blog_id, 1).
|
61
|
-
and_return result_stub({'blog_id' => 1})
|
62
|
-
dictionary.keys.should == [uuid1, uuid2, uuid3]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe '#values' do
|
67
|
-
it 'should load values from data store' do
|
68
|
-
connection.should_receive(:execute).
|
69
|
-
with("SELECT FIRST 2 * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
|
70
|
-
and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
|
71
|
-
connection.should_receive(:execute).
|
72
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid2, '', :blog_id, 1).
|
73
|
-
and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
|
74
|
-
connection.should_receive(:execute).
|
75
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid3, '', :blog_id, 1).
|
76
|
-
and_return result_stub({'blog_id' => 1})
|
77
|
-
dictionary.values.should == [1, 2, 3]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#first' do
|
82
|
-
it 'should load value from data store' do
|
83
|
-
connection.should_receive(:execute).
|
84
|
-
with("SELECT FIRST 1 * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
|
85
|
-
and_return result_stub('blog_id' => 1, uuid1 => 1)
|
86
|
-
dictionary.first.should == [uuid1, 1]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#last' do
|
91
|
-
it 'should load value from data store' do
|
92
|
-
connection.should_receive(:execute).
|
93
|
-
with("SELECT FIRST 1 REVERSED * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
|
94
|
-
and_return result_stub('blog_id' => 1, uuid3 => 3)
|
95
|
-
dictionary.last.should == [uuid3, 3]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'with data loaded in memory' do
|
102
|
-
before do
|
103
|
-
connection.stub(:execute).
|
104
|
-
with("SELECT FIRST 2 * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
|
105
|
-
and_return result_stub('blog_id' => 1, uuid1 => 1, uuid2 => 2)
|
106
|
-
connection.stub(:execute).
|
107
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid2, '', :blog_id, 1).
|
108
|
-
and_return result_stub('blog_id' => 1, uuid2 => 2, uuid3 => 3)
|
109
|
-
connection.stub(:execute).
|
110
|
-
with("SELECT FIRST 2 ?..? FROM #{cf} WHERE ? = ? LIMIT 1", uuid3, '', :blog_id, 1).
|
111
|
-
and_return result_stub({'blog_id' => 1})
|
112
|
-
dictionary.load
|
113
|
-
connection.should_not_receive(:execute)
|
114
|
-
end
|
115
|
-
|
116
|
-
describe '#each_pair' do
|
117
|
-
it 'should yield data from memory' do
|
118
|
-
hash = {}
|
119
|
-
dictionary.each_pair do |key, value|
|
120
|
-
hash[key] = value
|
121
|
-
end
|
122
|
-
hash.should == {uuid1 => 1, uuid2 => 2, uuid3 => 3}
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#[]' do
|
127
|
-
it 'should return value from memory' do
|
128
|
-
dictionary[uuid1].should == 1
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe '#slice' do
|
133
|
-
it 'should return slice of data in memory' do
|
134
|
-
dictionary.slice(uuid1, uuid2).should == {uuid1 => 1, uuid2 => 2}
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe '#first' do
|
139
|
-
it 'should return first element in memory' do
|
140
|
-
dictionary.first.should == [uuid1, 1]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe '#last' do
|
145
|
-
it 'should return first element in memory' do
|
146
|
-
dictionary.last.should == [uuid3, 3]
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe '#keys' do
|
151
|
-
it 'should return keys from memory' do
|
152
|
-
dictionary.keys.should == [uuid1, uuid2, uuid3]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '#values' do
|
157
|
-
it 'should return values from memory' do
|
158
|
-
dictionary.values.should == [1, 2, 3]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe '::load' do
|
164
|
-
let :comments do
|
165
|
-
[
|
166
|
-
{'user' => 'Cequel User', 'comment' => 'How do I load multiple rows?'},
|
167
|
-
{'user' => 'Mat Brown', 'comment' => 'Just use the ::load class method'}
|
168
|
-
]
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should load all rows in one query' do
|
172
|
-
connection.stub(:execute).
|
173
|
-
with(
|
174
|
-
'SELECT * FROM post_comments WHERE ? IN (?)',
|
175
|
-
'post_id', [1, 2]
|
176
|
-
).and_return result_stub(
|
177
|
-
*comments.each_with_index.
|
178
|
-
map { |comment, i| {'post_id' => i+1, i+4 => comment.to_json} }
|
179
|
-
)
|
180
|
-
rows = PostComments.load(1, 2)
|
181
|
-
rows.map { |row| row.post_id }.should == [1, 2]
|
182
|
-
rows.map { |row| row.values.first }.should == comments
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
private
|
187
|
-
|
188
|
-
def uuid
|
189
|
-
SimpleUUID::UUID.new.to_guid
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|