Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/views/storage_locations/_storage_location_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<td><%= storage_location.address %></td>
<td><%= storage_location.square_footage %></td>
<td><%= storage_location.warehouse_type %></td>
<td><%= @inventory.quantity_for(storage_location: storage_location.id) %></td>
<td><%= number_to_currency(storage_location.inventory_total_value_in_dollars(@inventory)) %></td>
<td class="text-right"><%= @inventory.quantity_for(storage_location: storage_location.id) %></td>
<td class="text-right"><%= number_to_currency(storage_location.inventory_total_value_in_dollars(@inventory)) %></td>
<td class="text-right">
<%= view_button_to storage_location %>
<%= edit_button_to edit_storage_location_path(storage_location) %>
Expand Down
12 changes: 10 additions & 2 deletions app/views/storage_locations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,21 @@
<th>Address</th>
<th>Square Footage</th>
<th>Warehouse Type</th>
<th>Total Inventory</th>
<th>Fair Market Value</th>
<th class="text-right">Total Inventory</th>
<th class="text-right">Fair Market Value</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<%= render partial: "storage_location_row", collection: @storage_locations, as: :storage_location %>
<tr>
<td colspan="4"><strong>Total</strong></td>
<td class="text-right">
<%= @storage_locations.sum { |sl| @inventory.quantity_for(storage_location: sl.id) } %>
</td>
<td class="text-right"><%= number_to_currency(@storage_locations.sum { |sl| sl.inventory_total_value_in_dollars(@inventory) }) %></td>
<td></td>
</tr>
</tbody>
</table>
</div>
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/storage_locations_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
address: "123 Donation Site Way",
warehouse_type: StorageLocation::WAREHOUSE_TYPES.first)
end
let!(:storage_location2) do
create(:storage_location,
name: "Test Storage Location 1",
address: "123 Donation Site Way",
warehouse_type: StorageLocation::WAREHOUSE_TYPES.first)
end

context "html" do
let(:response_format) { 'html' }
Expand All @@ -24,6 +30,25 @@
expect(response).to be_successful
end

it "displays grand total across storage locations" do
item1 = create(:item, name: "Item A", value_in_cents: 100)
item2 = create(:item, name: "Item B", value_in_cents: 200)

TestInventory.create_inventory(storage_location.organization,
{ storage_location.id => { item1.id => 2, item2.id => 1 } })
TestInventory.create_inventory(storage_location2.organization,
{ storage_location2.id => { item1.id => 3 } })
get storage_locations_path(format: response_format)
page = Nokogiri::HTML(response.body)

total_row = page.at("table tbody tr:last-child")
total_inventory = total_row.css("td.text-right")[0].text.strip
total_value = total_row.css("td.text-right")[1].text.strip

expect(total_inventory).to eq("6")
expect(total_value).to eq("$7.00")
end

context "with inactive locations" do
let!(:discarded_storage_location) { create(:storage_location, name: "Some Random Location", discarded_at: rand(10.years).seconds.ago) }

Expand Down Expand Up @@ -132,6 +157,7 @@
Storage Location with Items,123 Donation Site Way,100,Residential space used,3,1,1,1,0
Storage Location with Unique Items,Smithsonian Conservation Center new,100,Residential space used,5,0,0,0,5
Test Storage Location,123 Donation Site Way,100,Residential space used,0,0,0,0,0
Test Storage Location 1,123 Donation Site Way,100,Residential space used,0,0,0,0,0
CSV
expect(response.body).to eq(csv)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/system/storage_location_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@
select item.name, from: "filters[containing]"
click_button "Filter"

expect(page).to have_css("table tr", count: 2)
expect(page).to have_css("table tr", count: 3)
expect(page).to have_xpath("//table/tbody/tr/td", text: location1.name)
expect(page).not_to have_xpath("//table/tbody/tr/td", text: location2.name)
expect(page).not_to have_xpath("//table/tbody/tr/td", text: location3.name)

check "include_inactive_storage_locations"
click_button "Filter"

expect(page).to have_css("table tr", count: 3)
expect(page).to have_css("table tr", count: 4)
expect(page).to have_xpath("//table/tbody/tr/td", text: location3.name)
end

Expand Down
Loading