Skip to content

Commit

Permalink
Merge pull request #7889 from fjordllc/bug/notify_only_when_blog_firs…
Browse files Browse the repository at this point in the history
…t_published

ブログを更新するたびに通知されていたバグを初回公開時のみ通知されるように修正
  • Loading branch information
komagata authored Jul 7, 2024
2 parents ec3bb3d + 9643988 commit 7d86267
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/article_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
49 changes: 49 additions & 0 deletions test/system/notification/articles_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7d86267

Please sign in to comment.