Skip to content

Commit

Permalink
Don't allow new applications to be submitted twice. Closes hackclub#347
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta committed Feb 8, 2018
1 parent 0d7b38e commit 9588dbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/app/models/new_club_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 9 additions & 0 deletions api/spec/models/new_club_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
11 changes: 11 additions & 0 deletions api/spec/requests/v1/new_club_applications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9588dbb

Please sign in to comment.