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

Docを初回公開する時のみ「Doc公開」、それ以外は「内容を更新」と表示するようボタンテキストを変更 #8100

Merged
merged 2 commits into from
Oct 13, 2024
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
15 changes: 8 additions & 7 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]?
Expand All @@ -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
Expand All @@ -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?
Expand All @@ -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
Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions app/views/pages/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions test/system/notification/pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
8 changes: 4 additions & 4 deletions test/system/pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down