Skip to content

Commit 3540e02

Browse files
committed
Fix various rspecs
* Call KitCreateService instead of create(:kit) * Kit must be created in same organization as TestInventory storage location * Fix references to line_items
1 parent 37978a0 commit 3540e02

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Diff for: app/models/kit.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def deactivate
4646
# or deallocated, we are changing inventory for inactive items (which we don't allow).
4747
# @return [Boolean]
4848
def can_reactivate?
49-
line_items.joins(:item).where(items: { active: false }).none?
49+
item.line_items.joins(:item).where(items: { active: false }).none?
5050
end
5151

5252
def reactivate

Diff for: spec/models/kit_spec.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@
6464
end
6565

6666
describe '#can_deactivate?' do
67-
let(:kit) { create(:kit, organization: organization) }
67+
let(:kit) {
68+
kit_params = attributes_for(:kit)
69+
kit_params[:line_items_attributes] = [{item_id: create(:item).id, quantity: 1}]
70+
KitCreateService.new(organization_id: organization.id, kit_params: kit_params).call.kit
71+
}
6872

6973
context 'with inventory' do
7074
it 'should return false' do
71-
item = create(:item, :active, organization: organization, kit: kit)
72-
storage_location = create(:storage_location, :with_items, organization: organization, item: item)
75+
storage_location = create(:storage_location, organization: organization)
7376

7477
TestInventory.create_inventory(organization, {
7578
storage_location.id => {

Diff for: spec/requests/kit_requests_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
context "when it cannot be deactivated" do
4040
it "should disable the button" do
41-
storage_location = create(:storage_location)
41+
storage_location = create(:storage_location, organization: organization)
4242
TestInventory.create_inventory(kit.organization, {
4343
storage_location.id => {
4444
kit.item.id => 10
@@ -84,7 +84,7 @@
8484
it "cannot reactivate if it has an inactive item" do
8585
kit.deactivate
8686
expect(kit).not_to be_active
87-
kit.line_items.first.item.update!(active: false)
87+
kit.item.line_items.first.item.update!(active: false)
8888

8989
put reactivate_kit_url(kit)
9090
expect(kit.reload).not_to be_active

0 commit comments

Comments
 (0)