Skip to content

Commit 17027d7

Browse files
committed
5021- Item List Break Fixed
1 parent ac8a209 commit 17027d7

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

app/controllers/barcode_items_controller.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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 index new]
45
def index
5-
@items = current_organization.items.joins(:barcode_items)
66
@base_items = BaseItem.alphabetized
77
@selected_barcodeable_id = filter_params[:barcodeable_id]
88
@selected_partner_key = filter_params[:by_item_partner_key]
@@ -28,18 +28,17 @@ def create
2828
end
2929
else
3030
flash.now[:error] = "Something didn't work quite right -- try again?"
31+
load_items
3132
render action: :new
3233
end
3334
end
3435

3536
def new
3637
@barcode_item = current_organization.barcode_items.new
37-
@items = current_organization.items.alphabetized
3838
end
3939

4040
def edit
4141
@barcode_item = current_organization.barcode_items.includes(:barcodeable).find(params[:id])
42-
@items = current_organization.items.alphabetized
4342
end
4443

4544
def show
@@ -79,6 +78,7 @@ def update
7978
redirect_to barcode_items_path, notice: "Barcode updated!"
8079
else
8180
flash.now[:error] = "Something didn't work quite right -- try again?"
81+
load_items
8282
render action: :edit
8383
end
8484
end
@@ -102,6 +102,10 @@ def barcode_item_params
102102
params.require(:barcode_item).permit(:value, :barcodeable_id, :quantity).merge(organization_id: current_organization.id)
103103
end
104104

105+
def load_items
106+
@items = current_organization.items.joins(:barcode_items)
107+
end
108+
105109
helper_method \
106110
def filter_params
107111
return {} unless params.key?(:filters)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "BarcodeItems", type: :system do
4+
let(:organization) { create(:organization) }
5+
let(:organization_admin) { create(:organization_admin, organization: organization) }
6+
let!(:barcode_items) { create_list(:barcode_item, 6, organization: organization) }
7+
let(:items) { barcode_items.map(&:barcodeable) }
8+
let(:barcode_item) { barcode_items.first }
9+
10+
context "when organizational admin is signed in" do
11+
before do
12+
sign_in(organization_admin)
13+
end
14+
describe "Creating a Barcode Item" do
15+
before { visit new_barcode_item_path }
16+
17+
it "retains item dropdown options after an unsuccessful form submission" do
18+
select items.first.name, from: "Item"
19+
click_button "Save"
20+
expect(page).to have_content("Something didn't work quite right -- try again?")
21+
items.each do |item|
22+
expect(page).to have_select("Item", with_options: [item.name])
23+
end
24+
end
25+
end
26+
27+
describe "Editing a Barcode Item" do
28+
before { visit edit_barcode_item_path(barcode_item) }
29+
it "retains item dropdown options after an unsuccessful form submission" do
30+
fill_in "Barcode", with: ""
31+
click_button "Save"
32+
expect(page).to have_content("Something didn't work quite right -- try again?")
33+
items.each do |item|
34+
expect(page).to have_select("Item", with_options: [item.name])
35+
end
36+
end
37+
end
38+
39+
describe "when admin visits index page" do
40+
before { visit barcode_items_path }
41+
42+
it "displays all barcode items" do
43+
barcode_items.each do |barcode_item|
44+
expect(page).to have_content(barcode_item.value)
45+
expect(page).to have_content(barcode_item.quantity)
46+
expect(page).to have_content(barcode_item.barcodeable_type)
47+
end
48+
end
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)