chore: rubocop

chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
This commit is contained in:
Philipp Rothmann 2023-05-12 13:01:12 +02:00 committed by Philipp Rothmann
parent f6fb804bbe
commit fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions

View file

@ -3,26 +3,26 @@ class Workgroup < Group
has_many :tasks
# returns all non-finished tasks
has_many :open_tasks, -> { where(:done => false).order('due_date', 'name') }, :class_name => 'Task'
has_many :open_tasks, -> { where(done: false).order('due_date', 'name') }, class_name: 'Task'
validates_uniqueness_of :name
validate :last_admin_on_earth, :on => :update
validates :name, uniqueness: true
validate :last_admin_on_earth, on: :update
before_destroy :check_last_admin_group
protected
# Check before destroy a group, if this is the last group with admin role
def check_last_admin_group
if role_admin && Workgroup.where(role_admin: true).size == 1
raise I18n.t('workgroups.error_last_admin_group')
end
return unless role_admin && Workgroup.where(role_admin: true).size == 1
raise I18n.t('workgroups.error_last_admin_group')
end
# add validation check on update
# Return an error if this is the last group with admin role and role_admin should set to false
def last_admin_on_earth
if !role_admin && !Workgroup.where(role_admin: true).where.not(id: id).exists?
errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role'))
end
return unless !role_admin && !Workgroup.where(role_admin: true).where.not(id: id).exists?
errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role'))
end
end