Skip to content

Commit

Permalink
Fix various rspecs
Browse files Browse the repository at this point in the history
* Call KitCreateService instead of create(:kit)
* Kit must be created in same organization as TestInventory storage location
* Fix references to line_items
  • Loading branch information
jimmyli97 committed Aug 28, 2024
1 parent 37978a0 commit 3540e02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/kit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def deactivate
# or deallocated, we are changing inventory for inactive items (which we don't allow).
# @return [Boolean]
def can_reactivate?
line_items.joins(:item).where(items: { active: false }).none?
item.line_items.joins(:item).where(items: { active: false }).none?
end

def reactivate
Expand Down
9 changes: 6 additions & 3 deletions spec/models/kit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@
end

describe '#can_deactivate?' do
let(:kit) { create(:kit, organization: organization) }
let(:kit) {
kit_params = attributes_for(:kit)
kit_params[:line_items_attributes] = [{item_id: create(:item).id, quantity: 1}]
KitCreateService.new(organization_id: organization.id, kit_params: kit_params).call.kit
}

context 'with inventory' do
it 'should return false' do
item = create(:item, :active, organization: organization, kit: kit)
storage_location = create(:storage_location, :with_items, organization: organization, item: item)
storage_location = create(:storage_location, organization: organization)

TestInventory.create_inventory(organization, {
storage_location.id => {
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/kit_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

context "when it cannot be deactivated" do
it "should disable the button" do
storage_location = create(:storage_location)
storage_location = create(:storage_location, organization: organization)
TestInventory.create_inventory(kit.organization, {
storage_location.id => {
kit.item.id => 10
Expand Down Expand Up @@ -84,7 +84,7 @@
it "cannot reactivate if it has an inactive item" do
kit.deactivate
expect(kit).not_to be_active
kit.line_items.first.item.update!(active: false)
kit.item.line_items.first.item.update!(active: false)

put reactivate_kit_url(kit)
expect(kit.reload).not_to be_active
Expand Down

0 comments on commit 3540e02

Please sign in to comment.