File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff 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
@@ -82,7 +82,7 @@ def update
8282 flash [ :success ] = "Purchase updated successfully"
8383 redirect_to purchases_path
8484 rescue => e
85- load_form_collections
85+ load_form_collections ( @purchase )
8686 flash . now [ :alert ] = "Error updating purchase: #{ e . message } "
8787 render "edit"
8888 end
@@ -102,10 +102,13 @@ def destroy
102102
103103 private
104104
105- def load_form_collections
105+ def load_form_collections ( purchase = nil )
106106 @storage_locations = current_organization . storage_locations . active . alphabetized
107107 @items = current_organization . items . active . alphabetized
108- @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
109112 end
110113
111114 def purchase_params
Original file line number Diff line number Diff line change 254254 expect ( page . current_path ) . to eq ( purchases_path )
255255 end
256256 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
257270 end
258271
259272 context "with another organization's purchase" do
You can’t perform that action at this time.
0 commit comments