Add PushNotification#to

This commit is contained in:
Enrico Stano
2018-06-04 16:54:05 +02:00
parent 867fa00b2d
commit ea3858121d
2 changed files with 13 additions and 0 deletions

View File

@ -3,4 +3,8 @@ class PushNotification < ActiveRecord::Base
belongs_to :device_token, foreign_key: 'device_token_id'
validates :event, :device_token, presence: true
def to
device_token.token
end
end

View File

@ -13,4 +13,13 @@ RSpec.describe PushNotification do
it { is_expected.to have_db_column(:event_id) }
it { is_expected.to have_db_column(:device_token_id) }
end
describe "#to" do
let(:device_token) { Fabricate.build(:device_token, token: 'token') }
let(:push_notification) { described_class.new(device_token: device_token) }
it 'returns the associated DeviceToken\'s token' do
expect(push_notification.to).to eq('token')
end
end
end