diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 0ce120ca80c..51f932db5f0 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -41,6 +41,7 @@ def create @page.last_updated_user = current_user @page.user ||= current_user set_wip + is_published = @page.published_at? if @page.save url = Redirection.determin_url(self, @page) if !@page.wip? @@ -50,7 +51,7 @@ def create become_watcher!(@page, [current_user, @page.user]) - redirect_to url, notice: notice_message(@page, :create) + redirect_to url, notice: notice_message(@page, is_published) else render :new end @@ -59,6 +60,7 @@ def create def update set_wip @page.last_updated_user = current_user + is_published = @page.published_at? if @page.update(page_params) url = Redirection.determin_url(self, @page) if @page.saved_change_to_attribute?(:wip, from: true, to: false) && @page.published_at.nil? @@ -68,7 +70,7 @@ def update become_watcher!(@page, [current_user, @page.user]) - redirect_to url, notice: notice_message(@page, :update) + redirect_to url, notice: notice_message(@page, is_published) else render :edit end @@ -95,14 +97,13 @@ def set_wip @page.wip = params[:commit] == 'WIP' end - def notice_message(page, action_name) + def notice_message(page, is_published) return 'ドキュメントをWIPとして保存しました。' if page.wip? - case action_name - when :create - 'ドキュメントを作成しました。' - when :update + if is_published 'ドキュメントを更新しました。' + else + 'ドキュメントを作成しました。' end end diff --git a/app/views/pages/_form.html.slim b/app/views/pages/_form.html.slim index 089033f7904..b665396a277 100644 --- a/app/views/pages/_form.html.slim +++ b/app/views/pages/_form.html.slim @@ -75,10 +75,9 @@ i.fa-solid.fa-question = button_tag(class: 'a-button is-lg is-primary is-block') do - - case params[:action] - - when 'new', 'create' + - if page.published_at.blank? | Docを公開 - - when 'edit', 'update' + - else | 内容を更新 li.form-actions__item.is-sub - case params[:action] diff --git a/test/system/notification/pages_test.rb b/test/system/notification/pages_test.rb index 35ea8e6c774..5b9f180437b 100644 --- a/test/system/notification/pages_test.rb +++ b/test/system/notification/pages_test.rb @@ -65,8 +65,8 @@ class Notification::PagesTest < ApplicationSystemTestCase visit_with_auth page_path(page), 'komagata' click_link '内容変更' - click_button '内容を更新' - assert_text 'ドキュメントを更新しました。' + click_button 'Docを公開' + assert_text 'ドキュメントを作成しました。' visit_with_auth '/notifications', 'machida' diff --git a/test/system/pages_test.rb b/test/system/pages_test.rb index 25679f23731..b029f63e939 100644 --- a/test/system/pages_test.rb +++ b/test/system/pages_test.rb @@ -224,10 +224,10 @@ class PagesTest < ApplicationSystemTestCase stub_info = proc { |i| mock_log << i } Rails.logger.stub(:info, stub_info) do - click_button '内容を更新' + click_button 'Docを公開' end - assert_text 'ドキュメントを更新しました。' + assert_text 'ドキュメントを作成しました。' assert_match 'Message to Discord.', mock_log.to_s end @@ -312,9 +312,9 @@ class PagesTest < ApplicationSystemTestCase click_button 'WIP' check 'ドキュメント公開のお知らせを書く', allow_label_click: true - click_button '内容を更新' + click_button 'Docを公開' - assert_text 'ドキュメントを更新しました。' + assert_text 'ドキュメントを作成しました。' assert has_field?('announcement[title]', with: 'ドキュメント「お知らせにチェックを入れてWIP状態から新規Docを作成」を公開しました。') assert_text '「お知らせにチェックを入れてWIP状態から新規Docを作成」の本文です。' end