|
260 | 260 | end
|
261 | 261 | end
|
262 | 262 |
|
| 263 | + context "when providing nested arrays of ids" do |
| 264 | + |
| 265 | + let!(:band_two) do |
| 266 | + Band.create!(name: "Tool") |
| 267 | + end |
| 268 | + |
| 269 | + context "when all ids match" do |
| 270 | + |
| 271 | + let(:found) do |
| 272 | + Band.find([ [ band.id ], [ [ band_two.id ] ] ]) |
| 273 | + end |
| 274 | + |
| 275 | + it "contains the first match" do |
| 276 | + expect(found).to include(band) |
| 277 | + end |
| 278 | + |
| 279 | + it "contains the second match" do |
| 280 | + expect(found).to include(band_two) |
| 281 | + end |
| 282 | + |
| 283 | + context "when ids are duplicates" do |
| 284 | + |
| 285 | + let(:found) do |
| 286 | + Band.find([ [ band.id ], [ [ band.id ] ] ]) |
| 287 | + end |
| 288 | + |
| 289 | + it "contains only the first match" do |
| 290 | + expect(found).to eq([band]) |
| 291 | + end |
| 292 | + end |
| 293 | + end |
| 294 | + |
| 295 | + context "when any id does not match" do |
| 296 | + |
| 297 | + context "when raising a not found error" do |
| 298 | + config_override :raise_not_found_error, true |
| 299 | + |
| 300 | + let(:found) do |
| 301 | + Band.find([ [ band.id ], [ [ BSON::ObjectId.new ] ] ]) |
| 302 | + end |
| 303 | + |
| 304 | + it "raises an error" do |
| 305 | + expect { |
| 306 | + found |
| 307 | + }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/) |
| 308 | + end |
| 309 | + end |
| 310 | + |
| 311 | + context "when raising no error" do |
| 312 | + config_override :raise_not_found_error, false |
| 313 | + |
| 314 | + let(:found) do |
| 315 | + Band.find([ [ band.id ], [ [ BSON::ObjectId.new ] ] ]) |
| 316 | + end |
| 317 | + |
| 318 | + it "returns only the matching documents" do |
| 319 | + expect(found).to eq([ band ]) |
| 320 | + end |
| 321 | + end |
| 322 | + end |
| 323 | + end |
| 324 | + |
| 325 | + context "when providing a Set of ids" do |
| 326 | + |
| 327 | + let!(:band_two) do |
| 328 | + Band.create!(name: "Tool") |
| 329 | + end |
| 330 | + |
| 331 | + context "when all ids match" do |
| 332 | + let(:found) do |
| 333 | + Band.find(Set[ band.id, band_two.id ]) |
| 334 | + end |
| 335 | + |
| 336 | + it "contains the first match" do |
| 337 | + expect(found).to include(band) |
| 338 | + end |
| 339 | + |
| 340 | + it "contains the second match" do |
| 341 | + expect(found).to include(band_two) |
| 342 | + end |
| 343 | + end |
| 344 | + |
| 345 | + context "when any id does not match" do |
| 346 | + |
| 347 | + context "when raising a not found error" do |
| 348 | + config_override :raise_not_found_error, true |
| 349 | + |
| 350 | + let(:found) do |
| 351 | + Band.find(Set[ band.id, BSON::ObjectId.new ]) |
| 352 | + end |
| 353 | + |
| 354 | + it "raises an error" do |
| 355 | + expect { |
| 356 | + found |
| 357 | + }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/) |
| 358 | + end |
| 359 | + end |
| 360 | + |
| 361 | + context "when raising no error" do |
| 362 | + config_override :raise_not_found_error, false |
| 363 | + |
| 364 | + let(:found) do |
| 365 | + Band.find(Set[ band.id, BSON::ObjectId.new ]) |
| 366 | + end |
| 367 | + |
| 368 | + it "returns only the matching documents" do |
| 369 | + expect(found).to eq([ band ]) |
| 370 | + end |
| 371 | + end |
| 372 | + end |
| 373 | + end |
| 374 | + |
| 375 | + context "when providing a Range of ids" do |
| 376 | + |
| 377 | + let!(:band_two) do |
| 378 | + Band.create!(name: "Tool") |
| 379 | + end |
| 380 | + |
| 381 | + context "when all ids match" do |
| 382 | + let(:found) do |
| 383 | + Band.find(band.id.to_s..band_two.id.to_s) |
| 384 | + end |
| 385 | + |
| 386 | + it "contains the first match" do |
| 387 | + expect(found).to include(band) |
| 388 | + end |
| 389 | + |
| 390 | + it "contains the second match" do |
| 391 | + expect(found).to include(band_two) |
| 392 | + end |
| 393 | + |
| 394 | + |
| 395 | + context "when any id does not match" do |
| 396 | + |
| 397 | + context "when raising a not found error" do |
| 398 | + config_override :raise_not_found_error, true |
| 399 | + |
| 400 | + let(:found) do |
| 401 | + Band.find(band_two.id.to_s..BSON::ObjectId.new) |
| 402 | + end |
| 403 | + |
| 404 | + it "does not raise error and returns only the matching documents" do |
| 405 | + expect(found).to eq([ band_two ]) |
| 406 | + end |
| 407 | + end |
| 408 | + |
| 409 | + context "when raising no error" do |
| 410 | + config_override :raise_not_found_error, false |
| 411 | + |
| 412 | + let(:found) do |
| 413 | + Band.find(band_two.id.to_s..BSON::ObjectId.new) |
| 414 | + end |
| 415 | + |
| 416 | + it "returns only the matching documents" do |
| 417 | + expect(found).to eq([ band_two ]) |
| 418 | + end |
| 419 | + end |
| 420 | + end |
| 421 | + end |
| 422 | + |
| 423 | + context "when all ids do not match" do |
| 424 | + |
| 425 | + context "when raising a not found error" do |
| 426 | + config_override :raise_not_found_error, true |
| 427 | + |
| 428 | + let(:found) do |
| 429 | + Band.find(BSON::ObjectId.new..BSON::ObjectId.new) |
| 430 | + end |
| 431 | + |
| 432 | + it "raises an error" do |
| 433 | + expect { |
| 434 | + found |
| 435 | + }.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Band with id\(s\)/) |
| 436 | + end |
| 437 | + end |
| 438 | + |
| 439 | + context "when raising no error" do |
| 440 | + config_override :raise_not_found_error, false |
| 441 | + |
| 442 | + let(:found) do |
| 443 | + Band.find(BSON::ObjectId.new..BSON::ObjectId.new) |
| 444 | + end |
| 445 | + |
| 446 | + it "returns only the matching documents" do |
| 447 | + expect(found).to eq([]) |
| 448 | + end |
| 449 | + end |
| 450 | + end |
| 451 | + end |
| 452 | + |
263 | 453 | context "when providing a single id as extended json" do
|
264 | 454 |
|
265 | 455 | context "when the id matches" do
|
|
0 commit comments