From 3d00b70087a93c4c1992a3612e8f3b2055fba184 Mon Sep 17 00:00:00 2001 From: Godwin Date: Thu, 12 Jan 2017 18:42:44 -0800 Subject: [PATCH] Fixed registration status --- app/models/conference_registration.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/conference_registration.rb b/app/models/conference_registration.rb index d7f7b2c..8fbdb1c 100644 --- a/app/models/conference_registration.rb +++ b/app/models/conference_registration.rb @@ -34,10 +34,16 @@ class ConferenceRegistration < ActiveRecord::Base end def status(was = false) - return :unregistered if user.nil? - steps = ((was ? steps_completed_was : steps_completed) || []).map(&:to_sym) - return :registered if steps.include?(:hosting) || steps.include?(:questions) - return :preregistered if steps.include?(:contact_info) + # our user hasn't registered if their user doesn't exist or they haven't entered a city + return :unregistered if user.nil? || check(:city, was).blank? + + # registration completes once a guest has entered a housing preference or + # a housing provider has opted in or out of providing housing + return :preregistered unless + check(:housing, was).present? || !check(:can_provide_housing, was).nil? + + # they must be registered + return :registered end around_update :check_status @@ -60,4 +66,9 @@ class ConferenceRegistration < ActiveRecord::Base end end end + +private + def check(field, was) + send("#{field}#{was ? '_was' : ''}") + end end