Skip to content

Commit 61eccf1

Browse files
committed
Fix failing specs
1 parent 49ac86c commit 61eccf1

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

app/controllers/dashboard_controller.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class DashboardController < ApplicationController
33
respond_to :html, :js
44

55
def index
6-
inventory = View::Inventory.new(current_organization.id)
76
@org_stats = OrganizationStats.new(current_organization, inventory)
87
@partners_awaiting_review = current_organization.partners.awaiting_review
98
@outstanding_requests = current_organization
@@ -18,4 +17,12 @@ def index
1817
# passing nil here filters the announcements that didn't come from an organization
1918
@broadcast_announcements = BroadcastAnnouncement.filter_announcements(nil)
2019
end
20+
21+
private
22+
23+
def inventory
24+
return @inventory if defined? @inventory
25+
26+
@inventory = current_organization.nil? ? nil : View::Inventory.new(current_organization.id)
27+
end
2128
end

app/models/organization_stats.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def donation_sites_added
2424
donation_sites&.length || 0
2525
end
2626

27-
def locations_with_inventory
28-
return [] unless storage_locations
27+
def num_locations_with_inventory
28+
return 0 unless storage_locations
2929

30-
storage_locations.select { |loc| inventory.quantity_for(storage_location: loc.id).positive? }
30+
storage_locations.count { |loc| inventory.quantity_for(storage_location: loc.id).positive? }
3131
end
3232

3333
private

app/queries/low_inventory_query.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
class LowInventoryQuery
22
LowInventoryItem = Data.define(:id, :name, :on_hand_minimum_quantity, :on_hand_recommended_quantity, :total_quantity)
33

4-
def self.call(organization, inventory)
4+
def self.call(organization, inventory = View::Inventory.new(organization.id))
5+
return [] if organization.blank?
6+
57
items = inventory.all_items.uniq(&:item_id)
68

79
low_inventory_items = []

app/views/dashboard/_getting_started_prompt.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% partner_criteria_met = org_stats.partners_added > 0 %>
33
<% location_criteria_met = org_stats.storage_locations_added > 0 %>
44
<% donation_criteria_met = org_stats.donation_sites_added > 0 %>
5-
<% inventory_criteria_met = org_stats.locations_with_inventory.length > 0 %>
5+
<% inventory_criteria_met = org_stats.num_locations_with_inventory > 0 %>
66
<% criterias = [ location_criteria_met, partner_criteria_met, donation_criteria_met, inventory_criteria_met ] %>
77
<% current_step = criterias.find_index(false) %>
88

@@ -116,7 +116,7 @@
116116
<% else %>
117117
<i class="fa fa-pie-chart fa-2x" aria-hidden="true"></i>
118118
<% end %>
119-
<h4><%= pluralize(org_stats.locations_with_inventory.length, 'Storage Location') %> with Inventory</h4>
119+
<h4><%= pluralize(org_stats.num_locations_with_inventory, 'Storage Location') %> with Inventory</h4>
120120
</div>
121121

122122
<div class="org-stats-desc">

spec/models/organization_stats_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
#
33
RSpec.describe OrganizationStats, type: :model do
44
let(:current_org) { create(:organization) }
5+
let(:inventory) { View::Inventory.new(current_org.id) }
56

6-
subject { described_class.new(current_org) }
7+
subject { described_class.new(current_org, inventory) }
78

89
describe "partners_added method >" do
910
context "current org is nil >" do
1011
let(:current_org) { nil }
12+
let(:inventory) { nil }
1113

1214
it "should return 0" do
1315
expect(subject.partners_added).to eq(0)
@@ -28,6 +30,7 @@
2830
describe "storage_locations_added method >" do
2931
context "current org is nil >" do
3032
let(:current_org) { nil }
33+
let(:inventory) { nil }
3134

3235
it "should return 0" do
3336
expect(subject.storage_locations_added).to eq(0)
@@ -48,6 +51,7 @@
4851
describe "donation_sites_added method >" do
4952
context "current org is nil >" do
5053
let(:current_org) { nil }
54+
let(:inventory) { nil }
5155

5256
it "should return 0" do
5357
expect(subject.donation_sites_added).to eq(0)
@@ -65,12 +69,13 @@
6569
end
6670
end
6771

68-
describe "locations_with_inventory method >" do
72+
describe "num_locations_with_inventory method >" do
6973
context "current org is nil >" do
7074
let(:current_org) { nil }
75+
let(:inventory) { nil }
7176

7277
it "should return an empty array" do
73-
expect(subject.locations_with_inventory).to eq([])
78+
expect(subject.num_locations_with_inventory).to eq(0)
7479
end
7580
end
7681

@@ -87,7 +92,7 @@
8792
end
8893

8994
it "should return storage location" do
90-
expect(subject.locations_with_inventory).to include(storage_location_1)
95+
expect(subject.num_locations_with_inventory).to eq(1)
9196
end
9297
end
9398

@@ -96,7 +101,7 @@
96101
let(:storage_locations) { [storage_location_1] }
97102

98103
it "should return an empty array" do
99-
expect(subject.locations_with_inventory).to eq([])
104+
expect(subject.num_locations_with_inventory).to eq(0)
100105
end
101106
end
102107
end

0 commit comments

Comments
 (0)