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

お知らせの初回公開時に通知が発行されるように修正 #5662

Merged
merged 2 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/controllers/announcements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def update
set_wip

if @announcement.update(announcement_params)
Newspaper.publish(:announcement_create, @announcement) if @announcement.saved_change_to_published_at?(from: nil)
redirect_to @announcement, notice: notice_message(@announcement)
else
render :edit
Expand Down
48 changes: 48 additions & 0 deletions test/system/announcements_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,54 @@ class AnnouncementsTest < ApplicationSystemTestCase
assert_text 'お知らせをWIPとして保存しました。'
end

test 'create announcement with notification' do
visit_with_auth new_announcement_path, 'komagata'
fill_in 'announcement[title]', with: '公開お知らせ'
fill_in 'announcement[description]', with: '公開されるお知らせです。'
assert_difference 'Announcement.count', 1 do
click_button '作成'
end

visit_with_auth '/notifications', 'hatsuno'
assert_text 'お知らせ「公開お知らせ」'
end

test 'publish wip announcement with notification' do
announcement = announcements(:announcement_wip)
visit_with_auth announcement_path(announcement), 'komagata'
within '.announcement' do
click_link '内容修正'
end
click_button '公開'

visit_with_auth '/notifications', 'hatsuno'
assert_text 'お知らせ「wipのお知らせ」'
end

test 'update published announcement without notification' do
announcement = announcements(:announcement1)
visit_with_auth announcement_path(announcement), 'komagata'
within '.announcement' do
click_link '内容修正'
end
click_button '公開'

visit_with_auth '/notifications', 'hatsuno'
assert_no_text 'お知らせ「お知らせ1」'
end

test 'create wip announcement without notification' do
visit_with_auth new_announcement_path, 'komagata'
fill_in 'announcement[title]', with: '仮のお知らせ'
fill_in 'announcement[description]', with: 'まだWIPです。'
assert_difference 'Announcement.count', 1 do
click_button 'WIP'
end

visit_with_auth '/notifications', 'hatsuno'
assert_no_text 'お知らせ「仮のお知らせ」'
end

test 'delete announcement with notification' do
visit_with_auth '/announcements', 'komagata'
click_link 'お知らせ作成'
Expand Down