From 45b3370d49c9e8427ca6e94ac9cf660505122fbb Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 10 Jun 2020 18:16:58 -0500 Subject: [PATCH] models: fix exception in `api_attributes`. Fixup bug in eacb4d4df when calling `api_attributes` on an object that doesn't have a policy (its policy inherited from ApplicationPolicy). --- app/models/application_record.rb | 3 ++- test/functional/artist_urls_controller_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 24ec27a76..ee9fa44a0 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -54,7 +54,8 @@ class ApplicationRecord < ActiveRecord::Base # XXX deprecated, shouldn't expose this as an instance method. def api_attributes(user: CurrentUser.user) - Pundit.policy!([user, nil], self).api_attributes + policy = Pundit.policy([user, nil], self) || ApplicationPolicy.new([user, nil], self) + policy.api_attributes end def html_data_attributes diff --git a/test/functional/artist_urls_controller_test.rb b/test/functional/artist_urls_controller_test.rb index dc009fb79..8a0f15707 100644 --- a/test/functional/artist_urls_controller_test.rb +++ b/test/functional/artist_urls_controller_test.rb @@ -8,6 +8,11 @@ class ArtistUrlsControllerTest < ActionDispatch::IntegrationTest assert_response :success end + should "render for a json request" do + get artist_urls_path, as: :json + assert_response :success + end + should "render for a complex search" do @artist = FactoryBot.create(:artist, name: "bkub", url_string: "-http://bkub.com")