|
27 | 27 | klass.find('wrong-id') |
28 | 28 | }.to raise_error(Dynamoid::Errors::RecordNotFound, "Couldn't find Document with primary key \"wrong-id\"") |
29 | 29 | end |
| 30 | + |
| 31 | + it 'raises MissingHashKey when partition key is nil' do |
| 32 | + klass.create_table |
| 33 | + expect { |
| 34 | + klass.find(nil) |
| 35 | + }.to raise_error(Dynamoid::Errors::MissingHashKey) |
| 36 | + end |
30 | 37 | end |
31 | 38 |
|
32 | 39 | context 'composite primary key' do |
|
42 | 49 | }.to raise_error(Dynamoid::Errors::RecordNotFound, "Couldn't find Cat with primary key (\"wrong-id\",100500)") |
43 | 50 | end |
44 | 51 |
|
| 52 | + it 'raises MissingHashKey when partition key is nil' do |
| 53 | + obj = klass_with_composite_key.create!(age: 12) |
| 54 | + |
| 55 | + expect { |
| 56 | + klass_with_composite_key.find(nil, range_key: obj.age) |
| 57 | + }.to raise_error(Dynamoid::Errors::MissingHashKey) |
| 58 | + end |
| 59 | + |
45 | 60 | it 'raises MissingRangeKey when range key is not specified' do |
46 | 61 | obj = klass_with_composite_key.create!(age: 12) |
47 | 62 |
|
|
171 | 186 | }.to raise_error(Dynamoid::Errors::RecordNotFound, |
172 | 187 | "Couldn't find all Documents with primary keys [\"wrong-id\"] (found 0 results, but was looking for 1)") |
173 | 188 | end |
| 189 | + |
| 190 | + it 'raises MissingHashKey when any partition key is nil' do |
| 191 | + obj1, _ = (1..2).map { klass.create! } |
| 192 | + |
| 193 | + expect { |
| 194 | + klass.find([obj1.id, nil]) |
| 195 | + }.to raise_error(Dynamoid::Errors::MissingHashKey) |
| 196 | + end |
174 | 197 | end |
175 | 198 |
|
176 | 199 | context 'composite primary key' do |
|
214 | 237 | expect(klass_with_composite_key.find([obj1.id, obj1.age], [obj2.id, obj2.age])).to match_array(objects) |
215 | 238 | end |
216 | 239 |
|
| 240 | + it 'raises MissingHashKey when any partition key is nil' do |
| 241 | + objects = (1..2).map { |i| klass_with_composite_key.create!(age: i) } |
| 242 | + obj1, obj2 = objects |
| 243 | + |
| 244 | + expect { |
| 245 | + klass_with_composite_key.find([[obj1.id, obj1.age], [nil, obj2.age]]) |
| 246 | + }.to raise_error(Dynamoid::Errors::MissingHashKey) |
| 247 | + end |
| 248 | + |
217 | 249 | it 'raises MissingRangeKey when range key is not specified' do |
218 | 250 | obj1, obj2 = klass_with_composite_key.create!([{ age: 1 }, { age: 2 }]) |
219 | 251 |
|
| 252 | + expect { |
| 253 | + klass_with_composite_key.find([[obj1.id, obj1.age], [obj2.id, nil]]) |
| 254 | + }.to raise_error(Dynamoid::Errors::MissingRangeKey) |
| 255 | + |
220 | 256 | expect { |
221 | 257 | klass_with_composite_key.find([obj1.id, obj2.id]) |
222 | 258 | }.to raise_error(Dynamoid::Errors::MissingRangeKey) |
|
0 commit comments