Contact status ok by default

This commit is contained in:
Priit Tark 2015-03-10 18:08:41 +02:00
parent b2488c7ebe
commit 5341a42a43
2 changed files with 13 additions and 0 deletions

View file

@ -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) }

View file

@ -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'