This commit is contained in:
2026-03-22 19:52:14 +09:00
parent 76f8e6875e
commit 63c1dd197c
4 changed files with 61 additions and 43 deletions
@@ -6,7 +6,7 @@ class TheatreCommentsController < ApplicationController
comments = TheatreComment
.where(theatre_id: params[:theatre_id])
.where('no > ?', no_gt)
.order(:no)
.order(no: :desc)
render json: comments.as_json(include: { user: { only: [:id, :name] } })
end
@@ -51,14 +51,14 @@ RSpec.describe 'TheatreComments', type: :request do
)
end
it 'theatre_id で絞り込み、no_gt より大きいものを no 順で返す' do
it 'theatre_id で絞り込み、no_gt より大きいものを no 順で返す' do
get "/theatres/#{theatre.id}/comments", params: { no_gt: 1 }
expect(response).to have_http_status(:ok)
expect(response.parsed_body.map { |row| row['no'] }).to eq([2, 3])
expect(response.parsed_body.map { |row| row['no'] }).to eq([3, 2])
expect(response.parsed_body.map { |row| row['content'] }).to eq([
'second comment',
'third comment'
'third comment',
'second comment'
])
end
@@ -68,8 +68,8 @@ RSpec.describe 'TheatreComments', type: :request do
expect(response).to have_http_status(:ok)
expect(response.parsed_body.first['user']).to eq({
'id' => bob.id,
'name' => 'Bob'
'id' => alice.id,
'name' => 'Alice'
})
expect(response.parsed_body.first['user'].keys).to contain_exactly('id', 'name')
end
@@ -78,7 +78,7 @@ RSpec.describe 'TheatreComments', type: :request do
get "/theatres/#{theatre.id}/comments", params: { no_gt: -100 }
expect(response).to have_http_status(:ok)
expect(response.parsed_body.map { |row| row['no'] }).to eq([1, 2, 3])
expect(response.parsed_body.map { |row| row['no'] }).to eq([3, 2, 1])
end
end
+20 -2
View File
@@ -117,11 +117,18 @@ RSpec.describe 'Theatres API', type: :request do
expect(theatre.host_user_id).to eq(member.id)
expect(watch.expires_at).to be_within(1.second).of(30.seconds.from_now)
expect(json).to eq(
expect(json).to include(
'host_flg' => true,
'post_id' => nil,
'post_started_at' => nil
)
expect(json.fetch('watching_users')).to contain_exactly(
{
'id' => member.id,
'name' => 'member user'
}
)
end
end
@@ -167,11 +174,22 @@ RSpec.describe 'Theatres API', type: :request do
expect(response).to have_http_status(:ok)
expect(theatre.reload.host_user_id).to eq(other_user.id)
expect(json).to eq(
expect(json).to include(
'host_flg' => false,
'post_id' => nil,
'post_started_at' => nil
)
expect(json.fetch('watching_users')).to contain_exactly(
{
'id' => member.id,
'name' => 'member user'
},
{
'id' => other_user.id,
'name' => 'other user'
}
)
end
end