refactoring setup_roles and updated tests

This commit is contained in:
Chrisbr 2014-05-13 10:35:23 +02:00
parent 86c188a38a
commit 84843ade48
5 changed files with 27 additions and 14 deletions

View file

@ -29,15 +29,8 @@ class User < ActiveRecord::Base
end
def setup_role
if User.count == 0
admin = Role.where(name: 'Admin').first
self.role_ids = [admin.id] unless admin.nil?
end
if self.role_ids.empty?
participant = Role.where(name: 'Participant').first
self.role_ids = [participant.id] unless participant.nil?
end
self.roles << Role.find_by(name: 'Admin') if User.count == 0
self.roles << Role.find_by(name: 'Participant') if self.roles.empty?
end
def popup_details
@ -56,9 +49,9 @@ class User < ActiveRecord::Base
end
private
def create_person
# TODO Search people for existing email address, add to their account
build_person(:email => self.email) if person.nil?
true
end
def create_person
# TODO Search people for existing email address, add to their account
build_person(:email => self.email) if person.nil?
true
end
end