Update method name to require

This commit updates the method name to be called required_enterprise
since we only expect it to raise an error when the enterprise is not found.
This commit is contained in:
Tresor11
2025-03-31 22:13:45 +03:00
parent 5b3bae85ca
commit 507705a4eb
3 changed files with 25 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ module Admin
prepend_before_action :override_sells, only: :create
before_action :load_countries, except: [:index, :register, :check_permalink]
before_action :set_enterprise, only: [:edit, :update]
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]
@@ -217,12 +217,8 @@ module Admin
[:index, :for_order_cycle, :visible, :bulk_update]
end
def set_enterprise
@enterprise = @object
return if @enterprise
flash[:error] = I18n.t(:enterprise_not_found_error)
redirect_to admin_enterprises_path
def require_enterprise
raise ActiveRecord::RecordNotFound if @enterprise.blank?
end
def load_methods_and_fees

View File

@@ -3440,7 +3440,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
enterprise_register_package_error: "Please select a package"
enterprise_register_error: "Could not complete registration for %{enterprise}"
enterprise_register_success_notice: "Congratulations! Registration for %{enterprise} is complete!"
enterprise_not_found_error: "Enterprise not found"
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."

View File

@@ -0,0 +1,22 @@
require 'spec_helper'
RSpec.describe Admin::EnterprisesController, type: :request 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