Skip to content

Commit 5c1ddf1

Browse files
authored
#5085 - Donations should have paginated totals for in-kind value (#5121)
* Added paginated in kind value * Added feature test for pagination values
1 parent a2a0ae1 commit 5c1ddf1

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

app/controllers/donations_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def index
3333
@donations_quantity = @donations.collect(&:total_quantity).sum
3434
@paginated_donations_quantity = @paginated_donations.collect(&:total_quantity).sum
3535
@total_value_all_donations = total_value(@donations)
36+
@paginated_in_kind_value = total_value(@paginated_donations)
3637
@total_money_raised = total_money_raised(@donations)
3738
@storage_locations = @donations.filter_map { |donation| donation.storage_location if !donation.storage_location.discarded_at }.compact.uniq.sort
3839
@selected_storage_location = filter_params[:at_storage_location]

app/views/donations/index.html.erb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<th>Money Raised</th>
112112
<th>In Kind Value</th>
113113
<th>Comments</th>
114-
<th>Actions</th>
114+
<th class="text-right">Actions</th>
115115
</tr>
116116
</thead>
117117
<tbody>
@@ -125,14 +125,25 @@
125125
<td></td>
126126
<td class="text-left numeric">
127127
<strong id="donation_quantity">
128-
<%= @donations_quantity %> (Total)
128+
<%= @donations_quantity %>
129+
<br>
130+
(Total)
129131
</strong>
130132
<br>
131-
<%= @paginated_donations_quantity %> (This page)
133+
<%= @paginated_donations_quantity %>
134+
<br>
135+
(This page)
132136
</td>
133137
<td class="text-left numeric"><strong><%= dollar_value(@total_money_raised) %></strong></td>
134-
<td class="text-left numeric"><strong><%= dollar_value(@total_value_all_donations) %></strong></td>
135-
<td></td>
138+
<td class="text-left numeric in-kind">
139+
<strong>
140+
<%= dollar_value(@total_value_all_donations) %> (Total)
141+
</strong>
142+
<br>
143+
<%= dollar_value(@paginated_in_kind_value) %>
144+
<br>
145+
(This page)
146+
</td>
136147
</tr>
137148
</tfoot>
138149
</table>

spec/system/donation_system_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
before do
1515
create(:donation)
16-
create(:donation)
16+
donation = create(:donation)
17+
create(:line_item, itemizable: donation, item: create(:item, value_in_cents: 300))
1718
visit subject
1819
end
1920

@@ -28,6 +29,11 @@
2829
expect(page.find(:css, "table", visible: true)).to have_content("20")
2930
end
3031

32+
it "displays total in kind value on the index page" do
33+
expect(page).to have_css("table td.in-kind", text: "$3.00")
34+
expect(page).to have_css("table td.in-kind", text: "(This page)")
35+
end
36+
3137
it "doesn't die when an inactive item is in a donation" do
3238
item = create(:item, :active, name: "INACTIVE ITEM")
3339
create(:donation, :with_items, item: item)
@@ -570,7 +576,7 @@
570576

571577
it "Allows the user to edit a donation" do
572578
total_quantity = find("#donation_quantity").text
573-
expect(total_quantity).to eq "100 (Total)"
579+
expect(total_quantity).to eq "100\n(Total)"
574580
click_on "View"
575581
expect(page).to have_content "Rare Candy"
576582

@@ -585,7 +591,7 @@
585591
click_on "Save"
586592

587593
total_quantity = find("#donation_quantity").text
588-
expect(total_quantity).to eq "200 (Total)"
594+
expect(total_quantity).to eq "200\n(Total)"
589595

590596
expect(Donation.count).to eq(1)
591597
donation = Donation.last
@@ -621,7 +627,7 @@
621627
# removing the line item is a lot more benign than randomly
622628
# switching the item on it to a different item
623629
total_quantity = find("#donation_quantity").text
624-
expect(total_quantity).to eq "0 (Total)"
630+
expect(total_quantity).to eq "0\n(Total)"
625631
end
626632
end
627633

@@ -679,7 +685,7 @@
679685

680686
expect(page).to have_content "Donation #{@donation.id} has been removed!"
681687
# deleted the only donation, ensure total now reads 0
682-
expect(page).to have_content "0 (Total)"
688+
expect(page).to have_content "0\n(Total)"
683689
end
684690
end
685691
end

0 commit comments

Comments
 (0)