Skip to content

Commit

Permalink
Prefix outdated roles with triangle
Browse files Browse the repository at this point in the history
refs #2255
  • Loading branch information
amaierhofer committed Nov 15, 2023
1 parent 0224934 commit 27a570f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/decorators/role_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class RoleDecorator < ApplicationDecorator
decorates :role

def for_aside
content_tag(:strong, model.to_s)
text = content_tag(:strong, model.to_s)

if model.outdated?
helpers.icon(:exclamation_triangle) + FormatHelper::EMPTY_STRING + text
else
content_tag(:strong, model.to_s)
end
end
end
4 changes: 1 addition & 3 deletions app/jobs/people/create_roles_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def future_roles
def convert(role)
role.convert!
rescue => e
message = "#{e.message} - FutureRole(#{role.id})"
role.update!(label: message)
notify(message)
notify("#{e.message} - FutureRole(#{role.id})")
end

def notify(message)
Expand Down
6 changes: 6 additions & 0 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def attr_used?(attr)
def to_s(format = :default)
model_name = self.class.label
string = label? ? "#{model_name} (#{label})" : model_name
string += " (#{formatted_delete_date})" if delete_on
if format == :long
I18n.t('activerecord.attributes.role.string_long', role: string, group: group.to_s)
else
Expand Down Expand Up @@ -268,4 +269,9 @@ def prevent_changes

raise ActiveRecord::ReadOnlyRecord unless new_record? || only_archival
end

def formatted_delete_date
[I18n.t('global.until'), I18n.l(delete_on)].join(' ')
end

end
28 changes: 28 additions & 0 deletions spec/decorators/role_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
#
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito

require 'spec_helper'

describe RoleDecorator, :draper_with_helpers do
let(:role) { roles(:top_leader) }

let(:decorator) { described_class.new(role) }

describe '#for_aside' do
subject(:node) { Capybara::Node::Simple.new(decorator.for_aside) }

it 'wraps role#to_s in strong tag' do
expect(node).to have_css('strong', text: role.to_s)
end

it 'prepends exclamatione mark if role is outdated' do
role.delete_on = Time.zone.yesterday
expect(node).to have_css('i.fa.fa-exclamation-triangle')
expect(node).to have_css('strong', text: role.to_s)
end
end
end
25 changes: 25 additions & 0 deletions spec/models/role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,31 @@ def build(attrs)
end
end

context '#to_s' do
let(:group) { groups(:bottom_layer_one) }
let(:date) { Date.new(2023, 11, 15) }

def build_role(attrs = {})
Fabricate.build(Group::BottomLayer::Leader.sti_name, attrs.merge(group: group))
end

it 'includes group specific role type' do
expect(build_role.to_s).to eq 'Leader'
end

it 'appends label if set' do
expect(build_role(label: 'test').to_s).to eq 'Leader (test)'
end

it 'appends delete_on if set' do
expect(build_role(delete_on: date).to_s).to eq 'Leader (Bis 15.11.2023)'
end

it 'combines label and delete_on if both are set' do
expect(build_role(label: 'test', delete_on: date).to_s).to eq 'Leader (test) (Bis 15.11.2023)'
end
end

context '#outdated?' do
let(:group) { groups(:bottom_layer_one) }

Expand Down

0 comments on commit 27a570f

Please sign in to comment.