Persist and expose via API the progress of the tables arrangement simulations #316

Merged
bustikiller merged 8 commits from arrangements-status into main 2025-09-16 00:39:40 +00:00
4 changed files with 23 additions and 21 deletions
Showing only changes of commit 78ab27a697 - Show all commits

View File

@ -6,24 +6,24 @@ require 'rails_helper'
module Tables module Tables
RSpec.describe Distribution do RSpec.describe Distribution do
describe '#save!' do let(:tables_arrangement) { TablesArrangement.create! }
around do |example|
ActsAsTenant.with_tenant(create(:wedding)) do
example.run
end
end
around do |example|
ActsAsTenant.with_tenant(create(:wedding)) do
example.run
end
end
describe '#save!' do
let(:people) { create_list(:guest, 2, status: :invited) } let(:people) { create_list(:guest, 2, status: :invited) }
let(:distribution) do let(:distribution) do
described_class.new(min_per_table: 5, max_per_table: 10).tap{|d| d.random_distribution(people)} described_class.new(min_per_table: 5, max_per_table: 10, tables_arrangement_id: tables_arrangement.id)
.tap { |d| d.random_distribution(people) }
end end
context 'when tables_arrangement_id is nil' do context 'when tables_arrangement_id is nil' do
it { expect { distribution.save! }.to change(TablesArrangement, :count).by(1) }
it { expect { distribution.save! }.to change(Seat, :count).by(2) }
it { expect { distribution.save! }.to change { TablesArrangement.count }.by(1) }
it { expect { distribution.save! }.to change { Seat.count }.by(2) }
end end
context 'when tables_arrangement_id is set' do context 'when tables_arrangement_id is set' do
@ -34,13 +34,15 @@ module Tables
distribution.tables_arrangement_id = existing_arrangement.id distribution.tables_arrangement_id = existing_arrangement.id
end end
it { expect { distribution.save! }.not_to change { TablesArrangement.count } } it { expect { distribution.save! }.not_to(change(TablesArrangement, :count)) }
it { expect { distribution.save! }.to change { Seat.count }.by(1) } it { expect { distribution.save! }.to change(Seat, :count).by(1) }
end end
end end
describe '#random_distribution' do describe '#random_distribution' do
subject(:distribution) { described_class.new(min_per_table: 5, max_per_table: 10) } subject(:distribution) do
described_class.new(min_per_table: 5, max_per_table: 10, tables_arrangement_id: tables_arrangement.id)
end
context 'when there are fewer people than the minimum per table' do context 'when there are fewer people than the minimum per table' do
it 'creates one table' do it 'creates one table' do

View File

@ -17,7 +17,7 @@ module Tables
context 'when there are two tables with two people each' do context 'when there are two tables with two people each' do
let(:initial_solution) do let(:initial_solution) do
Distribution.new(min_per_table: 2, max_per_table: 2).tap do |distribution| Distribution.new(min_per_table: 2, max_per_table: 2, tables_arrangement_id: nil).tap do |distribution|
distribution.tables << Set[:a, :b].to_table distribution.tables << Set[:a, :b].to_table
distribution.tables << Set[:c, :d].to_table distribution.tables << Set[:c, :d].to_table
end end
@ -35,7 +35,7 @@ module Tables
context 'when there are two tables with three people each' do context 'when there are two tables with three people each' do
let(:initial_solution) do let(:initial_solution) do
Distribution.new(min_per_table: 3, max_per_table: 3).tap do |distribution| Distribution.new(min_per_table: 3, max_per_table: 3, tables_arrangement_id: nil).tap do |distribution|
distribution.tables << Set[:a, :b, :c].to_table distribution.tables << Set[:a, :b, :c].to_table
distribution.tables << Set[:d, :e, :f].to_table distribution.tables << Set[:d, :e, :f].to_table
end end

View File

@ -17,7 +17,7 @@ module Tables
context 'when there are two tables with two people each' do context 'when there are two tables with two people each' do
let(:initial_solution) do let(:initial_solution) do
Distribution.new(min_per_table: 2, max_per_table: 2).tap do |distribution| Distribution.new(min_per_table: 2, max_per_table: 2, tables_arrangement_id: nil).tap do |distribution|
distribution.tables << Set[:a, :b].to_table distribution.tables << Set[:a, :b].to_table
distribution.tables << Set[:c, :d].to_table distribution.tables << Set[:c, :d].to_table
end end
@ -35,7 +35,7 @@ module Tables
context 'when there are two tables with three people each' do context 'when there are two tables with three people each' do
let(:initial_solution) do let(:initial_solution) do
Distribution.new(min_per_table: 3, max_per_table: 3).tap do |distribution| Distribution.new(min_per_table: 3, max_per_table: 3, tables_arrangement_id: nil).tap do |distribution|
distribution.tables << Set[:a, :b, :c].to_table distribution.tables << Set[:a, :b, :c].to_table
distribution.tables << Set[:d, :e, :f].to_table distribution.tables << Set[:d, :e, :f].to_table
end end
@ -58,7 +58,7 @@ module Tables
context 'when there are three tables with two people each' do context 'when there are three tables with two people each' do
let(:initial_solution) do let(:initial_solution) do
Distribution.new(min_per_table: 2, max_per_table: 2).tap do |distribution| Distribution.new(min_per_table: 2, max_per_table: 2, tables_arrangement_id: nil).tap do |distribution|
distribution.tables << Set[:a, :b].to_table distribution.tables << Set[:a, :b].to_table
distribution.tables << Set[:c, :d].to_table distribution.tables << Set[:c, :d].to_table
distribution.tables << Set[:e, :f].to_table distribution.tables << Set[:e, :f].to_table

View File

@ -8,7 +8,7 @@ module Tables
RSpec.describe WheelSwap do RSpec.describe WheelSwap do
context 'when the solution has three tables' do context 'when the solution has three tables' do
let(:initial_solution) do let(:initial_solution) do
Distribution.new(min_per_table: 3, max_per_table: 3).tap do |distribution| Distribution.new(min_per_table: 3, max_per_table: 3, tables_arrangement_id: nil).tap do |distribution|
distribution.tables << Set[:a, :b, :c].to_table distribution.tables << Set[:a, :b, :c].to_table
distribution.tables << Set[:d, :e, :f].to_table distribution.tables << Set[:d, :e, :f].to_table
distribution.tables << Set[:g, :h, :i].to_table distribution.tables << Set[:g, :h, :i].to_table