Skip to content

Commit

Permalink
Merge pull request #7089 from fjordllc/bug/exclude-hibernated-and-ret…
Browse files Browse the repository at this point in the history
…ired-users-from-users-list-by-tag

タグ別のユーザーページにおいて「休会」と「退会」ユーザーが表示されない仕様に統一
  • Loading branch information
komagata authored Dec 31, 2023
2 parents 394e2e1 + c8f7838 commit cbe4137
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/views/tags/_tag.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
= 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}
span.user-group__count
| (#{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
5 changes: 5 additions & 0 deletions test/fixtures/acts_as_taggable_on/taggings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions test/system/user/tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cbe4137

Please sign in to comment.