All checks were successful
		
		
	
	Check usage of free licenses / check-licenses (pull_request) Successful in 1m38s
				
			Add copyright notice / copyright_notice (pull_request) Successful in 3m16s
				
			Run unit tests / unit_tests (pull_request) Successful in 5m31s
				
			Build Nginx-based docker image / build-static-assets (pull_request) Successful in 41m31s
				
			
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # 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
 |