From aab132576a9baedf119963119132bea67a63aeb3 Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Sat, 13 May 2023 10:06:26 +0300 Subject: [PATCH] Fix hound errors Fix hound errors --- app/controllers/concerns/administrate/punditize.rb | 5 +++-- spec/controllers/admin/orders_controller_spec.rb | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/concerns/administrate/punditize.rb b/app/controllers/concerns/administrate/punditize.rb index adcfa906b8..89b81a98f2 100644 --- a/app/controllers/concerns/administrate/punditize.rb +++ b/app/controllers/concerns/administrate/punditize.rb @@ -41,12 +41,13 @@ def policy_scope!(user, scope) begin policy_scope = policy_scope_class.new(user, pundit_model(scope)) rescue ArgumentError - raise Pundit::InvalidConstructorError, "Invalid #<#{policy_scope_class}> constructor is called" + raise(Pundit::InvalidConstructorError, + "Invalid #<#{policy_scope_class}> constructor is called") end if policy_scope.respond_to? :resolve_admin ActiveSupport::Deprecation.warn( - "The method `resolve_admin` on pundit policy scope is deprecated. " + + "Pundit policy scope `resolve_admin` method is deprecated. " + "Please use a namespaced pundit policy instead.", ) policy_scope.resolve_admin diff --git a/spec/controllers/admin/orders_controller_spec.rb b/spec/controllers/admin/orders_controller_spec.rb index e9db330090..7f0dcdcb83 100644 --- a/spec/controllers/admin/orders_controller_spec.rb +++ b/spec/controllers/admin/orders_controller_spec.rb @@ -7,9 +7,11 @@ context "with namespaced Punditize concern" do controller(Admin::OrdersController) do include Administrate::Punditize + def policy_namespaces [:own] end + def pundit_user Customer.find_by(name: "Current User") end @@ -129,7 +131,7 @@ def pundit_user expect(locals[:resources]).to contain_exactly(order1, order3) expect(ActiveSupport::Deprecation).to have_received(:warn). - with(/`resolve_admin` on pundit policy scope is deprecated/) + with(/`resolve_admin` method is deprecated/) end end @@ -144,7 +146,7 @@ def pundit_user order = create :order, customer: user expect { get :edit, params: { id: order.id } }.not_to raise_error expect(ActiveSupport::Deprecation).to have_received(:warn). - with(/`resolve_admin` on pundit policy scope is deprecated/) + with(/`resolve_admin` method is deprecated/) end it "does not allow me to see other users' records" do @@ -153,7 +155,7 @@ def pundit_user expect { get :show, params: { id: order.id } }. to raise_error(ActiveRecord::RecordNotFound) expect(ActiveSupport::Deprecation).to have_received(:warn). - with(/`resolve_admin` on pundit policy scope is deprecated/) + with(/`resolve_admin` method is deprecated/) end end @@ -174,7 +176,7 @@ def send_request(order:) expect(response).to redirect_to([:admin, order]) expect(order.reload.address_line_one).to eq("22 Acacia Avenue") expect(ActiveSupport::Deprecation).to have_received(:warn). - with(/`resolve_admin` on pundit policy scope is deprecated/) + with(/`resolve_admin` method is deprecated/) end it "does not allow me to update other users' records" do @@ -184,7 +186,7 @@ def send_request(order:) send_request(order: order) end.to raise_error(ActiveRecord::RecordNotFound) expect(ActiveSupport::Deprecation).to have_received(:warn). - with(/`resolve_admin` on pundit policy scope is deprecated/) + with(/`resolve_admin` method is deprecated/) end end