Skip to content

Commit ae29624

Browse files
authored
Merge branch 'main' into allow-the-superuser-to-reinvite-users
2 parents 11ebaf3 + f005fbc commit ae29624

10 files changed

Lines changed: 145 additions & 27 deletions

File tree

Gemfile.lock

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,30 @@ GEM
7676
addressable (2.8.7)
7777
public_suffix (>= 2.0.2, < 7.0)
7878
afm (0.2.2)
79-
annotaterb (4.14.0)
79+
annotaterb (4.16.0)
80+
activerecord (>= 6.0.0)
81+
activesupport (>= 6.0.0)
8082
ast (2.4.3)
8183
autoprefixer-rails (10.4.13.0)
8284
execjs (~> 2)
8385
awesome_print (1.9.2)
84-
aws-eventstream (1.3.1)
85-
aws-partitions (1.1050.0)
86-
aws-sdk-core (3.218.1)
86+
aws-eventstream (1.4.0)
87+
aws-partitions (1.1123.0)
88+
aws-sdk-core (3.226.1)
8789
aws-eventstream (~> 1, >= 1.3.0)
8890
aws-partitions (~> 1, >= 1.992.0)
8991
aws-sigv4 (~> 1.9)
9092
base64
9193
jmespath (~> 1, >= 1.6.1)
92-
aws-sdk-kms (1.98.0)
93-
aws-sdk-core (~> 3, >= 3.216.0)
94+
logger
95+
aws-sdk-kms (1.106.0)
96+
aws-sdk-core (~> 3, >= 3.225.0)
9497
aws-sigv4 (~> 1.5)
95-
aws-sdk-s3 (1.181.0)
96-
aws-sdk-core (~> 3, >= 3.216.0)
98+
aws-sdk-s3 (1.191.0)
99+
aws-sdk-core (~> 3, >= 3.225.0)
97100
aws-sdk-kms (~> 1)
98101
aws-sigv4 (~> 1.5)
99-
aws-sigv4 (1.11.0)
102+
aws-sigv4 (1.12.1)
100103
aws-eventstream (~> 1, >= 1.0.2)
101104
azure-storage-blob (2.0.3)
102105
azure-storage-common (~> 2.0)
@@ -120,7 +123,7 @@ GEM
120123
erubi (~> 1.4)
121124
parser (>= 2.4)
122125
smart_properties
123-
bigdecimal (3.2.1)
126+
bigdecimal (3.2.2)
124127
bindex (0.8.1)
125128
binding_of_caller (1.0.1)
126129
debug_inspector (>= 1.2.0)
@@ -135,7 +138,7 @@ GEM
135138
bugsnag (6.27.1)
136139
concurrent-ruby (~> 1.0)
137140
builder (3.3.0)
138-
bullet (8.0.5)
141+
bullet (8.0.8)
139142
activesupport (>= 3.0.0)
140143
uniform_notifier (~> 1.11)
141144
capybara (3.40.0)
@@ -235,11 +238,11 @@ GEM
235238
smart_properties
236239
erubi (1.13.1)
237240
execjs (2.10.0)
238-
factory_bot (6.5.0)
239-
activesupport (>= 5.0.0)
240-
factory_bot_rails (6.4.4)
241+
factory_bot (6.5.4)
242+
activesupport (>= 6.1.0)
243+
factory_bot_rails (6.5.0)
241244
factory_bot (~> 6.5)
242-
railties (>= 5.0.0)
245+
railties (>= 6.1.0)
243246
faker (3.5.1)
244247
i18n (>= 1.8.11, < 2)
245248
faraday (1.10.4)
@@ -277,11 +280,11 @@ GEM
277280
ffi (1.17.2-x86_64-darwin)
278281
ffi (1.17.2-x86_64-linux-gnu)
279282
filterrific (5.2.7)
280-
flipper (1.3.4)
283+
flipper (1.3.5)
281284
concurrent-ruby (< 2)
282-
flipper-active_record (1.3.4)
285+
flipper-active_record (1.3.5)
283286
activerecord (>= 4.2, < 9)
284-
flipper (~> 1.3.4)
287+
flipper (~> 1.3.5)
285288
flipper-ui (1.3.4)
286289
erubi (>= 1.0.0, < 2.0.0)
287290
flipper (~> 1.3.4)
@@ -334,7 +337,7 @@ GEM
334337
activesupport (>= 5.0.0)
335338
jmespath (1.6.2)
336339
json (2.11.3)
337-
jwt (2.10.1)
340+
jwt (3.1.2)
338341
base64
339342
kaminari (1.2.2)
340343
activesupport (>= 4.1.0)
@@ -509,8 +512,8 @@ GEM
509512
puma (6.6.0)
510513
nio4r (~> 2.0)
511514
racc (1.8.1)
512-
rack (3.1.15)
513-
rack-mini-profiler (3.3.1)
515+
rack (3.1.16)
516+
rack-mini-profiler (4.0.0)
514517
rack (>= 1.2.0)
515518
rack-protection (4.1.1)
516519
base64 (>= 0.1.0)
@@ -566,7 +569,7 @@ GEM
566569
rb-fsevent (0.11.2)
567570
rb-inotify (0.10.1)
568571
ffi (~> 1.0)
569-
rdoc (6.14.0)
572+
rdoc (6.14.1)
570573
erb
571574
psych (>= 4.0.0)
572575
recaptcha (5.19.0)
@@ -707,15 +710,15 @@ GEM
707710
tilt (2.2.0)
708711
timeout (0.4.3)
709712
ttfunk (1.7.0)
710-
turbo-rails (2.0.13)
713+
turbo-rails (2.0.16)
711714
actionpack (>= 7.1.0)
712715
railties (>= 7.1.0)
713716
tzinfo (2.0.6)
714717
concurrent-ruby (~> 1.0)
715718
unicode-display_width (3.1.4)
716719
unicode-emoji (~> 4.0, >= 4.0.4)
717720
unicode-emoji (4.0.4)
718-
uniform_notifier (1.16.0)
721+
uniform_notifier (1.17.0)
719722
uri (1.0.3)
720723
useragent (0.16.11)
721724
version_gem (1.1.8)

app/controllers/item_categories_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def update
3333
end
3434
end
3535

36+
def destroy
37+
@item_category = current_organization.item_categories.find_by(id: params[:id])
38+
if @item_category.items.exists?
39+
flash[:alert] = "Cannot delete item category because it has associated items."
40+
else
41+
@item_category.destroy
42+
flash[:notice] = "#{@item_category.name} has been deleted."
43+
end
44+
redirect_to items_path
45+
end
46+
3647
private
3748

3849
def item_category_params

app/models/item_category.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,16 @@ class ItemCategory < ApplicationRecord
1616

1717
belongs_to :organization
1818
has_many :items, -> { order(name: :asc) }, inverse_of: :item_category, dependent: :nullify
19-
has_many :partner_groups, dependent: :nullify
19+
has_and_belongs_to_many :partner_groups, dependent: :nullify
20+
21+
before_destroy :ensure_no_associated_partner_groups
22+
23+
private
24+
25+
def ensure_no_associated_partner_groups
26+
if partner_groups.exists?
27+
errors.add(:base, "Cannot delete item category with associated partner groups")
28+
throw(:abort)
29+
end
30+
end
2031
end

app/pdfs/picklists_pdf.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ def compute_and_render
7676
font_size 10
7777
end
7878

79+
# Add quota information only if quota is set and greater than 0
80+
quota = request.partner.quota
81+
if quota && quota > 0
82+
move_down 5
83+
text "Quota:", style: :bold, align: :right
84+
font_size 12
85+
text quota.to_s, align: :right
86+
font_size 10
87+
end
88+
7989
move_down 10
8090
text "Comments:", style: :bold
8191
font_size 12

app/views/items/_item_categories.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
<% end %>
2828
</ul>
2929
</td>
30-
<td>
30+
<td class="text-right">
3131
<%= view_button_to item_category_path(item_category) %>
3232
<%= edit_button_to edit_item_category_path(item_category.id) %>
33+
<%= delete_button_to(item_category_path(item_category.id), { confirm: confirm_delete_msg(item_category.name) }) if (item_category.items.count <= 0) %>
3334
</td>
3435
</tr>
3536
<% end %>

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
t.bigint "old_partner_id"
325325
t.boolean "archived", default: false
326326
t.index ["partner_id"], name: "index_families_on_partner_id"
327-
end
327+
end
328328

329329
create_table "flipper_features", force: :cascade do |t|
330330
t.string "key", null: false
-56.1 KB
Loading

spec/models/item_category_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,24 @@
2828
describe "versioning" do
2929
it { is_expected.to be_versioned }
3030
end
31+
32+
describe "delete" do
33+
let(:item_category) { create(:item_category) }
34+
let(:partner_group) { create(:partner_group, item_categories: [item_category]) }
35+
36+
before do
37+
partner_group
38+
end
39+
40+
it "should not delete if associated with partner groups" do
41+
expect(item_category.partner_groups).not_to be_empty
42+
expect { item_category.destroy }.not_to change(ItemCategory, :count)
43+
expect(item_category.errors.full_messages).to include("Cannot delete item category with associated partner groups")
44+
end
45+
46+
it "should delete if not associated with partner groups" do
47+
item_category.partner_groups.destroy_all
48+
expect { item_category.destroy }.to change(ItemCategory, :count).by(-1)
49+
end
50+
end
3151
end

spec/pdfs/picklists_pdf_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@
6767
expect(pdf_test.page(1).text).to include(request.partner.profile.pick_up_phone)
6868
end
6969
end
70+
71+
context "when partner has a quota" do
72+
it "renders the quota information when quota is set" do
73+
partner = create(:partner)
74+
partner.update(quota: 100)
75+
request = create(:request, :pending, organization: organization, partner: partner)
76+
create(:item_request, request: request, item: item1, name: "Item 1")
77+
78+
pdf = described_class.new(organization, [request])
79+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
80+
81+
expect(pdf_test.page(1).text).to include("Quota:")
82+
expect(pdf_test.page(1).text).to include("100")
83+
end
84+
85+
it "does not render quota information when quota is not set" do
86+
partner = create(:partner, quota: nil)
87+
request = create(:request, :pending, organization: organization, partner: partner)
88+
create(:item_request, request: request, item: item1, name: "Item 1")
89+
90+
pdf = described_class.new(organization, [request])
91+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
92+
93+
expect(pdf_test.page(1).text).not_to include("Quota:")
94+
end
95+
96+
it "does not render quota information when quota is zero" do
97+
partner = create(:partner, quota: 0)
98+
request = create(:request, :pending, organization: organization, partner: partner)
99+
create(:item_request, request: request, item: item1, name: "Item 1")
100+
101+
pdf = described_class.new(organization, [request])
102+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
103+
104+
expect(pdf_test.page(1).text).not_to include("Quota:")
105+
end
106+
end
70107
end
71108

72109
context "When packs are not enabled" do

spec/requests/item_categories_requests_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,29 @@
9393
end
9494
end
9595
end
96+
97+
describe "DELETE #destroy" do
98+
let!(:item_category) { create(:item_category, organization: organization) }
99+
100+
context "when the item category has no associated items" do
101+
it "destroys the requested item category" do
102+
expect {
103+
delete item_category_url(id: item_category.id)
104+
}.to change(ItemCategory, :count).by(-1)
105+
expect(response).to redirect_to(items_path)
106+
end
107+
end
108+
109+
context "when the item category has associated items" do
110+
let!(:item) { create(:item, item_category: item_category) }
111+
112+
it "does not destroy the item category and shows an error" do
113+
expect {
114+
delete item_category_url(id: item_category.id)
115+
}.not_to change(ItemCategory, :count)
116+
expect(response).to redirect_to(items_path)
117+
expect(flash[:alert]).to eq("Cannot delete item category because it has associated items.")
118+
end
119+
end
120+
end
96121
end

0 commit comments

Comments
 (0)