diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index 9aa5e0d00cc..6dea361fe24 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -57,7 +57,7 @@ def target_users if @target == 'followings' current_user.followees_list(watch: @watch) elsif @tag - User.tagged_with(@tag) + User.tagged_with(@tag).unhibernated.unretired else users_scope = if @company diff --git a/app/models/user.rb b/app/models/user.rb index 7e78569a68f..9aeb1475626 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -357,6 +357,7 @@ class User < ApplicationRecord scope :desc_tagged_with, lambda { |tag_name| with_attached_avatar .unretired + .unhibernated .order(last_activity_at: :desc) .tagged_with(tag_name) } @@ -409,7 +410,7 @@ def users_role(target, allowed_targets: [], default_target: :none) end def tags - unretired.all_tag_counts(order: 'count desc, name asc') + unretired.unhibernated.all_tag_counts(order: 'count desc, name asc') end def depressed_reports diff --git a/app/views/tags/_tag.html.slim b/app/views/tags/_tag.html.slim index e0ddd8e89d1..45bab5437f8 100644 --- a/app/views/tags/_tag.html.slim +++ b/app/views/tags/_tag.html.slim @@ -4,7 +4,7 @@ = link_to users_tag_path(tag.name), class: 'user-group__title-link' - rank = users_tags_rank(tag.count, @top3_tags_counts) - if rank.present? - span.user-group__title-icon(class="#{users_tags_rank(tag.count, @top3_tags_counts)}") + span.user-group__title-icon(class="#{rank}") i.fa-solid.fa-crown span.user-group__title-label | #{tag.name} @@ -12,4 +12,6 @@ | (#{tag.count}) .a-user-icons .a-user-icons__items - = render partial: 'tags/user', collection: User.desc_tagged_with(tag.name), as: :user + = render partial: 'tags/user', + collection: User.desc_tagged_with(tag.name), + as: :user diff --git a/test/fixtures/acts_as_taggable_on/taggings.yml b/test/fixtures/acts_as_taggable_on/taggings.yml index c82b0a8212b..73d9337c806 100644 --- a/test/fixtures/acts_as_taggable_on/taggings.yml +++ b/test/fixtures/acts_as_taggable_on/taggings.yml @@ -23,6 +23,11 @@ machida_tag_guitar: context: tags tag: guitar +kensyu_tag_guitar: + taggable: kensyu (User) + context: tags + tag: guitar + kimura_tag_cat: taggable: kimura (User) context: tags diff --git a/test/system/user/tags_test.rb b/test/system/user/tags_test.rb index c18f837e4bd..e563d3be29b 100644 --- a/test/system/user/tags_test.rb +++ b/test/system/user/tags_test.rb @@ -149,4 +149,73 @@ class User::TagsTest < ApplicationSystemTestCase assert_includes all('.tag-links__item-link').map(&:text), 'ハッシュハッシュ' end + + test 'hibernated users are not displayed in the user list by tag' do + user = users(:kensyu) + tag_name = acts_as_taggable_on_tags('guitar').name.to_s + + User.tags.where.not(name: tag_name).destroy_all + + visit_with_auth users_tag_path(tag_name), 'kensyu' + assert_text "タグ「#{tag_name}」のユーザー(2)" + assert_selector ".users-item__icon img[title='#{user.login_name} (#{user.name})']" + + visit_with_auth users_tags_path, 'kensyu' + displayed_users_number = find('.user-group__count').text[/\d+/] + assert_equal '2', displayed_users_number + assert_selector ".a-user-icons__items img[title='#{user.login_name} (#{user.name})']" + + visit_with_auth new_hibernation_path, 'kensyu' + within('form[name=hibernation]') do + fill_in( + 'hibernation[scheduled_return_on]', + with: (Date.current + 30) + ) + fill_in('hibernation[reason]', with: 'test') + end + find('.check-box-to-read').click + click_on '休会する' + page.driver.browser.switch_to.alert.accept + assert_text '休会処理が完了しました' + + visit_with_auth users_tag_path(tag_name), 'komagata' + assert_text "タグ「#{tag_name}」のユーザー(1)" + assert_no_selector ".users-item__icon img[title='#{user.login_name} (#{user.name})']" + + visit_with_auth users_tags_path, 'komagata' + displayed_users_number = find('.user-group__count').text[/\d+/] + assert_equal '1', displayed_users_number + assert_no_selector ".a-user-icons__items img[title='#{user.login_name} (#{user.name})']" + end + + test 'retired users are not displayed in the user list by tag' do + user = users(:kensyu) + tag_name = acts_as_taggable_on_tags('guitar').name.to_s + + User.tags.where.not(name: tag_name).destroy_all + + visit_with_auth users_tag_path(tag_name), 'kensyu' + assert_text "タグ「#{tag_name}」のユーザー(2)" + assert_selector ".users-item__icon img[title='#{user.login_name} (#{user.name})']" + + visit_with_auth users_tags_path, 'kensyu' + displayed_users_number = find('.user-group__count').text[/\d+/] + assert_equal '2', displayed_users_number + assert_selector ".a-user-icons__items img[title='#{user.login_name} (#{user.name})']" + + visit_with_auth new_retirement_path, 'kensyu' + find('label', text: 'とても良い').click + click_on '退会する' + page.driver.browser.switch_to.alert.accept + assert_text '退会処理が完了しました' + + visit_with_auth users_tag_path(tag_name), 'komagata' + assert_text "タグ「#{tag_name}」のユーザー(1)" + assert_no_selector ".users-item__icon img[title='#{user.login_name} (#{user.name})']" + + visit_with_auth users_tags_path, 'komagata' + displayed_users_number = find('.user-group__count').text[/\d+/] + assert_equal '1', displayed_users_number + assert_no_selector ".a-user-icons__items img[title='#{user.login_name} (#{user.name})']" + end end