Do not show flash message if we're performing an async update without reload

This commit is contained in:
Rohan Mitchell
2015-11-17 11:42:16 +11:00
parent 9fef0a9909
commit a2c0088c91
4 changed files with 21 additions and 5 deletions

View File

@@ -133,7 +133,7 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
update: (destination) ->
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc.$update {order_cycle_id: this.order_cycle.id}, (data) =>
oc.$update {order_cycle_id: this.order_cycle.id, reloading: (if destination? then 1 else 0)}, (data) =>
if data['success']
if destination?
$window.location = destination

View File

@@ -61,8 +61,8 @@ module Admin
respond_to do |format|
if @order_cycle.update_attributes(params[:order_cycle])
OpenFoodNetwork::OrderCycleFormApplicator.new(@order_cycle, spree_current_user).go!
flash[:notice] = 'Your order cycle has been updated.'
format.json { render :json => {:success => true} }
flash[:notice] = 'Your order cycle has been updated.' if params[:reloading] == '1'
format.json { render :json => {:success => true} }
else
format.json { render :json => {:success => false} }
end

View File

@@ -92,6 +92,22 @@ module Admin
end
end
describe "update" do
let(:order_cycle) { create(:simple_order_cycle) }
before { login_as_admin }
it "sets flash message when page is reloading" do
spree_put :update, id: order_cycle.id, reloading: '1', order_cycle: {}
flash[:notice].should == 'Your order cycle has been updated.'
end
it "does not set flash message otherwise" do
spree_put :update, id: order_cycle.id, reloading: '0', order_cycle: {}
flash[:notice].should be_nil
end
end
describe "bulk_update" do
let(:oc) { create(:simple_order_cycle) }
let!(:coordinator) { oc.coordinator }

View File

@@ -784,7 +784,7 @@ describe 'OrderCycle services', ->
it 'redirects to the destination page on success', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
$httpBackend.expectPUT('/admin/order_cycles.json', {
$httpBackend.expectPUT('/admin/order_cycles.json?reloading=1', {
order_cycle: 'this is the submit data'
}).respond {success: true}
@@ -795,7 +795,7 @@ describe 'OrderCycle services', ->
it 'does not redirect on error', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
$httpBackend.expectPUT('/admin/order_cycles.json', {
$httpBackend.expectPUT('/admin/order_cycles.json?reloading=1', {
order_cycle: 'this is the submit data'
}).respond {success: false}