Skip to content

Commit

Permalink
Withdrawing or Declining your seat in the Teachercon registration wil…
Browse files Browse the repository at this point in the history
…l also update your application
  • Loading branch information
Hamms committed Jan 15, 2018
1 parent d70a67a commit e52d52c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dashboard/app/models/pd/teachercon1819_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ class Pd::Teachercon1819Registration < ActiveRecord::Base
YES_OR_NO = [YES, NO].freeze
OTHER = 'Other'.freeze

after_create :update_application_status
def update_application_status
status = sanitize_form_data_hash.try(:[], :teacher_accept_seat)
return unless status

if status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:withdraw_date] ||
status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:withdraw_other]
pd_application.update!(status: "waitlisted")
elsif status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:decline]
pd_application.update!(status: "declined")
end
end

def self.options
{
dietaryNeeds: [
Expand Down
22 changes: 22 additions & 0 deletions dashboard/test/models/pd/teachercon1819_registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,26 @@ class Pd::Teachercon1819RegistrationTest < ActiveSupport::TestCase
refute registration.sanitize_form_data_hash.key?(:contact_first_name)
refute registration.sanitize_form_data_hash.key?(:dietary_needs)
end

test 'withdrawing or declining in the registration will also update the application' do
{
Pd::Teachercon1819Registration::TEACHER_SEAT_ACCEPTANCE_OPTIONS[:accept] => "accepted",
Pd::Teachercon1819Registration::TEACHER_SEAT_ACCEPTANCE_OPTIONS[:withdraw_date] => "waitlisted",
Pd::Teachercon1819Registration::TEACHER_SEAT_ACCEPTANCE_OPTIONS[:withdraw_other] => "waitlisted",
Pd::Teachercon1819Registration::TEACHER_SEAT_ACCEPTANCE_OPTIONS[:decline] => "declined"
}.each do |accept_seat, status|
application = create(:pd_teacher1819_application)
application.status = "accepted"
application.lock!

Pd::Teachercon1819Registration.create(
pd_application: application,
form_data: build(:pd_teachercon1819_registration_hash).merge(
teacher_accept_seat: accept_seat
).to_json
)

assert_equal application.reload.status, status
end
end
end

0 comments on commit e52d52c

Please sign in to comment.