Skip to content

Commit

Permalink
最新の更新順に質問を並びかえるスコープの名前を具体的なものに修正
Browse files Browse the repository at this point in the history
  • Loading branch information
junohm410 committed Mar 6, 2024
1 parent 80a0a5c commit ff86b95
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index
.by_tag(params[:tag])
.with_avatar
.includes(:practice, :answers, :tags, :correct_answer)
.recent
.latest_update_order
.page(params[:page])
@questions_property = Question.generate_questions_property(params[:target])
end
Expand All @@ -31,7 +31,7 @@ def show
.where(practice: @question.practice)
.where.not(id: @question.id)
.includes(:correct_answer)
.recent
.latest_update_order
.limit(MAX_PRACTICE_QUESTIONS_DISPLAYED)
respond_to do |format|
format.html
Expand Down
2 changes: 1 addition & 1 deletion app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Question < ApplicationRecord
scope :not_solved, -> { where.not(id: CorrectAnswer.select(:question_id)) }
scope :wip, -> { where(wip: true) }
scope :not_wip, -> { where(wip: false) }
scope :recent, -> { order(updated_at: :desc, id: :desc) }
scope :latest_update_order, -> { order(updated_at: :desc, id: :desc) }
scope :by_practice_id, ->(practice_id) { where(practice_id:) if practice_id.present? }
scope :by_tag, ->(tag) { tagged_with(tag) if tag }
scope :by_target, lambda { |target|
Expand Down
4 changes: 2 additions & 2 deletions test/models/question_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class QuestionTest < ActiveSupport::TestCase
assert_includes Question.by_target(nil), not_solved_question
end

test '.recent' do
test '.latest_update_order' do
Question.destroy_all
question1 = Question.create!(
title: 'テストの質問',
Expand All @@ -75,7 +75,7 @@ class QuestionTest < ActiveSupport::TestCase
updated_at: '2022-03-01'
)

assert_equal [question3, question2, question1], Question.recent
assert_equal [question3, question2, question1], Question.latest_update_order
end

test '.by_practice_id' do
Expand Down

0 comments on commit ff86b95

Please sign in to comment.