Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

タグ別のユーザーページにおいて「休会」と「退会」ユーザーが表示されない仕様に統一 #7089

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -352,6 +352,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 @@ -404,7 +405,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})']"
Copy link
Contributor

@junohm410 junohm410 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users/tagsページ上のユーザーアイコンの検索・アサーションでは、「ターゲットとなるユーザーが、このページ上の他のタグにも属している」という可能性を考えると、withinなどで「ギター」タグのユーザー一覧の中にスコープを絞ってアイコン検索するようにした方がいいかなと考えましたが、いかがでしょうか?👀

Copy link
Contributor Author

@2525nicole 2525nicole Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junohm410
※お先にコメントのご返信のみ失礼いたします><!
CircleCIが通りましたら別途「ご確認をお願いいたします」とご連絡しますので、
その後確認をいただけますと幸いです🙏

ご提案ありがとうございます🙇‍♀️
HTMLの構造上、特定のタグ名とタグに属するアイコンに共通するセレクタを指定するのが難しそうに感じたのでアプローチを変更いたしました🙇‍♀️

ser.tags.where.not(name: tag_name).destroy_allによりアプリ内で「ギター」タグのみを残すことで、
「ギター」タグのみに対して表示を確認できるようにしております🙏

ここでテストしたいのはタグ別ページにおいて「休会と退会ユーザーが表示されなくなること」なので、
ターゲットとなる「ギター」以外のタグをページに残した状態でテストを行う必要がない(=kensyuが登録している「ギター」タグのみ表示し、テストできれば良い)のではないかと判断いたしました🙏

参考にさせていただいた記事:
【minitest / RSpec】繰り返し表示されている要素の中から「これ」という1件を選んで検証する方法あれこれ #Rails - Qiita

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご修正ありがとうございます!
ご説明やURLを拝読しあらためて実際のHTML要素もみたところ、withinでは解決しにくい問題でしたね🙇‍♂️こちらはすみませんでした🙏

ギタータグ以外のタグ登録を消去して、今回検証したい「ギター」に対し、kensyuが属するか否かを確実に確認するという方針について、把握しました!
大変勉強になりました🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junohm410
ご確認ありがとうございます🙇‍♀️
とんでもないです!!HTML要素まで見ていただき恐れ入ります🙏
「対象を絞る」という視点が不足していたので、大事な点をご教示いただきこちらこそ大変勉強になりました!
ありがとうございます🙇‍♀️


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