2018-07-13 11:52:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe UserStatus do
|
2018-07-13 11:52:31 -04:00
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value('smirk').for(:emoji) }
|
|
|
|
it { is_expected.not_to allow_value('hello world').for(:emoji) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:emoji) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_length_of(:message).is_at_most(100) }
|
|
|
|
it { is_expected.to allow_value('').for(:message) }
|
|
|
|
|
|
|
|
it 'is expected to be deleted when the user is deleted' do
|
|
|
|
status = create(:user_status)
|
|
|
|
|
2021-05-02 20:10:40 -04:00
|
|
|
expect { status.user.destroy! }.to change { described_class.count }.from(1).to(0)
|
2018-07-13 11:52:31 -04:00
|
|
|
end
|
2021-02-12 13:08:59 -05:00
|
|
|
|
2022-09-12 17:10:38 -04:00
|
|
|
describe '#clear_status_after' do
|
|
|
|
it 'is an alias of #clear_status_at', :freeze_time do
|
|
|
|
status = build(:user_status, clear_status_at: 8.hours.from_now)
|
|
|
|
|
|
|
|
expect(status.clear_status_after).to be_like_time(8.hours.from_now)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-12 13:08:59 -05:00
|
|
|
describe '#clear_status_after=' do
|
|
|
|
it 'sets clear_status_at' do
|
|
|
|
status = build(:user_status)
|
|
|
|
|
|
|
|
freeze_time do
|
|
|
|
status.clear_status_after = '8_hours'
|
|
|
|
|
|
|
|
expect(status.clear_status_at).to be_like_time(8.hours.from_now)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsets clear_status_at' do
|
|
|
|
status = build(:user_status, clear_status_at: 8.hours.from_now)
|
|
|
|
|
|
|
|
status.clear_status_after = nil
|
|
|
|
|
|
|
|
expect(status.clear_status_at).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unknown clear status is given' do
|
|
|
|
it 'unsets clear_status_at' do
|
|
|
|
status = build(:user_status, clear_status_at: 8.hours.from_now)
|
|
|
|
|
|
|
|
status.clear_status_after = 'unknown'
|
|
|
|
|
|
|
|
expect(status.clear_status_at).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-07-26 05:09:02 -04:00
|
|
|
|
|
|
|
describe '#customized?' do
|
|
|
|
it 'is customized when message text is present' do
|
|
|
|
subject.message = 'My custom status'
|
|
|
|
|
|
|
|
expect(subject).to be_customized
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not customized when message text is absent' do
|
|
|
|
subject.message = nil
|
|
|
|
|
|
|
|
expect(subject).not_to be_customized
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is customized without message but with custom emoji' do
|
|
|
|
subject.emoji = 'bow'
|
|
|
|
|
|
|
|
expect(subject).to be_customized
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not customized without message but with default custom emoji' do
|
|
|
|
subject.emoji = 'speech_balloon'
|
|
|
|
|
|
|
|
expect(subject).not_to be_customized
|
|
|
|
end
|
|
|
|
end
|
2018-07-13 11:52:31 -04:00
|
|
|
end
|