Skip to content

Commit b275438

Browse files
committed
πŸžπŸ”¨Marketplace: Buying Products with one unarchived DeliveryArea
- #2198 When we added [archiving delivery areas], I didn't take into account that `Marketplace#cart_for_shopper` was checking against all the delivery areas. This fixes that and adds a system spec to make sure we can still checkout after! [archiving delivery areas]: #2024
1 parent ed4f6a3 commit b275438

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

β€Žapp/furniture/marketplace/carts/_footer.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<%= render "marketplace/carts/total", cart: cart %>
1111
</td>
1212
</tr>
13+
1314
<%- if cart.ready_for_checkout? %>
1415
<tr>
1516
<td class="text-right py-3.5" colspan="8">

β€Žapp/furniture/marketplace/marketplace.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def square_order_notifications_enabled?
132132
end
133133

134134
def default_delivery_area
135-
(delivery_areas.size == 1) ? delivery_areas.first : nil
135+
(delivery_areas.unarchived.size == 1) ? delivery_areas.unarchived.first : nil
136136
end
137137
end
138138
end

β€Žspec/furniture/marketplace/buying_products_system_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ def url_options
5050
end
5151
end
5252

53+
describe "when the `Marketplace` has one active `DeliveryArea`" do
54+
it "allows Checkout" do
55+
archived_delivery_area = create(:marketplace_delivery_area,
56+
marketplace: marketplace, label: "Oakland", price_cents: 10_00)
57+
archived_delivery_area.archive
58+
visit(polymorphic_path(marketplace.room.location))
59+
60+
add_product_to_cart(marketplace.products.first)
61+
62+
expect { click_link("Checkout") }.not_to raise_error
63+
end
64+
end
65+
5366
it "Doesn't offer archived Products for sale" do
5467
archived_product = create(:marketplace_product, :archived, marketplace:)
5568

β€Žspec/furniture/marketplace/marketplace_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
cart = marketplace.cart_for_shopper(shopper:)
6565
expect(cart.delivery_area).to be_nil
6666
end
67+
68+
context "when only one of them is unarchived" do
69+
before { marketplace.delivery_areas.first.archive }
70+
71+
it "sets the default delivery area to the single unarchived one" do
72+
cart = marketplace.cart_for_shopper(shopper:)
73+
expect(cart.delivery_area).to eq(marketplace.delivery_areas.unarchived.first)
74+
end
75+
end
6776
end
6877
end
6978

0 commit comments

Comments
Β (0)