Save subscription form on subs unpause so that proxy orders and orders are synced

This commit is contained in:
luisramos0
2019-07-17 10:26:14 +01:00
parent b3c378e8c1
commit 57f1742f24
2 changed files with 17 additions and 2 deletions

View File

@@ -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

View File

@@ -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