Skip to content

Commit 79c9829

Browse files
committed
5021- Item List Break Fixed
1 parent ac8a209 commit 79c9829

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-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)
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)