wedding-planner/spec/models/group_affinity_spec.rb

47 lines
1.4 KiB
Ruby
Raw Normal View History

2024-12-26 19:30:32 +00:00
# Copyright (C) 2024 Manuel Bustillo
# frozen_string_literal: true
require 'rails_helper'
2024-12-28 17:27:28 +01:00
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
2024-12-28 17:27:28 +01:00
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