mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Save subscription form on subs unpause so that proxy orders and orders are synced
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require 'open_food_network/permissions'
|
||||
require 'open_food_network/proxy_order_syncer'
|
||||
|
||||
module Admin
|
||||
class SubscriptionsController < ResourceController
|
||||
@@ -67,8 +68,13 @@ module Admin
|
||||
end
|
||||
|
||||
def unpause
|
||||
@subscription.update_attributes(paused_at: nil)
|
||||
render_as_json @subscription
|
||||
params[:subscription][:paused_at] = nil
|
||||
form = SubscriptionForm.new(@subscription, params[:subscription])
|
||||
if form.save
|
||||
render_as_json @subscription, order_update_issues: form.order_update_issues
|
||||
else
|
||||
render json: { errors: form.json_errors }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -664,6 +664,15 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
expect(json_response['id']).to eq subscription.id
|
||||
expect(subscription.reload.paused_at).to be nil
|
||||
end
|
||||
|
||||
context "when there is an open OC and no associated orders exist yet for it (OC was opened when the subscription was paused)" do
|
||||
it "creates an associated order" do
|
||||
spree_put :unpause, params
|
||||
|
||||
expect(subscription.reload.paused_at).to be nil
|
||||
expect(subscription.proxy_orders.size).to be 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user