Merge pull request #4809 from jeduardo824/redirect-to-shops-when-shop-does-not-exist

redirect to shops list when an enterprise is not found
This commit is contained in:
Pau Pérez Fabregat
2020-03-06 18:39:00 +01:00
committed by GitHub
3 changed files with 23 additions and 2 deletions

View File

@@ -63,8 +63,6 @@ class EnterprisesController < BaseController
end
def reset_order
distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) ||
Enterprise.is_distributor.find(params[:id])
order = current_order(true)
reset_distributor(order, distributor)
@@ -74,6 +72,14 @@ class EnterprisesController < BaseController
reset_order_cycle(order, distributor)
order.save!
rescue ActiveRecord::RecordNotFound
flash[:error] = I18n.t(:enterprise_shop_show_error)
redirect_to shops_path
end
def distributor
@distributor ||= Enterprise.is_distributor.find_by_permalink(params[:id]) ||
Enterprise.is_distributor.find(params[:id])
end
def reset_distributor(order, distributor)

View File

@@ -2412,6 +2412,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
enterprise_register_success_notice: "Congratulations! Registration for %{enterprise} is complete!"
enterprise_bulk_update_success_notice: "Enterprises updated successfully"
enterprise_bulk_update_error: 'Update failed'
enterprise_shop_show_error: "The shop you are looking for doesn't exist or is inactive on OFN. Please check other shops."
order_cycles_create_notice: 'Your order cycle has been created.'
order_cycles_update_notice: 'Your order cycle has been updated.'
order_cycles_bulk_update_notice: 'Order cycles have been updated.'

View File

@@ -139,4 +139,18 @@ describe EnterprisesController, type: :controller do
expect(response.status).to be 409
end
end
context "checking access on nonexistent enterprise" do
before do
spree_get :shop, id: "some_nonexistent_enterprise"
end
it "redirects to shops_path" do
expect(response).to redirect_to shops_path
end
it "shows a flash message with the error" do
expect(request.flash[:error]).to eq(I18n.t(:enterprise_shop_show_error))
end
end
end