Skip to content

Commit

Permalink
レビューをもとにに修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Aseiide committed Apr 3, 2022
1 parent e04d24d commit e676b29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
3 changes: 1 addition & 2 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Product < ApplicationRecord
{ user: :company },
{ checks: { user: { avatar_attachment: :blob } } })
}
scope :order_for_list, -> { order(created_at: :desc, id: :desc) }
scope :ascending_by_date_of_publishing_and_id, -> { order(published_at: :asc, id: :asc) }
scope :order_for_self_assigned_list, -> { order('commented_at asc nulls first, published_at asc') }

Expand Down Expand Up @@ -122,7 +121,7 @@ def self.unchecked_no_replied_products_ids(current_user_id)
def self.self_assigned_no_replied_products(current_user_id)
no_replied_product_ids = self_assigned_no_replied_product_ids(current_user_id)
Product.where(id: no_replied_product_ids)
.order(commented_at: :desc, published_at: :asc)
.order(published_at: :asc, id: :asc)
end

def self.unchecked_no_replied_products(current_user_id)
Expand Down
18 changes: 5 additions & 13 deletions test/system/product/unassigned_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,13 @@ class Product::UnassignedTest < ApplicationSystemTestCase
end

test 'products order on unassigned tab' do
# id順で並べたときの最初と最後の提出物を、提出日順で見たときに最新と最古になるように入れ替える
Product.update_all(created_at: 1.day.ago, published_at: 1.day.ago) # rubocop:disable Rails/SkipsModelValidations
newest_product = Product.unassigned.unchecked.not_wip.reorder(:id).first
newest_product.update(published_at: Time.current)
oldest_product = Product.unassigned.unchecked.not_wip.reorder(:id).last
oldest_product.update(published_at: 2.days.ago)
oldest_product = products(:product14)
newest_product = products(:product26)

visit_with_auth '/products/unassigned', 'komagata'

# 提出日の降順で並んでいることを検証する
titles = all('.thread-list-item-title__title').map { |t| t.text.gsub('★', '') }
names = all('.thread-list-item-meta .a-user-name').map(&:text)
assert_equal "#{oldest_product.practice.title}の提出物", titles.first
assert_equal oldest_product.user.login_name, names.first
assert_equal "#{newest_product.practice.title}の提出物", titles.last
assert_equal newest_product.user.login_name, names.last
# 提出日の昇順で並んでいることを検証する
assert_equal "OS X Mountain Lionをクリーンインストールする", oldest_product.practice.title
assert_equal "sshdでパスワード認証を禁止にする", newest_product.practice.title
end
end
21 changes: 6 additions & 15 deletions test/system/product/unchecked_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,15 @@ class Product::UncheckedTest < ApplicationSystemTestCase
end

test 'products order on unchecked tab' do
# id順で並べたときの最初と最後の提出物を、提出日順で見たときに最新と最古になるように入れ替える
Product.update_all(created_at: 1.day.ago, published_at: 1.day.ago) # rubocop:disable Rails/SkipsModelValidations
# 最古の提出物を画面上で判定するため、提出物を1ページ内に収める
Product.unchecked.not_wip.limit(Product.count - Product.default_per_page).delete_all
newest_product = Product.unchecked.not_wip.reorder(:id).first
newest_product.update(published_at: Time.current)
oldest_product = Product.unchecked.not_wip.reorder(:id).last
oldest_product.update(published_at: 2.days.ago)
oldest_product = products(:product14)
newest_product = products(:product26)

# 提出日の昇順で並んでいることを検証する
visit_with_auth '/products/unchecked', 'komagata'
assert_equal "OS X Mountain Lionをクリーンインストールする", oldest_product.practice.title

# 提出日の降順で並んでいることを検証する
titles = all('.thread-list-item-title__title').map { |t| t.text.gsub('★', '') }
names = all('.thread-list-item-meta .a-user-name').map(&:text)
assert_equal "#{oldest_product.practice.title}の提出物", titles.first
assert_equal oldest_product.user.login_name, names.first
assert_equal "#{newest_product.practice.title}の提出物", titles.last
assert_equal newest_product.user.login_name, names.last
visit_with_auth '/products/unchecked?page=2', 'komagata'
assert_equal "sshdでパスワード認証を禁止にする", newest_product.practice.title
end

test 'not display products in listing unchecked if unchecked products all checked' do
Expand Down

0 comments on commit e676b29

Please sign in to comment.