diff --git a/api/app/models/new_club_application.rb b/api/app/models/new_club_application.rb index a14450f7c..588d4fca6 100644 --- a/api/app/models/new_club_application.rb +++ b/api/app/models/new_club_application.rb @@ -77,6 +77,11 @@ class NewClubApplication < ApplicationRecord } def submit! + if submitted? + errors.add(:base, 'already submitted') + return false + end + self.submitted_at = Time.current if valid? diff --git a/api/spec/models/new_club_application_spec.rb b/api/spec/models/new_club_application_spec.rb index 621598873..df06b1772 100644 --- a/api/spec/models/new_club_application_spec.rb +++ b/api/spec/models/new_club_application_spec.rb @@ -215,6 +215,15 @@ ) end + it 'fails if already submitted' do + # submit twice + subject.submit! + res = subject.submit! + + expect(res).to eq(false) + expect(subject.errors[:base]).to include 'already submitted' + end + it 'succeeds when required fields are set & leader profiles complete' do res = subject.submit! diff --git a/api/spec/requests/v1/new_club_applications_spec.rb b/api/spec/requests/v1/new_club_applications_spec.rb index 9ec78769d..cca74d18d 100644 --- a/api/spec/requests/v1/new_club_applications_spec.rb +++ b/api/spec/requests/v1/new_club_applications_spec.rb @@ -758,6 +758,17 @@ ).to include('leader profiles not complete') end + it 'fails if already submitted' do + post "/v1/new_club_applications/#{application.id}/submit", + headers: auth_headers + expect(response.status).to eq(200) + + post "/v1/new_club_applications/#{application.id}/submit", + headers: auth_headers + expect(response.status).to eq(422) + expect(json['errors']['base']).to include('already submitted') + end + it 'submits successfully when all fields are present' do post "/v1/new_club_applications/#{application.id}/submit", headers: auth_headers