|
481 | 481 | describe "versioning" do
|
482 | 482 | it { is_expected.to be_versioned }
|
483 | 483 | end
|
| 484 | + |
| 485 | + describe "kit items" do |
| 486 | + context "with kit and regular items" do |
| 487 | + let(:organization) { create(:organization) } |
| 488 | + let(:kit) { create(:kit, organization: organization) } |
| 489 | + let(:kit_item) { create(:item, kit: kit, organization: organization) } |
| 490 | + let(:regular_item) { create(:item, organization: organization) } |
| 491 | + |
| 492 | + describe "#can_delete?" do |
| 493 | + it "returns false for kit items" do |
| 494 | + expect(kit_item.can_delete?).to be false |
| 495 | + end |
| 496 | + |
| 497 | + it "returns true for regular items" do |
| 498 | + expect(regular_item.can_delete?).to be true |
| 499 | + end |
| 500 | + end |
| 501 | + |
| 502 | + describe "#deactivate!" do |
| 503 | + it "deactivates both the kit item and its associated kit" do |
| 504 | + kit_item.deactivate! |
| 505 | + expect(kit_item.reload.active).to be false |
| 506 | + expect(kit.reload.active).to be false |
| 507 | + end |
| 508 | + |
| 509 | + it "only deactivates regular items" do |
| 510 | + regular_item.deactivate! |
| 511 | + expect(regular_item.reload.active).to be false |
| 512 | + end |
| 513 | + end |
| 514 | + |
| 515 | + describe "#validate_destroy" do |
| 516 | + it "prevents deletion of kit items" do |
| 517 | + expect { kit_item.destroy! }.to raise_error(ActiveRecord::RecordNotDestroyed) |
| 518 | + expect(kit_item.errors[:base]).to include("Cannot delete item - it has already been used!") |
| 519 | + end |
| 520 | + |
| 521 | + it "allows deletion of regular items" do |
| 522 | + expect { regular_item.destroy! }.not_to raise_error |
| 523 | + end |
| 524 | + end |
| 525 | + end |
| 526 | + end |
484 | 527 | end
|
0 commit comments