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

ユーザーの検索結果に、管理者でログインしたときだけそのユーザーの相談部屋へのリンクを表示 #4147

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8790657
first commit
ot0m1 Feb 5, 2022
f859a3f
相談部屋へのリンクを表示
ot0m1 Feb 10, 2022
5b38b4a
冗長な条件分岐をリファクタリング
ot0m1 Feb 10, 2022
b0f7b84
さらにリファクタリング
ot0m1 Feb 10, 2022
1142061
rubocop通した
ot0m1 Feb 10, 2022
4059f8d
さらにリファクタリング
ot0m1 Feb 10, 2022
4c85f20
クリップボードのテストを通るように修正
ot0m1 Feb 14, 2022
1bea353
talk?メソッドの返り値をbooleanのみに
ot0m1 Feb 17, 2022
8e9eea5
メソッド名を具体的に
ot0m1 Feb 17, 2022
11ea071
管理者だけにリンクが表示されるように変更
ot0m1 Feb 17, 2022
9cdc350
不要な条件分岐を削除
ot0m1 Feb 17, 2022
f9d98ee
管理者かを判断するロジックをVue側に持たせた
ot0m1 Feb 17, 2022
65cfe98
テストを追加
ot0m1 Feb 17, 2022
cc300ee
最新の origin/mian を取り込み
ot0m1 Feb 19, 2022
fe5ba3d
テストの条件を変更
ot0m1 Feb 19, 2022
33b922b
ヘルパーのテストを追加
ot0m1 Feb 22, 2022
fba40bd
テスト名を修正
ot0m1 Feb 22, 2022
6522a73
不要なヘルパーメソッドを削除
ot0m1 Feb 22, 2022
0072d92
不要なヘルパーテストを削除
ot0m1 Feb 22, 2022
634086f
テストのパターンを追加
ot0m1 Feb 25, 2022
8a7fa44
不要なスペースを削除
ot0m1 Feb 28, 2022
f6fc8a7
テストが通るように最新の origin/main を取り込み
ot0m1 Mar 1, 2022
7f133ba
テスト名を変更
ot0m1 Mar 2, 2022
028fd7e
テストが通るように最新の origin/main を取り込み
ot0m1 Mar 2, 2022
57c1b36
適切なアサーションに修正
ot0m1 Mar 3, 2022
e2093ac
間違った assert の引数を修正
ot0m1 Mar 7, 2022
ad279f9
冗長な変数宣言を削除
ot0m1 Mar 8, 2022
4b9677e
テストを分割
ot0m1 Mar 10, 2022
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
4 changes: 4 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ def filtered_message(searchable)
def comment_or_answer?(searchable)
searchable.is_a?(Comment) || searchable.is_a?(Answer)
end

def talk?(searchable)
Copy link
Member

Choose a reason for hiding this comment

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

対応するhelperのテストがあるといいかもです〜

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ヘルパーテストを追加するみたいな考えが全くありませんでした🙏
追加しました。

searchable.instance_of?(User) && searchable.talk.present?
end
end
15 changes: 15 additions & 0 deletions app/javascript/searchable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,25 @@
| {{ searchable.document_author_login_name }}
|  {{ searchable.model_name_with_i18n }}
| )
a(v-if='isRole("admin") && canDisplayTalk', :href='talkUrl')
| 相談部屋
</template>
<script>
import dayjs from 'dayjs'
import ja from 'dayjs/locale/ja'
import role from './role'
dayjs.locale(ja)
export default {
mixins: [role],
props: {
searchable: { type: Object, required: true },
word: { type: String, required: true }
},
data() {
return {
currentUser: window.currentUser
}
},
computed: {
modelName() {
return `is-${this.searchable.model_name}`
Expand All @@ -61,6 +70,12 @@ export default {
'YYYY年MM月DD日(dd) HH:mm'
)
},
canDisplayTalk() {
return this.searchable.model_name === 'user' && this.searchable.talk_id
},
talkUrl() {
return `/talks/${this.searchable.talk_id}`
},
summary() {
const word = this.word
const wordsPattern = word
Expand Down
3 changes: 3 additions & 0 deletions app/views/api/searchables/_searchable.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ if comment_or_answer?(searchable)
json.document_author_login_name document.user.login_name
json.document_author_id document.user.id
end
if talk?(searchable)
json.talk_id searchable.talk.id
end
13 changes: 13 additions & 0 deletions test/helpers/search_hepler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require 'test_helper'

class SearchHelperTest < ActionView::TestCase
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class SearchHelperTest < ActionView::TestCase
class SearchHelperTest < ActionView::TestCase

test 'does it return correct boolean value in talk' do
Copy link
Member

Choose a reason for hiding this comment

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

「talkかどうかを返す」みたいな内容でいいと思います〜。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

テスト名変更しました。

user = users(:kimura)
assert_equal true, talk?(user)
Copy link
Member

Choose a reason for hiding this comment

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

trueかどうかのチェックはassertメソッドがいいと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

アサーションの種類について全然把握していませんでした🙇‍♂️

Rails テスティングガイドを見て assert と assert_not を用いるのが良いことを理解しました。


user = users(:taikai3)
assert_equal false, talk?(user)
end
end
20 changes: 20 additions & 0 deletions test/system/searchables_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,24 @@ class SearchablesTest < ApplicationSystemTestCase
assert_text 'kimura'
assert_no_text 'machida'
end

test 'check that link to talk room is displayed properly' do
Copy link
Member

Choose a reason for hiding this comment

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

  • 管理者で相談部屋へのリンクが表示される
  • 管理者以外で相談部屋へのリンクが表示されない

こちらは二つのテストケースに分けた方がテストのタイトルと合わせてわかりやすいかもです〜

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確かに…🙏 分割しました。

visit_with_auth '/', 'hatsuno'
within('form[name=search]') do
select 'すべて'
fill_in 'word', with: ''
end
find('#test-search').click
assert_no_text '相談部屋'

logout

visit_with_auth '/', 'komagata'
within('form[name=search]') do
select 'ユーザー'
fill_in 'word', with: ''
end
find('#test-search').click
assert_text '相談部屋'
end
end