Skip to content

Commit addf11e

Browse files
committed
5021 - Barcode new/Edit form breal fixed
1 parent 56e7201 commit addf11e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

app/controllers/barcode_items_controller.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Provides full CRUD+ for Barcode Items. These barcode items are all associated with regular Items. The one
22
# anomaly here is the :find action, which has some special logic built-in to it, see the comments below.
33
class BarcodeItemsController < ApplicationController
4+
before_action :load_items, only: %i[edit new]
45
def index
56
@items = current_organization.items.joins(:barcode_items)
67
@base_items = BaseItem.alphabetized
@@ -28,18 +29,17 @@ def create
2829
end
2930
else
3031
flash.now[:error] = "Something didn't work quite right -- try again?"
32+
load_items
3133
render action: :new
3234
end
3335
end
3436

3537
def new
3638
@barcode_item = current_organization.barcode_items.new
37-
@items = current_organization.items.alphabetized
3839
end
3940

4041
def edit
4142
@barcode_item = current_organization.barcode_items.includes(:barcodeable).find(params[:id])
42-
@items = current_organization.items.alphabetized
4343
end
4444

4545
def show
@@ -79,6 +79,7 @@ def update
7979
redirect_to barcode_items_path, notice: "Barcode updated!"
8080
else
8181
flash.now[:error] = "Something didn't work quite right -- try again?"
82+
load_items
8283
render action: :edit
8384
end
8485
end
@@ -102,6 +103,10 @@ def barcode_item_params
102103
params.require(:barcode_item).permit(:value, :barcodeable_id, :quantity).merge(organization_id: current_organization.id)
103104
end
104105

106+
def load_items
107+
@items = current_organization.items.alphabetized
108+
end
109+
105110
helper_method \
106111
def filter_params
107112
return {} unless params.key?(:filters)

spec/requests/barcode_items_requests_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,33 @@
130130
end
131131
end
132132

133+
context 'while signed in as organization admin' do
134+
let!(:barcode_items) { create_list(:barcode_item, 6, organization: organization) }
135+
let(:items) { barcode_items.map(&:barcodeable) }
136+
let(:barcode_item) { barcode_items.first }
137+
before do
138+
sign_in(organization_admin)
139+
end
140+
141+
describe "GET #new" do
142+
it "The new barcode item form should contain the Items even after a failed save" do
143+
post barcode_items_path, params: { barcode_item: {value: 10, quantity: 20 } }
144+
items.each do |item|
145+
expect(response.body).to include(item.name)
146+
end
147+
end
148+
end
149+
150+
describe "GET #edit" do
151+
it "The Edit Barcode Item form should contain the Items even after a failed update" do
152+
put barcode_item_path(barcode_item.id), params: { barcode_item: { value: 10, quantity: '', barcodeable_id: items.first.id} }
153+
items.each do |item|
154+
expect(response.body).to include(item.name)
155+
end
156+
end
157+
end
158+
end
159+
133160
# For the time being, users cannot access these routes, but this may change in
134161
# the near future.
135162
# context "While not signed in" do

0 commit comments

Comments
 (0)