mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Merge pull request #13224 from Tresor11/tb-rescue-not-found-error-for-enterprise
Fix: Admin visiting non-existent enterprise raises error
This commit is contained in:
@@ -15,6 +15,7 @@ module Admin
|
||||
prepend_before_action :override_sells, only: :create
|
||||
|
||||
before_action :load_countries, except: [:index, :register, :check_permalink]
|
||||
before_action :require_enterprise, only: [:edit, :update]
|
||||
before_action :load_methods_and_fees, only: [:edit, :update]
|
||||
before_action :load_groups, only: [:new, :edit, :update, :create]
|
||||
before_action :load_taxons, only: [:new, :edit, :update, :create]
|
||||
@@ -216,6 +217,10 @@ module Admin
|
||||
[:index, :for_order_cycle, :visible, :bulk_update]
|
||||
end
|
||||
|
||||
def require_enterprise
|
||||
raise ActiveRecord::RecordNotFound if @enterprise.blank?
|
||||
end
|
||||
|
||||
def load_methods_and_fees
|
||||
enterprise_payment_methods = @enterprise.payment_methods.to_a
|
||||
enterprise_shipping_methods = @enterprise.shipping_methods.to_a
|
||||
|
||||
@@ -629,7 +629,7 @@ en:
|
||||
price: Price
|
||||
producer: Producer
|
||||
category: Category
|
||||
sku: SKU
|
||||
sku: SKU
|
||||
on_hand: "On Hand"
|
||||
on_demand: "On Demand"
|
||||
tax_category: "Tax Category"
|
||||
@@ -641,7 +641,7 @@ en:
|
||||
price: Price
|
||||
producer: Producer
|
||||
category: Category
|
||||
sku: SKU
|
||||
sku: SKU
|
||||
on_hand: "On Hand"
|
||||
on_demand: "On Demand"
|
||||
tax_category: "Tax Category"
|
||||
@@ -652,7 +652,7 @@ en:
|
||||
clone: Clone
|
||||
delete: Delete
|
||||
remove: Remove
|
||||
preview: Preview
|
||||
preview: Preview
|
||||
image:
|
||||
edit: Edit
|
||||
product_preview:
|
||||
@@ -801,7 +801,7 @@ en:
|
||||
connected_apps_enabled:
|
||||
discover_regen: Discover Regenerative portal
|
||||
affiliate_sales_data: DFC anonymised orders API for research purposes
|
||||
vine: Voucher Integration Engine (VINE)
|
||||
vine: Voucher Integration Engine (VINE)
|
||||
update:
|
||||
resource: Connected app settings
|
||||
|
||||
@@ -1430,7 +1430,7 @@ en:
|
||||
use_limit: Use/Limit
|
||||
customers: Customer
|
||||
net_value: Net Value
|
||||
active: Active?
|
||||
active: Active?
|
||||
add_new: Add New
|
||||
no_voucher_yet: No Vouchers yet
|
||||
white_label:
|
||||
@@ -2140,7 +2140,7 @@ en:
|
||||
voucher_not_found: Not found
|
||||
add_voucher_error: There was an error while adding the voucher
|
||||
create_voucher_error: "There was an error while creating the voucher: %{error}"
|
||||
voucher_redeeming_error: There was an error while trying to redeem your voucher
|
||||
voucher_redeeming_error: There was an error while trying to redeem your voucher
|
||||
shops:
|
||||
hubs:
|
||||
show_closed_shops: "Show closed shops"
|
||||
@@ -2219,7 +2219,7 @@ en:
|
||||
invoice_column_price_per_unit_without_taxes: "Price Per unit (Excl. tax)"
|
||||
invoice_column_tax_rate: "Tax rate"
|
||||
invoice_tax_total: "GST Total:"
|
||||
invoice_cancel_and_replace_invoice: "cancels and replaces invoice"
|
||||
invoice_cancel_and_replace_invoice: "cancels and replaces invoice"
|
||||
tax_invoice: "TAX INVOICE"
|
||||
tax_total: "Total tax (%{rate}):"
|
||||
invoice_shipping_category_delivery: "Delivery"
|
||||
@@ -4734,7 +4734,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
title: "Edit Product Category"
|
||||
destroy:
|
||||
delete_taxon:
|
||||
success: "Successfully deleted the product category"
|
||||
success: "Successfully deleted the product category"
|
||||
error: "Unable to delete the product category due to assigned products."
|
||||
form:
|
||||
name: Name
|
||||
@@ -4742,7 +4742,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
meta_description: Meta Description
|
||||
meta_keywords: Meta Keywords
|
||||
description: Description
|
||||
dfc_id: DFC URI
|
||||
dfc_id: DFC URI
|
||||
general_settings:
|
||||
edit:
|
||||
legal_settings: "Legal Settings"
|
||||
|
||||
24
spec/requests/admin/enterprises_controller_spec.rb
Normal file
24
spec/requests/admin/enterprises_controller_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Admin::EnterprisesController do
|
||||
let(:admin) { create(:admin_user) }
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns a successful response' do
|
||||
get edit_admin_enterprise_path(enterprise)
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "redirect to the enterprises page for non-existing enterprise" do
|
||||
get edit_admin_enterprise_path(id: 'non-existing')
|
||||
expect(response).to redirect_to(admin_enterprises_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user