diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index af43354190a..7d2aa4cc227 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) # rubocop:disable Rails/SkipsModelValidations + 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