Skip to content

Commit 1e875bb

Browse files
Merge branch 'main' into 5372AlignmentNudges
2 parents 6db73c5 + 6de15f3 commit 1e875bb

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed

app/controllers/purchases_controller.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def edit
6565
@purchase.line_items.build
6666
@audit_performed_and_finalized = Audit.finalized_since?(@purchase, @purchase.storage_location_id)
6767

68-
load_form_collections
68+
load_form_collections(@purchase)
6969
end
7070

7171
def show
@@ -78,9 +78,11 @@ def update
7878
ItemizableUpdateService.call(itemizable: @purchase,
7979
params: purchase_params,
8080
event_class: PurchaseEvent)
81+
82+
flash[:success] = "Purchase updated successfully"
8183
redirect_to purchases_path
8284
rescue => e
83-
load_form_collections
85+
load_form_collections(@purchase)
8486
flash.now[:alert] = "Error updating purchase: #{e.message}"
8587
render "edit"
8688
end
@@ -100,10 +102,13 @@ def destroy
100102

101103
private
102104

103-
def load_form_collections
105+
def load_form_collections(purchase = nil)
104106
@storage_locations = current_organization.storage_locations.active.alphabetized
105107
@items = current_organization.items.active.alphabetized
106-
@vendors = current_organization.vendors.active.alphabetized
108+
109+
@vendors = current_organization.vendors.active
110+
@vendors = @vendors.or(Vendor.where(id: purchase.vendor_id)) if purchase
111+
@vendors = @vendors.alphabetized
107112
end
108113

109114
def purchase_params

app/views/items/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<%= f.input_field :package_size, class: "form-control", min: 0 %>
4545
<% end %>
4646

47-
<% if Flipper.enabled?(:enable_packs) %>
47+
<% if Flipper.enabled?(:enable_packs) && current_organization.request_units.present? %>
4848
<%= f.input :request_units, label: "Additional Custom Request Units" do %>
4949
<%= f.association :request_units, as: :check_boxes, collection: current_organization.request_units, checked: selected_item_request_units(@item), label_method: :name, value_method: :id, class: "form-check-input" %>
5050
<% end %>

db/seeds.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def random_record_for_org(org, klass)
4242
organization.state = "IN"
4343
organization.zipcode = "12345"
4444
organization.email = "[email protected]"
45+
organization.bank_is_set_up = true
4546
end
4647
Organization.seed_items(pdx_org)
4748

@@ -51,6 +52,7 @@ def random_record_for_org(org, klass)
5152
organization.state = "CA"
5253
organization.zipcode = "90210"
5354
organization.email = "[email protected]"
55+
organization.bank_is_set_up = false #sf_org represents a brand new bank
5456
end
5557
Organization.seed_items(sf_org)
5658

@@ -60,6 +62,7 @@ def random_record_for_org(org, klass)
6062
organization.state = Faker::Address.state_abbr
6163
organization.zipcode = Faker::Address.zip_code
6264
organization.email = "[email protected]"
65+
organization.bank_is_set_up = true
6366
end
6467
Organization.seed_items(sc_org)
6568

spec/requests/items_requests_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@
111111
end
112112
end
113113

114+
context "when the organization has no request_units" do
115+
let(:item) { create(:item, organization: organization) }
116+
before { organization.request_units.destroy_all }
117+
118+
it "does not show the Additional Custom Request Units section" do
119+
get edit_item_path(item)
120+
expect(response.body).to_not match "Additional Custom Request Units"
121+
end
122+
end
123+
114124
context "when item is housing a kit" do
115125
let(:kit) { create(:kit, organization:) }
116126
let(:item) { create(:item, organization: organization, kit:) }

spec/system/purchase_system_spec.rb

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,66 @@
218218
# Bug fix -- Issue #378
219219
# A user can view another organizations purchase
220220
context "Editing purchase" do
221-
it "A user can see purchased_from value" do
222-
purchase = create(:purchase, purchased_from: "Old Vendor", organization: organization)
223-
visit edit_purchase_path(purchase)
224-
expect(page).to have_content("Vendor (Old Vendor)")
221+
context "with an eligible purchase" do
222+
let(:purchase) { create(:purchase, purchased_from: "Old Vendor", organization: organization) }
223+
224+
it "can view the edit page and vendor is present" do
225+
visit edit_purchase_path(purchase)
226+
227+
expect(page).to have_content("Vendor (Old Vendor)")
228+
end
229+
230+
it "can save the purchase" do
231+
visit edit_purchase_path(purchase)
232+
click_button "Save"
233+
234+
expect(page).to have_content("Purchase updated successfully")
235+
expect(page.current_path).to eq(purchases_path)
236+
end
237+
238+
context "with an error saving the purchase" do
239+
it "can save the purchase from the update page " do
240+
visit edit_purchase_path(purchase)
241+
242+
fill_in "purchase[amount_spent]", with: nil
243+
244+
click_button "Save"
245+
246+
expect(page).to have_content("Error updating purchase")
247+
expect(page.current_path).to eq(purchase_path(purchase))
248+
249+
fill_in "purchase[amount_spent]", with: "10"
250+
251+
click_button "Save"
252+
253+
expect(page).to have_content("Purchase updated successfully")
254+
expect(page.current_path).to eq(purchases_path)
255+
end
256+
end
257+
258+
context "with a deactivated vendor" do
259+
let(:deactivated_vendor) { create(:vendor, active: false) }
260+
let(:purchase) { create(:purchase, vendor: deactivated_vendor) }
261+
262+
it "can save the purchase" do
263+
visit edit_purchase_path(purchase)
264+
click_button "Save"
265+
266+
expect(page).to have_content("Purchase updated successfully")
267+
expect(page.current_path).to eq(purchases_path)
268+
end
269+
end
225270
end
226271

227-
it "A user can view another organizations purchase" do
228-
purchase = create(:purchase, organization: create(:organization))
229-
visit edit_purchase_path(purchase)
230-
expect(page).to have_content("Still haven't found what you're looking for")
272+
context "with another organization's purchase" do
273+
let(:another_organization) { create(:organization) }
274+
let(:purchase) { create(:purchase, organization: another_organization) }
275+
276+
it "cannot view the edit page" do
277+
visit edit_purchase_path(purchase)
278+
279+
expect(page).to have_content("Still haven't found what you're looking for")
280+
end
231281
end
232282
end
233283

0 commit comments

Comments
 (0)