Use delegate in web/push_subscription model for token value (#38313)

This commit is contained in:
Matt Jankowski
2026-03-20 11:48:28 -04:00
committed by GitHub
parent 7aa696149f
commit 24d3c94f4a
2 changed files with 5 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ class Web::PushSubscription < ApplicationRecord
validates_with WebPushKeyValidator
delegate :locale, to: :user
delegate :token, to: :access_token, prefix: :associated_access
generates_token_for :unsubscribe, expires_in: Web::PushNotificationWorker::TTL
@@ -36,10 +37,6 @@ class Web::PushSubscription < ApplicationRecord
policy_allows_notification?(notification) && alert_enabled_for_notification_type?(notification)
end
def associated_access_token
access_token.token
end
class << self
def unsubscribe_for(application_id, resource_owner)
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id).not_revoked.pluck(:id)

View File

@@ -93,4 +93,8 @@ RSpec.describe Web::PushSubscription do
end
end
end
describe 'Delegations' do
it { is_expected.to delegate_method(:token).to(:access_token).with_prefix(:associated_access) }
end
end