dynamoid 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,242 +0,0 @@
1
- require 'dynamoid/adapter/local'
2
- require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
3
-
4
- describe Dynamoid::Adapter::Local do
5
-
6
- unless ENV['ACCESS_KEY'] && ENV['SECRET_KEY']
7
-
8
- # BatchGetItem
9
- it 'performs BatchGetItem with singular keys' do
10
- Dynamoid::Adapter.create_table('table1', :id)
11
- Dynamoid::Adapter.put_item('table1', {:id => '1', :name => 'Josh'})
12
- Dynamoid::Adapter.create_table('table2', :id)
13
- Dynamoid::Adapter.put_item('table2', {:id => '1', :name => 'Justin'})
14
-
15
- results = Dynamoid::Adapter.batch_get_item('table1' => '1', 'table2' => '1')
16
- results.size.should == 2
17
- results['table1'].should include({:name => 'Josh', :id => '1'})
18
- results['table2'].should include({:name => 'Justin', :id => '1'})
19
- end
20
-
21
- it 'performs BatchGetItem with multiple keys' do
22
- Dynamoid::Adapter.create_table('table1', :id)
23
- Dynamoid::Adapter.put_item('table1', {:id => '1', :name => 'Josh'})
24
- Dynamoid::Adapter.put_item('table1', {:id => '2', :name => 'Justin'})
25
-
26
- results = Dynamoid::Adapter.batch_get_item('table1' => ['1', '2'])
27
- results.size.should == 1
28
- results['table1'].should include({:name => 'Josh', :id => '1'})
29
- results['table1'].should include({:name => 'Justin', :id => '2'})
30
- end
31
-
32
- it 'performs BatchGetItem with range keys' do
33
- Dynamoid::Adapter.create_table('table1', :id, :range_key => { :range => :string })
34
- Dynamoid::Adapter.put_item('table1', {:id => '1', :range => 1.0})
35
- Dynamoid::Adapter.put_item('table1', {:id => '2', :range => 2.0})
36
-
37
- results = Dynamoid::Adapter.batch_get_item('table1' => [['1', 1.0], ['2', 2.0]])
38
- results.size.should == 1
39
- results['table1'].should include({:id => '1', :range => 1.0})
40
- results['table1'].should include({:id => '2', :range => 2.0})
41
- end
42
-
43
- it 'performs BatchGetItem with range keys on one primary key' do
44
- Dynamoid::Adapter.create_table('table1', :id, :range_key => { :range => :string })
45
- Dynamoid::Adapter.put_item('table1', {:id => '1', :range => 1.0})
46
- Dynamoid::Adapter.put_item('table1', {:id => '1', :range => 2.0})
47
-
48
- results = Dynamoid::Adapter.batch_get_item('table1' => [['1', 1.0], ['1', 2.0]])
49
- results.size.should == 1
50
- results['table1'].should include({:id => '1', :range => 1.0})
51
- results['table1'].should include({:id => '1', :range => 2.0})
52
- end
53
-
54
- # CreateTable
55
- it 'performs CreateTable' do
56
- Dynamoid::Adapter.create_table('Test Table', :id)
57
-
58
- Dynamoid::Adapter.list_tables.should include 'Test Table'
59
- end
60
-
61
- # DeleteItem
62
- it 'performs DeleteItem' do
63
- Dynamoid::Adapter.create_table('table1', :id)
64
- Dynamoid::Adapter.put_item('table1', {:id => '1', :name => 'Josh'})
65
-
66
- Dynamoid::Adapter.delete_item('table1', '1')
67
-
68
- Dynamoid::Adapter.data['table1'][:data].should be_empty
69
- end
70
-
71
- it 'performs DeleteItem for an item that does not exist' do
72
- Dynamoid::Adapter.create_table('table1', :id)
73
-
74
- Dynamoid::Adapter.delete_item('table1', '1')
75
-
76
- Dynamoid::Adapter.data['table1'][:data].should be_empty
77
- end
78
-
79
- # DeleteTable
80
- it 'performs DeleteTable' do
81
- Dynamoid::Adapter.create_table('table1', :id)
82
-
83
- Dynamoid::Adapter.delete_table('table1')
84
-
85
- Dynamoid::Adapter.data['table1'].should be_nil
86
- end
87
-
88
- # DescribeTable
89
-
90
- # GetItem
91
- it "performs GetItem for an item that does not exist" do
92
- Dynamoid::Adapter.create_table('Test Table', :id)
93
-
94
- Dynamoid::Adapter.get_item('Test Table', '1').should be_nil
95
- end
96
-
97
- it "performs GetItem for an item that does exist" do
98
- Dynamoid::Adapter.create_table('Test Table', :id)
99
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
100
-
101
- Dynamoid::Adapter.get_item('Test Table', '1').should == {:id => '1', :name => 'Josh'}
102
- end
103
-
104
- it "performs GetItem for an item with a range key" do
105
- Dynamoid::Adapter.create_table('Test Table', :id, :range_key => { :range => :number })
106
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :range => 1.0})
107
-
108
- Dynamoid::Adapter.get_item('Test Table', '1').should be_nil
109
- Dynamoid::Adapter.get_item('Test Table', '1', :range_key => 1.0).should == {:id => '1', :range => 1.0}
110
- end
111
-
112
- # ListTables
113
- it 'performs ListTables' do
114
- Dynamoid::Adapter.create_table('Table1', :id)
115
- Dynamoid::Adapter.create_table('Table2', :id)
116
-
117
- Dynamoid::Adapter.list_tables.should include 'Table1'
118
- Dynamoid::Adapter.list_tables.should include 'Table2'
119
- end
120
-
121
- # PutItem
122
- it 'performs PutItem for an item that does not exist' do
123
- Dynamoid::Adapter.create_table('Test Table', :id)
124
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
125
-
126
- Dynamoid::Adapter.data['Test Table'].should == {:hash_key=>:id, :range_key=>nil, :data=>{"1."=>{:id=>"1", :name=>"Josh"}}}
127
- end
128
-
129
- it 'puts an item twice and overwrites an existing item' do
130
- Dynamoid::Adapter.create_table('Test Table', :id)
131
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
132
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Justin'})
133
-
134
- Dynamoid::Adapter.data['Test Table'].should == {:hash_key=>:id, :range_key=>nil, :data=>{"1."=>{:id=>"1", :name=>"Justin"}}}
135
- end
136
-
137
- it 'puts an item twice and does not overwrite an existing item if the range key is not the same' do
138
- Dynamoid::Adapter.create_table('Test Table', :id, :range_key => { :range => :number })
139
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Justin', :range => 1.0})
140
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Justin', :range => 2.0})
141
-
142
- Dynamoid::Adapter.data['Test Table'].should == {:hash_key=>:id, :range_key=>:range, :data=>{"1.1.0"=>{:id=>"1", :name=>"Justin", :range => 1.0}, "1.2.0" => {:id=>"1", :name=>"Justin", :range => 2.0}}}
143
- end
144
-
145
- it 'puts an item twice and does overwrite an existing item if the range key is the same' do
146
- Dynamoid::Adapter.create_table('Test Table', :id, :range_key => { :range => :number })
147
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh', :range => 1.0})
148
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Justin', :range => 1.0})
149
-
150
- Dynamoid::Adapter.data['Test Table'].should == {:hash_key=>:id, :range_key=>:range, :data=>{"1.1.0"=>{:id=>"1", :name=>"Justin", :range => 1.0}}}
151
- end
152
-
153
-
154
- # Query
155
- it 'performs query on a table and returns items' do
156
- Dynamoid::Adapter.create_table('Test Table', :id)
157
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
158
-
159
- Dynamoid::Adapter.query('Test Table', :hash_value => '1').should == [{ :id=> '1', :name=>"Josh" }]
160
- end
161
-
162
- it 'performs query on a table and returns items if there are multiple items' do
163
- Dynamoid::Adapter.create_table('Test Table', :id)
164
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
165
- Dynamoid::Adapter.put_item('Test Table', {:id => '2', :name => 'Justin'})
166
-
167
- Dynamoid::Adapter.query('Test Table', :hash_value => '1').should == [{ :id=> '1', :name=>"Josh" }]
168
- end
169
-
170
- context 'range queries' do
171
- before do
172
- Dynamoid::Adapter.create_table('Test Table', :id, :range_key => { :range => :number })
173
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :range => 1.0})
174
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :range => 2.0})
175
- end
176
-
177
- it 'performs query on a table with a range and selects items in a range' do
178
- Dynamoid::Adapter.query('Test Table', :hash_value => '1', :range_value => 0.0..3.0).should =~ [{:id => '1', :range => 1.0}, {:id => '1', :range => 2.0}]
179
- end
180
-
181
- it 'performs query on a table with a range and selects items greater than' do
182
- Dynamoid::Adapter.query('Test Table', :hash_value => '1', :range_greater_than => 1.0).should =~ [{:id => '1', :range => 2.0}]
183
- end
184
-
185
- it 'performs query on a table with a range and selects items less than' do
186
- Dynamoid::Adapter.query('Test Table', :hash_value => '1', :range_less_than => 2.0).should =~ [{:id => '1', :range => 1.0}]
187
- end
188
-
189
- it 'performs query on a table with a range and selects items gte' do
190
- Dynamoid::Adapter.query('Test Table', :hash_value => '1', :range_gte => 1.0).should =~ [{:id => '1', :range => 1.0}, {:id => '1', :range => 2.0}]
191
- end
192
-
193
- it 'performs query on a table with a range and selects items lte' do
194
- Dynamoid::Adapter.query('Test Table', :hash_value => '1', :range_lte => 2.0).should =~ [{:id => '1', :range => 1.0}, {:id => '1', :range => 2.0}]
195
- end
196
-
197
- end
198
-
199
- # Scan
200
- it 'performs scan on a table and returns items' do
201
- Dynamoid::Adapter.create_table('Test Table', :id)
202
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
203
-
204
- Dynamoid::Adapter.scan('Test Table', :name => 'Josh').should == [{ :id=> '1', :name=>"Josh" }]
205
- end
206
-
207
- it 'performs scan on a table and returns items if there are multiple items but only one match' do
208
- Dynamoid::Adapter.create_table('Test Table', :id)
209
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
210
- Dynamoid::Adapter.put_item('Test Table', {:id => '2', :name => 'Justin'})
211
-
212
- Dynamoid::Adapter.scan('Test Table', :name => 'Josh').should == [{ :id=> '1', :name=>"Josh" }]
213
- end
214
-
215
- it 'performs scan on a table and returns multiple items if there are multiple matches' do
216
- Dynamoid::Adapter.create_table('Test Table', :id)
217
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
218
- Dynamoid::Adapter.put_item('Test Table', {:id => '2', :name => 'Josh'})
219
-
220
- Dynamoid::Adapter.scan('Test Table', :name => 'Josh').should == [{ :id=> '1', :name=>"Josh" }, { :id=> '2', :name=>"Josh" }]
221
- end
222
-
223
- it 'performs scan on a table and returns all items if no criteria are specified' do
224
- Dynamoid::Adapter.create_table('Test Table', :id)
225
- Dynamoid::Adapter.put_item('Test Table', {:id => '1', :name => 'Josh'})
226
- Dynamoid::Adapter.put_item('Test Table', {:id => '2', :name => 'Josh'})
227
-
228
- Dynamoid::Adapter.scan('Test Table', {}).should == [{ :id=> '1', :name=>"Josh" }, { :id=> '2', :name=>"Josh" }]
229
- end
230
-
231
- # UpdateItem
232
-
233
- # UpdateTable
234
-
235
- protected
236
-
237
- def setup_value(table, key, value)
238
- Dynamoid::Adapter.data[table][key] = value
239
- end
240
-
241
- end
242
- end