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).
This commit is contained in:
evazion
2020-06-10 18:16:58 -05:00
parent 8a2ae91ff2
commit 45b3370d49
2 changed files with 7 additions and 1 deletions

View File

@@ -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

View File

@@ -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")