From fd214e83d34f003df5bb87a2b503f089eab95a7f Mon Sep 17 00:00:00 2001 From: yamadaab Date: Wed, 11 Aug 2021 18:20:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E3=81=BFQ&A=E3=82=92Watch=E4=B8=AD=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/questions_controller.rb | 17 +++++++++++++++++ test/system/questions_test.rb | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index af43354190a..bea6e471af4 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -41,6 +41,7 @@ def create @question = Question.new(question_params) @question.user = current_user if @question.save + create_mentors_watch notify_to_chat(@question) redirect_to @question, notice: '質問を作成しました。' else @@ -95,4 +96,20 @@ def questions_property QuestionsProperty.new('未解決の質問一覧', '未解決の質問はまだありません。') end end + + def create_mentors_watch + Watch.insert_all(watch_records) + end + + def watch_records + User.mentor.map do |mentor| + { + watchable_type: 'Question', + watchable_id: @question.id, + created_at: Time.current, + updated_at: Time.current, + user_id: mentor.id + } + end + end end diff --git a/test/system/questions_test.rb b/test/system/questions_test.rb index 4e45f494fa6..5c290de62ce 100644 --- a/test/system/questions_test.rb +++ b/test/system/questions_test.rb @@ -277,4 +277,14 @@ class QuestionsTest < ApplicationSystemTestCase click_link '2', match: :first assert_selector '.thread-list-item', count: 25 end + + test 'mentor create a question' do + visit_with_auth new_question_path, 'komagata' + within 'form[name=question]' do + fill_in 'question[title]', with: 'メンターのみ投稿された質問が"Watch中"になるテスト' + fill_in 'question[description]', with: 'メンターのみ投稿された質問が"Watch中"になるテスト' + click_button '登録する' + end + assert_text 'Watch中' + end end From 33183b2443ee01007eb4140175ca1190086b457d Mon Sep 17 00:00:00 2001 From: yamadaab Date: Mon, 4 Oct 2021 07:08:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?rubocop=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/questions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index bea6e471af4..7d2aa4cc227 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -98,7 +98,7 @@ def questions_property end def create_mentors_watch - Watch.insert_all(watch_records) + Watch.insert_all(watch_records) # rubocop:disable Rails/SkipsModelValidations end def watch_records