diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb index 25140598a5..b13c5c97d4 100644 --- a/app/models/web/push_subscription.rb +++ b/app/models/web/push_subscription.rb @@ -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) diff --git a/spec/models/web/push_subscription_spec.rb b/spec/models/web/push_subscription_spec.rb index 3c2cd3bac1..b1e93687b3 100644 --- a/spec/models/web/push_subscription_spec.rb +++ b/spec/models/web/push_subscription_spec.rb @@ -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