From 43c83f8eb8d370edfa7dd39fece209d400f57a1f Mon Sep 17 00:00:00 2001 From: motohiro-mm Date: Mon, 24 Jun 2024 18:59:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=83=96=E3=83=AD=E3=82=B0=E5=88=9D?= =?UTF-8?q?=E5=9B=9E=E5=85=AC=E9=96=8B=E3=81=AE=E3=81=BF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E6=9D=A1=E4=BB=B6=E5=88=86?= =?UTF-8?q?=E5=B2=90=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/article_notifier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/article_notifier.rb b/app/models/article_notifier.rb index f85ee675170..a13e924f6a9 100644 --- a/app/models/article_notifier.rb +++ b/app/models/article_notifier.rb @@ -3,7 +3,7 @@ class ArticleNotifier def call(payload) article = payload[:article] - return if article.wip? + return unless article.saved_change_to_attribute?(:published_at, from: nil) receivers = User.students_trainees_mentors_and_admins.reject { |receiver| receiver == article.user } send_notification(article:, receivers:) From 9643988e633f553f621fd75de5ee0b265281cc37 Mon Sep 17 00:00:00 2001 From: motohiro-mm Date: Mon, 24 Jun 2024 18:59:49 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/notification/articles_test.rb | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/system/notification/articles_test.rb diff --git a/test/system/notification/articles_test.rb b/test/system/notification/articles_test.rb new file mode 100644 index 00000000000..5efd26e284f --- /dev/null +++ b/test/system/notification/articles_test.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class ArticlesTest < ApplicationSystemTestCase + setup do + @article = articles(:article1) + @delivery_mode = AbstractNotifier.delivery_mode + AbstractNotifier.delivery_mode = :normal + end + + teardown do + AbstractNotifier.delivery_mode = @delivery_mode + end + + test 'the notification is sent only when the article is first published' do + visit_with_auth new_article_path, 'komagata' + fill_in('article_title', with: '通知テスト1回目') + fill_in('article_body', with: 'test') + click_on '公開する' + assert_text '記事を作成しました' + + visit_with_auth notifications_path, 'hajime' + within first('.card-list-item.is-unread') do + assert_text 'komagataさんがブログに「通知テスト1回目」を投稿しました。' + end + click_link '全て既読にする' + + visit_with_auth edit_article_path(@article), 'komagata' + fill_in('article_title', with: '通知テスト2回目') + click_on '更新する' + + visit_with_auth notifications_path, 'hajime' + assert_no_selector '.card-list-item.is-unread' + assert_no_text 'komagataさんがブログに「通知テスト2回目」を投稿しました。' + end + + test 'the notification is not sent when the article with WIP is saved' do + visit_with_auth new_article_path, 'komagata' + fill_in('article_title', with: '通知テストwip') + fill_in('article_body', with: 'test') + click_on 'WIP' + assert_text '記事をWIPとして保存しました' + + visit_with_auth notifications_path, 'hajime' + assert_no_selector '.card-list-item.is-unread' + assert_no_text 'komagataさんがブログに「通知テストwip」を投稿しました。' + end +end