wedding-planner/spec/models/group_affinity_spec.rb
Manuel Bustillo 91bbae1c63
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 59s
Add copyright notice / copyright_notice (pull_request) Successful in 2m21s
Run unit tests / unit_tests (pull_request) Successful in 3m2s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 25m17s
Add copyright notice
2025-01-13 20:38:47 +00:00

49 lines
1.4 KiB
Ruby

# Copyright (C) 2024 Manuel Bustillo
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe GroupAffinity do
subject(:affinity) { build(:group_affinity, group_a:, group_b:) }
let(:wedding) { create(:wedding) }
let(:group_a) { create(:group, wedding:) }
let(:group_b) { create(:group, wedding:) }
let(:group_c) { create(:group, wedding:) }
describe 'validations' do
it do
expect(affinity).to validate_numericality_of(:discomfort)
.is_greater_than_or_equal_to(0)
.is_less_than_or_equal_to(2)
end
end
describe '.create' do
before do
create(:group_affinity, group_a: group_a, group_b: group_b)
end
it 'disallows the creation of a group affinity with the same group on both sides' do
expect do
create(:group_affinity, group_a: group_c, group_b: group_c)
end.to raise_error(ActiveRecord::StatementInvalid)
end
it 'disallows the creation of a group affinity that already exists' do
expect do
create(:group_affinity, group_a: group_a, group_b: group_b)
end.to raise_error(ActiveRecord::StatementInvalid)
end
it 'disallows the creation of a group affinity with the same groups in reverse order' do
expect do
create(:group_affinity, group_a: group_b, group_b: group_a)
end.to raise_error(ActiveRecord::StatementInvalid)
end
end
end