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

ブログ記事を published_at 順に並べる #7955

Merged
merged 6 commits into from
Aug 21, 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
3 changes: 2 additions & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def set_article
end

def list_articles
articles = Article.with_attached_thumbnail.includes(user: { avatar_attachment: :blob }).order(created_at: :desc).page(params[:page])
articles = Article.with_attached_thumbnail.includes(user: { avatar_attachment: :blob })
.order(published_at: :desc, created_at: :desc).page(params[:page])
admin_or_mentor_login? ? articles : articles.where(wip: false)
end

Expand Down
8 changes: 8 additions & 0 deletions test/system/articles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class ArticlesTest < ApplicationSystemTestCase
setup do
@article = articles(:article1)
@article2 = articles(:article2)
@article3 = articles(:article3)
end

Expand Down Expand Up @@ -412,4 +413,11 @@ class ArticlesTest < ApplicationSystemTestCase
visit '/articles.atom'
assert_no_text 'WIPの記事は atom feed に表示されない'
end

test 'WIP articles are listed first in desc order' do
visit_with_auth articles_path, 'komagata'
titles = all('h2.thumbnail-card__title').map(&:text)

assert_equal titles, ["WIP#{@article3.title}", @article2.title, @article.title]
end
end