このコミットが含まれているのは:
@@ -83,6 +83,10 @@ service, representation, and spec.
|
||||
by 4 spaces.
|
||||
- Put one logical pair per line when the expression would otherwise become
|
||||
dense.
|
||||
- For Ruby arrays, never put whitespace or a line break immediately before `]`.
|
||||
- Keep the first element on the same line as `[` by default.
|
||||
- If an array would exceed the line limit, break after `[` and indent
|
||||
elements by 4 spaces.
|
||||
- For Ruby blocks, use 2-space indentation for the block body.
|
||||
- Keep comments short and useful; avoid narrating obvious code.
|
||||
- Do not add production dependencies without approval.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
class TheatrePostSelector
|
||||
Candidate = Struct.new(:post, :weight, :penalty, :tags, keyword_init: true)
|
||||
ELIGIBLE_POST_URL_CONDITION =
|
||||
["url LIKE '%nicovideo.jp%'",
|
||||
"url LIKE '%youtube.com/watch%'",
|
||||
"url LIKE '%youtu.be/%'"]
|
||||
.join(' OR ')
|
||||
|
||||
def initialize theatre:
|
||||
@theatre = theatre
|
||||
@@ -52,7 +57,7 @@ class TheatrePostSelector
|
||||
end
|
||||
|
||||
def eligible_posts
|
||||
posts = Post.where("url LIKE '%nicovideo.jp%'")
|
||||
posts = Post.where(ELIGIBLE_POST_URL_CONDITION)
|
||||
posts = posts.where.not(id: theatre.current_post_id) if theatre.current_post_id
|
||||
posts
|
||||
end
|
||||
|
||||
@@ -28,6 +28,13 @@ RSpec.describe 'Theatres API', type: :request do
|
||||
)
|
||||
end
|
||||
|
||||
let!(:youtube_post) do
|
||||
Post.create!(
|
||||
title: 'youtube post',
|
||||
url: 'https://www.youtube.com/watch?v=yt123'
|
||||
)
|
||||
end
|
||||
|
||||
let!(:other_post) do
|
||||
Post.create!(
|
||||
title: 'other post',
|
||||
@@ -286,7 +293,7 @@ RSpec.describe 'Theatres API', type: :request do
|
||||
.to change { theatre.reload.current_post_id }
|
||||
|
||||
expect(response).to have_http_status(:no_content)
|
||||
expect([niconico_post.id, second_niconico_post.id])
|
||||
expect([niconico_post.id, second_niconico_post.id, youtube_post.id])
|
||||
.to include(theatre.reload.current_post_id)
|
||||
expect(theatre.reload.current_post_started_at)
|
||||
.to be_within(1.second).of(Time.current)
|
||||
@@ -294,10 +301,27 @@ RSpec.describe 'Theatres API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when only a YouTube post is eligible' do
|
||||
before do
|
||||
niconico_post.destroy!
|
||||
second_niconico_post.destroy!
|
||||
theatre.update!(host_user: member)
|
||||
sign_in_as(member)
|
||||
end
|
||||
|
||||
it 'sets current_post to the YouTube post' do
|
||||
do_request
|
||||
|
||||
expect(response).to have_http_status(:no_content)
|
||||
expect(theatre.reload.current_post_id).to eq(youtube_post.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when current user is host and no eligible post exists' do
|
||||
before do
|
||||
niconico_post.destroy!
|
||||
second_niconico_post.destroy!
|
||||
youtube_post.destroy!
|
||||
theatre.update!(
|
||||
host_user: member,
|
||||
current_post: other_post,
|
||||
|
||||
新しい課題から参照
ユーザをブロックする