Skip to content

Commit

Permalink
🧹 Marketplace: DeliveryConstraints only set in DeliveryArea
Browse files Browse the repository at this point in the history
- Prerequisite for #1420

- #1325
- #1136
- #1185

This does not get rid of the reading of the fields; but it does make it
so they are no longer writable; which will make the "stop reading from
them!" PR a bit tidier.
  • Loading branch information
zspencer committed Apr 30, 2023
1 parent 1c89b6e commit 1fe029a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/furniture/marketplace/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Cart < Record

belongs_to :shopper, inverse_of: :carts

belongs_to :delivery_area, inverse_of: :carts, optional: true

has_many :cart_products, dependent: :destroy, inverse_of: :cart
has_many :products, through: :cart_products, inverse_of: :carts

Expand Down
1 change: 1 addition & 0 deletions app/furniture/marketplace/delivery_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DeliveryArea < Record

belongs_to :marketplace, inverse_of: :delivery_areas
has_many :orders, inverse_of: :delivery_area
has_many :carts, inverse_of: :delivery_area
has_many :deliveries, inverse_of: :delivery_area

attribute :delivery_window, ::Marketplace::Delivery::WindowType.new
Expand Down
4 changes: 1 addition & 3 deletions app/furniture/marketplace/marketplaces/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div class="mt-3">
<%= form_with model: marketplace.location do |f| %>
<%= render "money_field", { attribute: :delivery_fee, form: f, min: 0, step: 0.01} %>
<%= render "text_field", { attribute: :notify_emails, form: f } %>
<%= render "text_field", { attribute: :order_by, form: f } %>
<%= render "text_field", { attribute: :delivery_window, form: f } %>

<%= f.submit %>
<% end %>
</div>
2 changes: 2 additions & 0 deletions spec/furniture/marketplace/cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

it { is_expected.to belong_to(:shopper).inverse_of(:carts) }

it { is_expected.to belong_to(:delivery_area).inverse_of(:carts).optional }

describe "#price_total" do
subject(:price_total) { cart.price_total }

Expand Down
1 change: 1 addition & 0 deletions spec/furniture/marketplace/delivery_area_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
RSpec.describe Marketplace::DeliveryArea, type: :model do
it { is_expected.to belong_to(:marketplace).inverse_of(:delivery_areas) }
it { is_expected.to have_many(:orders).inverse_of(:delivery_area) }
it { is_expected.to have_many(:carts).inverse_of(:delivery_area) }
it { is_expected.to have_many(:deliveries).inverse_of(:delivery_area) }
end

0 comments on commit 1fe029a

Please sign in to comment.