Skip to content

Commit

Permalink
Merge pull request #7955 from fjordllc/feature/order-articles-by-publ…
Browse files Browse the repository at this point in the history
…ished_at-desc

ブログ記事を published_at 順に並べる
  • Loading branch information
komagata authored Aug 21, 2024
2 parents e671dc5 + e59f94d commit e473f98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit e473f98

Please sign in to comment.