lotus-dynamodb 0.1.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 +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +9 -0
- data/.yardopts +5 -0
- data/Gemfile +16 -0
- data/LICENSE.md +22 -0
- data/Procfile +1 -0
- data/README.md +112 -0
- data/Rakefile +17 -0
- data/benchmarks/coercer.rb +76 -0
- data/examples/Gemfile +2 -0
- data/examples/purchase.rb +164 -0
- data/lib/lotus/dynamodb/config.rb +14 -0
- data/lib/lotus/dynamodb/version.rb +8 -0
- data/lib/lotus/model/adapters/dynamodb/coercer.rb +211 -0
- data/lib/lotus/model/adapters/dynamodb/collection.rb +321 -0
- data/lib/lotus/model/adapters/dynamodb/command.rb +117 -0
- data/lib/lotus/model/adapters/dynamodb/query.rb +559 -0
- data/lib/lotus/model/adapters/dynamodb_adapter.rb +190 -0
- data/lib/lotus-dynamodb.rb +3 -0
- data/lotus-dynamodb.gemspec +30 -0
- data/test/fixtures.rb +75 -0
- data/test/model/adapters/dynamodb/coercer_test.rb +269 -0
- data/test/model/adapters/dynamodb/query_test.rb +259 -0
- data/test/model/adapters/dynamodb_adapter_test.rb +940 -0
- data/test/test_helper.rb +46 -0
- data/test/version_test.rb +7 -0
- metadata +203 -0
@@ -0,0 +1,259 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Lotus::Model::Adapters::Dynamodb::Query do
|
4
|
+
before do
|
5
|
+
MockResponse = Struct.new(:entities)
|
6
|
+
|
7
|
+
class MockDataset
|
8
|
+
include AWS::DynamoDB::Types
|
9
|
+
|
10
|
+
attr_accessor :entities
|
11
|
+
attr_accessor :records
|
12
|
+
|
13
|
+
def initialize(entities)
|
14
|
+
@entities = entities
|
15
|
+
@records = MockResponse.new(entities)
|
16
|
+
end
|
17
|
+
|
18
|
+
def query(options = {})
|
19
|
+
records
|
20
|
+
end
|
21
|
+
|
22
|
+
def scan(options = {})
|
23
|
+
records
|
24
|
+
end
|
25
|
+
|
26
|
+
def key?(column, index = nil)
|
27
|
+
return true if index.nil? && column == :id
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def format_attribute(column, value)
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
records.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class MockCollection
|
41
|
+
def deserialize(array)
|
42
|
+
array
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
collection = MockCollection.new
|
47
|
+
@query = Lotus::Model::Adapters::Dynamodb::Query.new(dataset, collection)
|
48
|
+
end
|
49
|
+
|
50
|
+
after do
|
51
|
+
Object.send(:remove_const, :MockResponse)
|
52
|
+
Object.send(:remove_const, :MockDataset)
|
53
|
+
Object.send(:remove_const, :MockCollection)
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:dataset) { MockDataset.new([]) }
|
57
|
+
|
58
|
+
describe '#negate!' do
|
59
|
+
it 'raises an error' do
|
60
|
+
-> { @query.negate! }.must_raise NotImplementedError
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#offset' do
|
65
|
+
it 'raises an error' do
|
66
|
+
-> { @query.offset(1) }.must_raise NotImplementedError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#sum' do
|
71
|
+
it 'raises an error' do
|
72
|
+
-> { @query.sum(:id) }.must_raise NotImplementedError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#average' do
|
77
|
+
it 'raises an error' do
|
78
|
+
-> { @query.average(:id) }.must_raise NotImplementedError
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#avg' do
|
83
|
+
it 'raises an error' do
|
84
|
+
-> { @query.avg(:id) }.must_raise NotImplementedError
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#max' do
|
89
|
+
it 'raises an error' do
|
90
|
+
-> { @query.max(:id) }.must_raise NotImplementedError
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#min' do
|
95
|
+
it 'raises an error' do
|
96
|
+
-> { @query.min(:id) }.must_raise NotImplementedError
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#interval' do
|
101
|
+
it 'raises an error' do
|
102
|
+
-> { @query.interval(:id) }.must_raise NotImplementedError
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#range' do
|
107
|
+
it 'raises an error' do
|
108
|
+
-> { @query.range(:id) }.must_raise NotImplementedError
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#to_s' do
|
113
|
+
let(:dataset) { MockDataset.new([1, 2, 3]) }
|
114
|
+
|
115
|
+
it 'must be array representation' do
|
116
|
+
@query.to_s.must_equal dataset.entities.to_s
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#empty?' do
|
121
|
+
describe "when it's empty" do
|
122
|
+
it 'returns true' do
|
123
|
+
@query.must_be_empty
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "when it's filled with elements" do
|
128
|
+
let(:dataset) { MockDataset.new([1, 2, 3]) }
|
129
|
+
|
130
|
+
it 'returns false' do
|
131
|
+
@query.wont_be_empty
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#any?' do
|
137
|
+
describe "when it's empty" do
|
138
|
+
it 'returns false' do
|
139
|
+
assert !@query.any?
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "when it's filled with elements" do
|
144
|
+
let(:dataset) { MockDataset.new([1, 2, 3]) }
|
145
|
+
|
146
|
+
it 'returns true' do
|
147
|
+
assert @query.any?
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "when a block is passed" do
|
151
|
+
describe "and it doesn't match elements" do
|
152
|
+
it 'returns false' do
|
153
|
+
assert !@query.any? {|e| e > 100 }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "and it matches elements" do
|
158
|
+
it 'returns true' do
|
159
|
+
assert @query.any? {|e| e % 2 == 0 }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'operation' do
|
167
|
+
describe 'scan' do
|
168
|
+
it 'equals by default' do
|
169
|
+
@query.operation.must_equal :scan
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'equals after where call' do
|
173
|
+
@query.where(something: 'anything').operation.must_equal :scan
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'equals after or call' do
|
177
|
+
@query.or.operation.must_equal :scan
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'equals after exclude call' do
|
181
|
+
@query.exclude(something: 'anything').operation.must_equal :scan
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'equals after select call' do
|
185
|
+
@query.select('wow').operation.must_equal :scan
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'equals after limit call' do
|
189
|
+
@query.limit(1).operation.must_equal :scan
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'equals after count call' do
|
193
|
+
@query.count
|
194
|
+
@query.operation.must_equal :scan
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe 'query' do
|
199
|
+
describe 'after query call' do
|
200
|
+
before do
|
201
|
+
@query = @query.query
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'equals' do
|
205
|
+
@query.operation.must_equal :query
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'equals after or call' do
|
209
|
+
@query.or.operation.must_equal :query
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'equals after selet call' do
|
213
|
+
@query.select('wow').operation.must_equal :query
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'equals after limit call' do
|
217
|
+
@query.limit(1).operation.must_equal :query
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'equals after count call' do
|
221
|
+
@query.count
|
222
|
+
@query.operation.must_equal :query
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'after where with key schema call' do
|
227
|
+
before do
|
228
|
+
@query = @query.where(id: 1)
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'equals' do
|
232
|
+
@query.operation.must_equal :query
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'equals after exclude call' do
|
236
|
+
@query.exclude(something: 'anything').operation.must_equal :query
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe 'after order call' do
|
241
|
+
it 'equals after asc call' do
|
242
|
+
@query.asc.operation.must_equal :query
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'equals after desc call' do
|
246
|
+
@query.desc.operation.must_equal :query
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'equals after consistent call' do
|
251
|
+
@query.consistent.operation.must_equal :query
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'equals after index call' do
|
255
|
+
@query.index('omg').operation.must_equal :query
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|