Skip to content

Commit 6fa8d65

Browse files
authored
4745: Disable deactivate button for storage locations not deactivatable (#4775)
* 4745: Disable deactivate button for storage locations not deactivatable * Remove @inventory_item_totals instance variable from storage locations controller
1 parent f0b9f80 commit 6fa8d65

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

app/controllers/storage_locations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def index
1414
@items = StorageLocation.items_inventoried(current_organization, @inventory)
1515
@include_inactive_storage_locations = params[:include_inactive_storage_locations].present?
1616
@storage_locations = current_organization.storage_locations.alphabetized
17-
if @inventory && filter_params[:containing].present?
17+
if filter_params[:containing].present?
1818
containing_ids = @inventory.storage_locations.keys.select do |sl|
1919
@inventory.quantity_for(item_id: filter_params[:containing], storage_location: sl).positive?
2020
end

app/views/storage_locations/_storage_location_row.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
<td><%= storage_location.address %></td>
44
<td><%= storage_location.square_footage %></td>
55
<td><%= storage_location.warehouse_type %></td>
6-
<td><%= @inventory ? @inventory.quantity_for(storage_location: storage_location.id) : storage_location.size %></td>
6+
<td><%= @inventory.quantity_for(storage_location: storage_location.id) %></td>
77
<td><%= number_to_currency(storage_location.inventory_total_value_in_dollars(@inventory)) %></td>
88
<td class="text-right">
99
<%= view_button_to storage_location %>
1010
<%= edit_button_to edit_storage_location_path(storage_location) %>
1111
<% if storage_location.discarded? %>
1212
<%= reactivate_button_to storage_location_reactivate_path(storage_location), { confirm: confirm_reactivate_msg(storage_location.name) } %>
1313
<% else %>
14-
<%= deactivate_button_to storage_location_deactivate_path(storage_location), { confirm: confirm_deactivate_msg(storage_location.name) } %>
14+
<%= deactivate_button_to storage_location_deactivate_path(storage_location),
15+
{ confirm: confirm_deactivate_msg(storage_location.name), enabled: @inventory.quantity_for(storage_location: storage_location.id).zero? } %>
1516
<% end %>
1617
</td>
1718
</tr>

spec/requests/storage_locations_requests_spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
end
1010

1111
describe "GET #index" do
12-
before { create(:storage_location, name: "Test Storage Location", address: "123 Donation Site Way", warehouse_type: StorageLocation::WAREHOUSE_TYPES.first) }
12+
let!(:storage_location) do
13+
create(:storage_location,
14+
name: "Test Storage Location",
15+
address: "123 Donation Site Way",
16+
warehouse_type: StorageLocation::WAREHOUSE_TYPES.first)
17+
end
1318

1419
context "html" do
1520
let(:response_format) { 'html' }
@@ -34,6 +39,29 @@
3439
end
3540
end
3641
end
42+
43+
context "with empty storage location" do
44+
it "shows a deactivate button" do
45+
get storage_locations_path(format: response_format)
46+
page = Nokogiri::HTML(response.body)
47+
deactivate_link = page.at_css("a[href='#{storage_location_deactivate_path(storage_location)}']")
48+
expect(deactivate_link.attr("class")).not_to match(/disabled/)
49+
end
50+
end
51+
52+
context "with nonempty storage location" do
53+
before do
54+
TestInventory.create_inventory(storage_location.organization,
55+
{ storage_location.id => { create(:item, name: "A").id => 1 } })
56+
end
57+
58+
it "shows a disabled deactivate button" do
59+
get storage_locations_path(format: response_format)
60+
page = Nokogiri::HTML(response.body)
61+
deactivate_link = page.at_css("a[href='#{storage_location_deactivate_path(storage_location)}']")
62+
expect(deactivate_link.attr("class")).to match(/disabled/)
63+
end
64+
end
3765
end
3866

3967
context "csv" do

spec/system/storage_location_system_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@
134134
location1 = create(:storage_location, :with_items)
135135
visit subject
136136

137-
expect(accept_confirm { click_on "Deactivate", match: :first }).to include "Are you sure you want to deactivate #{location1.name}"
138-
expect(page.find(".alert")).to have_content "Cannot deactivate storage location containing inventory items with non-zero quantities"
137+
expect(page).to have_link('Deactivate', class: "disabled", href: "/storage_locations/#{location1.id}/deactivate")
139138
end
140139

141140
it "Allows user to deactivate and reactivate storage locations" do

0 commit comments

Comments
 (0)