2019-01-25 21:53:06 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe SystemNotification do
|
2019-05-08 20:22:52 +08:00
|
|
|
let(:system_notification) { build :system_notification }
|
2019-01-25 21:53:06 +08:00
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(system_notification).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Validations' do
|
|
|
|
describe '#title' do
|
|
|
|
it { is_expected.to validate_presence_of(:title) }
|
2019-02-20 23:05:15 +08:00
|
|
|
it { is_expected.to validate_length_of(:title).is_at_most(255) }
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#modal_title' do
|
|
|
|
it { is_expected.to validate_presence_of(:modal_title) }
|
2019-02-20 23:05:15 +08:00
|
|
|
it { is_expected.to validate_length_of(:modal_title).is_at_most(255) }
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#modal_body' do
|
|
|
|
it { is_expected.to validate_presence_of(:modal_body) }
|
2020-07-20 17:52:33 +08:00
|
|
|
it { is_expected.to validate_length_of(:modal_body).is_at_most(100000) }
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#description' do
|
|
|
|
it { is_expected.to validate_presence_of(:description) }
|
2019-02-20 23:05:15 +08:00
|
|
|
it { is_expected.to validate_length_of(:description).is_at_most(255) }
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#source_id' do
|
|
|
|
it { is_expected.to validate_presence_of(:source_id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#source_created_at' do
|
|
|
|
it { is_expected.to validate_presence_of(:source_created_at) }
|
|
|
|
end
|
2019-01-31 15:53:02 +08:00
|
|
|
|
|
|
|
describe '#last_time_changed_at' do
|
|
|
|
it { is_expected.to validate_presence_of(:last_time_changed_at) }
|
|
|
|
end
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Associations' do
|
|
|
|
it { is_expected.to have_many(:users) }
|
|
|
|
end
|
2019-02-04 21:33:22 +08:00
|
|
|
|
|
|
|
describe 'self.last_sync_timestamp' do
|
|
|
|
context 'when there is no users or system notifications in db' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(described_class.last_sync_timestamp).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no system notifications in db' do
|
2019-04-25 15:18:26 +08:00
|
|
|
it 'returns first users created_at' do
|
2019-02-04 21:33:22 +08:00
|
|
|
create :user
|
2019-04-25 15:18:26 +08:00
|
|
|
create :user, created_at: Time.now + 5.seconds
|
2019-02-04 21:33:22 +08:00
|
|
|
|
|
|
|
expect(described_class.last_sync_timestamp)
|
2019-04-25 15:18:26 +08:00
|
|
|
.to be == User.first.created_at.to_i
|
2019-02-04 21:33:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when have some system notifications' do
|
|
|
|
it 'returns last system notifications last_time_changed_at timestamp' do
|
|
|
|
create :user
|
|
|
|
create :system_notification
|
|
|
|
|
|
|
|
expect(described_class.last_sync_timestamp)
|
|
|
|
.to be SystemNotification.last.last_time_changed_at.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-01-25 21:53:06 +08:00
|
|
|
end
|