Skip to content

Commit

Permalink
Merge branch 'production' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
komagata authored Feb 18, 2022
2 parents aa7d652 + 84b58ff commit 5ee6f35
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
4 changes: 3 additions & 1 deletion app/models/comment/after_create_callback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ def create_watch(comment)
end

def create_checker_id(comment)
return nil unless comment.user.mentor?

product = comment.commentable
product.checker_id = comment.sender.id if product.checker_id.blank?
product.checker_id = comment.sender.id unless product.checker_id?
end

def delete_product_cache(product_id)
Expand Down
1 change: 1 addition & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Product < ApplicationRecord

belongs_to :practice
belongs_to :user, touch: true
belongs_to :checker, class_name: 'Product', optional: true
alias sender user

after_create ProductCallbacks.new
Expand Down
61 changes: 61 additions & 0 deletions test/system/product/checker_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require 'application_system_test_case'

class Product::CheckerTest < ApplicationSystemTestCase
test 'be person on charge at comment on product of there are not person on charge' do
visit_with_auth '/products/unchecked?target=unchecked_no_replied', 'machida'
def assigned_product_count
text[/自分の担当 ((\d+))/, 1].to_i
end

before_comment = assigned_product_count

[
'担当者がいない提出物の場合、担当者になる',
'自分が担当者の場合、担当者のまま'
].each do |comment|
visit "/products/#{products(:product1).id}"
post_comment(comment)

visit '/products/unchecked?target=unchecked_no_replied'
assert_equal before_comment + 1, assigned_product_count
end
end

test 'be not person on charge at comment on product of there are person on charge' do
visit_with_auth '/products/unchecked?target=unchecked_no_replied', 'komagata'
product = find('.thread-list-item', match: :first)
product.click_button '担当する'
show_product_path = product.find_link(href: /products/)[:href]
logout

visit_with_auth '/products/unchecked?target=unchecked_no_replied', 'machida'

def assigned_product_count
text[/自分の担当 ((\d+))/, 1].to_i
end

before_comment = assigned_product_count

visit show_product_path
post_comment('担当者がいる提出物の場合、担当者にならない')

visit '/products/unchecked?target=unchecked_no_replied'
assert_equal before_comment, assigned_product_count
end

test 'when student comment to a product, they are not in charge' do
old_product = products(:product8)

visit_with_auth product_url(old_product), 'kimura'

within first('#comments.loaded', wait: 10) do
fill_in 'new_comment[description]', with: 'edit test'
click_button 'コメントする'
end

assert_text 'コメントを投稿しました'
assert_nil Product.find(old_product.id).checker_id
end
end
42 changes: 0 additions & 42 deletions test/system/products_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,48 +353,6 @@ class ProductsTest < ApplicationSystemTestCase
assert_not page.has_css?('.pagination')
end

test 'be person on charge at comment on product of there are not person on charge' do
visit_with_auth '/products/unchecked?target=unchecked_no_replied', 'machida'
def assigned_product_count
text[/自分の担当 ((\d+))/, 1].to_i
end

before_comment = assigned_product_count

[
'担当者がいない提出物の場合、担当者になる',
'自分が担当者の場合、担当者のまま'
].each do |comment|
visit "/products/#{products(:product1).id}"
post_comment(comment)

visit '/products/unchecked?target=unchecked_no_replied'
assert_equal before_comment + 1, assigned_product_count
end
end

test 'be not person on charge at comment on product of there are person on charge' do
visit_with_auth '/products/unchecked?target=unchecked_no_replied', 'komagata'
product = find('.thread-list-item', match: :first)
product.click_button '担当する'
show_product_path = product.find_link(href: /products/)[:href]
logout

visit_with_auth '/products/unchecked?target=unchecked_no_replied', 'machida'

def assigned_product_count
text[/自分の担当 ((\d+))/, 1].to_i
end

before_comment = assigned_product_count

visit show_product_path
post_comment('担当者がいる提出物の場合、担当者にならない')

visit '/products/unchecked?target=unchecked_no_replied'
assert_equal before_comment, assigned_product_count
end

test 'show user full_name next to user login_name' do
visit_with_auth "/products/#{products(:product1).id}", 'kimura'
assert_text 'mentormentaro (メンタ 麺太郎)'
Expand Down

0 comments on commit 5ee6f35

Please sign in to comment.