From fec6e5460248515bbb9ae038a25ec6c01714d120 Mon Sep 17 00:00:00 2001 From: Duncan <52967253+dunkOnIT@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:46:23 +0200 Subject: [PATCH] default competitor limit to 0 if null (#724) --- app/services/registration_checker.rb | 2 +- spec/services/registration_checker_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/services/registration_checker.rb b/app/services/registration_checker.rb index 09f4d084..a0a50566 100644 --- a/app/services/registration_checker.rb +++ b/app/services/registration_checker.rb @@ -173,7 +173,7 @@ def validate_update_status! raise RegistrationError.new(:unprocessable_entity, ErrorCodes::INVALID_REQUEST_DATA) unless Registration::REGISTRATION_STATES.include?(new_status) - competitor_limit = @competition_info.competitor_limit + competitor_limit = @competition_info.competitor_limit || 0 raise RegistrationError.new(:forbidden, ErrorCodes::COMPETITOR_LIMIT_REACHED) if new_status == 'accepted' && competitor_limit > 0 && Registration.accepted_competitors_count(@competition_info.competition_id) >= competitor_limit diff --git a/spec/services/registration_checker_spec.rb b/spec/services/registration_checker_spec.rb index 518fee1a..7c7f98ce 100644 --- a/spec/services/registration_checker_spec.rb +++ b/spec/services/registration_checker_spec.rb @@ -1127,6 +1127,15 @@ .not_to raise_error end + it 'organizer can accept registrations limit is nil' do + registration = FactoryBot.create(:registration, registration_status: 'pending') + competition_info = CompetitionInfo.new(FactoryBot.build(:competition, competitor_limit: nil)) + update_request = FactoryBot.build(:update_request, :organizer_for_user, user_id: registration[:user_id], competing: { 'status' => 'accepted' }) + + expect { RegistrationChecker.update_registration_allowed!(update_request, competition_info, update_request['submitted_by']) } + .not_to raise_error + end + it 'user can change state to cancelled' do override_registration = FactoryBot.create(:registration, user_id: 188000, registration_status: 'waiting_list') update_request = FactoryBot.build(:update_request, user_id: override_registration[:user_id], competing: { 'status' => 'cancelled' })