diff --git a/app/models/contact.rb b/app/models/contact.rb index da8a3f651..520d55982 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -40,6 +40,14 @@ class Contact < ActiveRecord::Base before_create :generate_code before_create :generate_auth_info after_create :ensure_disclosure + after_save :manage_automatic_statuses + def manage_automatic_statuses + if statuses.empty? && valid? + statuses.create(value: ContactStatus::OK) + elsif statuses.length > 1 || !valid? + statuses.find_by(value: ContactStatus::OK).try(:destroy) + end + end scope :current_registrars, ->(id) { where(registrar_id: id) } diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index dbf7bc3dc..5c45c56a0 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -147,6 +147,11 @@ describe Contact do @contact.auth_info.should == 'password' end + it 'should have ok status by default' do + @contact.statuses.size.should == 1 + @contact.statuses.first.value.should == 'ok' + end + context 'as birthday' do before :all do @contact.ident_type = 'birthday'