1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

improves test if there is already an admin, not failing anymore if role doesnt exist

This commit is contained in:
Nicolas Florentin 2017-07-13 09:25:32 +02:00
parent 65a56ac2f4
commit decb7e8159

View File

@ -83,7 +83,7 @@ if Group.count == 0
end end
# Create the default admin if none exists yet # Create the default admin if none exists yet
if Role.find_by(name: 'admin').users.count === 0 if Role.where(name: 'admin').joins(:users).count === 0
admin = User.new(username: 'admin', email: Rails.application.secrets.admin_email, password: Rails.application.secrets.admin_password, password_confirmation: Rails.application.secrets.admin_password, group_id: Group.first.id, profile_attributes: {first_name: 'admin', last_name: 'admin', gender: true, phone: '0123456789', birthday: Time.now}) admin = User.new(username: 'admin', email: Rails.application.secrets.admin_email, password: Rails.application.secrets.admin_password, password_confirmation: Rails.application.secrets.admin_password, group_id: Group.first.id, profile_attributes: {first_name: 'admin', last_name: 'admin', gender: true, phone: '0123456789', birthday: Time.now})
admin.add_role 'admin' admin.add_role 'admin'
admin.save! admin.save!