Skip to content

Commit

Permalink
Merge pull request #7012 from fjordllc/feature/put-the-changed-author…
Browse files Browse the repository at this point in the history
…-on-watch-if-you-change-the-author-of-docs

Docの作者をWatch中になるようにした
  • Loading branch information
komagata authored Dec 14, 2023
2 parents 13a045a + 36f09f3 commit 9b38599
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create
url = new_announcement_url(page_id: @page.id) if @page.announcement_of_publication?
end

current_user.become_watcher!(@page)
become_watcher!(@page, [current_user, @page.user])

redirect_to url, notice: notice_message(@page, :create)
else
Expand All @@ -64,7 +64,7 @@ def update
url = new_announcement_path(page_id: @page.id) if @page.announcement_of_publication?
end

current_user.become_watcher!(@page)
become_watcher!(@page, [current_user, @page.user])

redirect_to url, notice: notice_message(@page, :update)
else
Expand Down Expand Up @@ -117,4 +117,8 @@ def redirect_to_slug

redirect_to request.original_url.sub(params[:slug_or_id], @page.slug) unless params[:slug_or_id].start_with?(/[a-z]/)
end

def become_watcher!(page, users)
users.each { |user| user.become_watcher!(page) }
end
end
38 changes: 37 additions & 1 deletion test/system/pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class PagesTest < ApplicationSystemTestCase
assert_match 'Message to Discord.', mock_log.to_s
end

test 'non-author docs editor becomes Watcher when editing docs' do
test 'non-author docs editor becomes watcher' do
# 編集前にWatch中になってないかチェック(作成者を除くDocs編集者)
editor = 'machida'
visit_with_auth page_path(pages(:page1)), editor
Expand All @@ -250,6 +250,42 @@ class PagesTest < ApplicationSystemTestCase
assert_text 'Watch中'
end

test 'author becomes watcher' do
author = 'kimura'
# 編集前にWatch中になってないかチェック
visit_with_auth page_path(pages(:page1)), author
assert_text 'Watch'
visit page_path(pages(:page2))
assert_text 'Watch'

logout

# 編集者もwatch中になるため、作者と編集者を別にする
editor = 'machida'
visit_with_auth edit_page_path(pages(:page1)), editor

within('.form') do
find('#select2-page_user_id-container').click
select(author, from: 'page[user_id]')
end
click_button '内容を更新'

visit edit_page_path(pages(:page2))

within('.form') do
find('#select2-page_user_id-container').click
select(author, from: 'page[user_id]')
end
click_button 'WIP'

logout

visit_with_auth page_path(pages(:page1)), author
assert_text 'Watch中'
visit page_path(pages(:page2))
assert_text 'Watch中'
end

test 'Check the list of columns on the right of the document' do
visit_with_auth "/pages/#{pages(:page7).id}", 'kimura'
assert_link 'OS X Mountain Lionをクリーンインストールする'
Expand Down

0 comments on commit 9b38599

Please sign in to comment.