2024-12-28 16:31:27 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-12-28 17:27:28 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-07-11 20:08:26 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-12-28 17:27:28 +01:00
|
|
|
RSpec.describe Guest do
|
2024-11-16 02:16:19 +01:00
|
|
|
describe 'validations' do
|
2024-12-28 17:27:28 +01:00
|
|
|
subject(:guest) { build(:guest) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
|
|
|
|
2024-11-16 02:16:19 +01:00
|
|
|
it do
|
2024-12-28 17:27:28 +01:00
|
|
|
expect(guest).to define_enum_for(:status).with_values(
|
2024-11-16 02:16:19 +01:00
|
|
|
considered: 0,
|
|
|
|
invited: 10,
|
|
|
|
confirmed: 20,
|
|
|
|
declined: 30,
|
|
|
|
tentative: 40
|
|
|
|
)
|
|
|
|
end
|
2024-11-09 17:45:23 +01:00
|
|
|
end
|
|
|
|
|
2024-12-28 17:27:28 +01:00
|
|
|
it { is_expected.to belong_to(:group).optional }
|
2024-11-09 17:45:23 +01:00
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
describe '.potential' do
|
|
|
|
it 'returns guests that are not declined or considered' do
|
|
|
|
_declined_guest = create(:guest, status: :declined)
|
|
|
|
_considered_guest = create(:guest, status: :considered)
|
|
|
|
invited_guest = create(:guest, status: :invited)
|
|
|
|
confirmed_guest = create(:guest, status: :confirmed)
|
|
|
|
tentative_guest = create(:guest, status: :tentative)
|
|
|
|
|
2024-12-28 17:27:28 +01:00
|
|
|
expect(described_class.potential).to contain_exactly(invited_guest, confirmed_guest, tentative_guest)
|
2024-11-09 17:45:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-07-11 20:08:26 +02:00
|
|
|
end
|