Reviewed-on: #375 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #375 でマージされました.
このコミットが含まれているのは:
@@ -151,6 +151,154 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it 'learns accepted non-nico tag answers from camelCase main game logs' do
|
||||
sign_in_as admin
|
||||
|
||||
tag_question = GekanatorQuestion.create!(
|
||||
text: 'MAD 要素がある?',
|
||||
kind: 'tag',
|
||||
source: 'admin_curated',
|
||||
status: 'accepted',
|
||||
priority_weight: 1.0,
|
||||
condition: { type: 'tag', key: 'meme:MAD' },
|
||||
created_by: admin
|
||||
)
|
||||
|
||||
expect {
|
||||
post '/gekanator/games', params: {
|
||||
guessed_post_id: guessed_post.id,
|
||||
correct_post_id: correct_post.id,
|
||||
answers: [
|
||||
{
|
||||
questionId: 'tag:meme:MAD',
|
||||
question_text: 'MAD 要素がある?',
|
||||
answer: 'yes',
|
||||
original_answer: 'yes'
|
||||
},
|
||||
{
|
||||
questionId: 'tag:meme:missing',
|
||||
question_text: '存在しない質問?',
|
||||
answer: 'yes',
|
||||
original_answer: 'yes'
|
||||
},
|
||||
{
|
||||
questionId: 'tag:meme:MAD',
|
||||
question_text: 'MAD 要素がある?',
|
||||
answer: 'unknown',
|
||||
original_answer: 'unknown'
|
||||
}
|
||||
]
|
||||
}
|
||||
}.to change { GekanatorQuestionExample.count }.by(1)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(json['learned_example_count']).to eq(1)
|
||||
|
||||
example = GekanatorQuestionExample.last
|
||||
expect(example).to have_attributes(
|
||||
gekanator_question_id: tag_question.id,
|
||||
post_id: correct_post.id,
|
||||
user_id: admin.id,
|
||||
answer: 'yes',
|
||||
source: 'post_game_answer'
|
||||
)
|
||||
expect(example.gekanator_game_id).to eq(json['id'])
|
||||
end
|
||||
|
||||
it 'does not learn fact questions or nico tag questions from main game logs' do
|
||||
sign_in_as admin
|
||||
|
||||
[
|
||||
{
|
||||
text: 'example.com 由来?',
|
||||
kind: 'source',
|
||||
condition: { type: 'source', host: 'example.com' }
|
||||
},
|
||||
{
|
||||
text: '題名に結束バンドを含む?',
|
||||
kind: 'title',
|
||||
condition: { type: 'title-contains', text: '結束バンド' }
|
||||
},
|
||||
{
|
||||
text: '2024 年投稿?',
|
||||
kind: 'original_date',
|
||||
condition: { type: 'original-year', year: 2024 }
|
||||
},
|
||||
{
|
||||
text: 'ニコニコにぼっちタグ?',
|
||||
kind: 'tag',
|
||||
condition: { type: 'tag', key: 'nico:ぼっち' }
|
||||
}
|
||||
].each do |attributes|
|
||||
GekanatorQuestion.create!(
|
||||
text: attributes[:text],
|
||||
kind: attributes[:kind],
|
||||
source: 'admin_curated',
|
||||
status: 'accepted',
|
||||
priority_weight: 1.0,
|
||||
condition: attributes[:condition],
|
||||
created_by: admin
|
||||
)
|
||||
end
|
||||
|
||||
expect {
|
||||
post '/gekanator/games', params: {
|
||||
guessed_post_id: guessed_post.id,
|
||||
correct_post_id: correct_post.id,
|
||||
answers: [
|
||||
{ question_id: 'source:example.com', answer: 'yes' },
|
||||
{ question_id: 'title:contains:結束バンド', answer: 'yes' },
|
||||
{ question_id: 'original-year:2024', answer: 'yes' },
|
||||
{ question_id: 'tag:nico:ぼっち', answer: 'yes' }
|
||||
]
|
||||
}
|
||||
}.not_to change { GekanatorQuestionExample.count }
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(json['learned_example_count']).to eq(0)
|
||||
end
|
||||
|
||||
it 'updates an existing main game example instead of duplicating it' do
|
||||
sign_in_as admin
|
||||
|
||||
tag_question = GekanatorQuestion.create!(
|
||||
text: '喜多ちゃんが関係してる?',
|
||||
kind: 'tag',
|
||||
source: 'admin_curated',
|
||||
status: 'accepted',
|
||||
priority_weight: 1.0,
|
||||
condition: { type: 'tag', key: 'character:喜多郁代' },
|
||||
created_by: admin
|
||||
)
|
||||
existing = GekanatorQuestionExample.create!(
|
||||
gekanator_question: tag_question,
|
||||
post: correct_post,
|
||||
user: admin,
|
||||
answer: 'no',
|
||||
source: 'post_game_answer',
|
||||
weight: 1.0
|
||||
)
|
||||
|
||||
expect {
|
||||
post '/gekanator/games', params: {
|
||||
guessed_post_id: guessed_post.id,
|
||||
correct_post_id: correct_post.id,
|
||||
answers: [
|
||||
{
|
||||
question_id: 'tag:character:喜多郁代',
|
||||
answer: 'yes',
|
||||
original_answer: 'yes'
|
||||
}
|
||||
]
|
||||
}
|
||||
}.not_to change { GekanatorQuestionExample.count }
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(json['learned_example_count']).to eq(1)
|
||||
expect(existing.reload.answer).to eq('yes')
|
||||
expect(existing.sample_count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /gekanator/question_suggestions' do
|
||||
@@ -249,7 +397,7 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
expect(GekanatorQuestionSuggestion.last.processed).to eq(false)
|
||||
end
|
||||
|
||||
it 'limits suggestions to three per game' do
|
||||
it 'allows more than three suggestions per game' do
|
||||
sign_in_as admin
|
||||
|
||||
3.times do |i|
|
||||
@@ -267,9 +415,10 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
question_text: 'fourth question?',
|
||||
answer: 'yes'
|
||||
}
|
||||
}.not_to change { GekanatorQuestionSuggestion.count }
|
||||
}.to change { GekanatorQuestionSuggestion.count }.by(1)
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(json['count']).to eq(4)
|
||||
end
|
||||
|
||||
it 'allows a non-admin user to suggest a question for their own game' do
|
||||
|
||||
新しい課題から参照
ユーザをブロックする