Reviewed-on: #377 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #377 でマージされました.
このコミットが含まれているのは:
@@ -206,6 +206,40 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
expect(example.gekanator_game_id).to eq(json['id'])
|
||||
end
|
||||
|
||||
it 'learns accepted post_similarity answers from main game logs' do
|
||||
sign_in_as admin
|
||||
|
||||
question = create_post_similarity_question!(text: '泣いてる?')
|
||||
|
||||
expect {
|
||||
post '/gekanator/games', params: {
|
||||
guessed_post_id: guessed_post.id,
|
||||
correct_post_id: correct_post.id,
|
||||
answers: [
|
||||
{
|
||||
question_id: "post-similarity:#{question.id}",
|
||||
question_text: '泣いてる?',
|
||||
answer: 'partial',
|
||||
original_answer: 'partial'
|
||||
}
|
||||
]
|
||||
}
|
||||
}.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: question.id,
|
||||
post_id: correct_post.id,
|
||||
user_id: admin.id,
|
||||
answer: 'partial',
|
||||
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
|
||||
|
||||
@@ -475,28 +509,59 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
end
|
||||
|
||||
describe 'GET /gekanator/games/:id/extra_questions' do
|
||||
it 'returns at most two accepted user_suggested post_similarity questions without duplicates' do
|
||||
it 'returns at most six accepted user_suggested post_similarity questions without duplicates' do
|
||||
sign_in_as admin
|
||||
|
||||
lowest = create_post_similarity_question!(
|
||||
text: 'lowest?',
|
||||
priority_weight: 0.5
|
||||
)
|
||||
low = create_post_similarity_question!(
|
||||
text: 'low?',
|
||||
priority_weight: 1.0
|
||||
)
|
||||
high = create_post_similarity_question!(
|
||||
text: 'high?',
|
||||
priority_weight: 3.0
|
||||
)
|
||||
middle = create_post_similarity_question!(
|
||||
text: 'middle?',
|
||||
priority_weight: 1.5
|
||||
)
|
||||
medium_high = create_post_similarity_question!(
|
||||
text: 'medium high?',
|
||||
priority_weight: 2.0
|
||||
)
|
||||
high = create_post_similarity_question!(
|
||||
text: 'high?',
|
||||
priority_weight: 2.5
|
||||
)
|
||||
higher = create_post_similarity_question!(
|
||||
text: 'higher?',
|
||||
priority_weight: 2.8
|
||||
)
|
||||
highest = create_post_similarity_question!(
|
||||
text: 'highest?',
|
||||
priority_weight: 3.0
|
||||
)
|
||||
overflow = create_post_similarity_question!(
|
||||
text: 'overflow?',
|
||||
priority_weight: 2.2
|
||||
)
|
||||
|
||||
get "/gekanator/games/#{game.id}/extra_questions"
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json['questions'].length).to eq(2)
|
||||
expect(json['questions'].map { _1['id'] }.uniq.length).to eq(2)
|
||||
expect(json['questions'].map { _1['id'] }).to all(be_in([low.id, high.id, middle.id]))
|
||||
expect(json['questions'].length).to eq(6)
|
||||
expect(json['questions'].map { _1['id'] }.uniq.length).to eq(6)
|
||||
expect(json['questions'].map { _1['id'] }).to all(
|
||||
be_in([
|
||||
lowest.id,
|
||||
low.id,
|
||||
middle.id,
|
||||
medium_high.id,
|
||||
high.id,
|
||||
higher.id,
|
||||
highest.id,
|
||||
overflow.id,
|
||||
])
|
||||
)
|
||||
end
|
||||
|
||||
it 'can return questions that already have an example for the correct post' do
|
||||
@@ -519,6 +584,37 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
expect(json['questions'].map { _1['id'] }).to include(existing.id)
|
||||
end
|
||||
|
||||
it 'prioritizes questions the current user has not answered' do
|
||||
sign_in_as admin
|
||||
|
||||
answered = create_post_similarity_question!(
|
||||
text: 'already answered?',
|
||||
priority_weight: 3.0
|
||||
)
|
||||
GekanatorQuestionExample.create!(
|
||||
gekanator_question: answered,
|
||||
post: other_post,
|
||||
user: admin,
|
||||
answer: 'yes',
|
||||
source: 'post_game_extra'
|
||||
)
|
||||
|
||||
unanswered =
|
||||
6.times.map { |index|
|
||||
create_post_similarity_question!(
|
||||
text: "unanswered #{index}?",
|
||||
priority_weight: 0.5
|
||||
)
|
||||
}
|
||||
|
||||
get "/gekanator/games/#{game.id}/extra_questions"
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json['questions'].map { _1['id'] }).to match_array(
|
||||
unanswered.map(&:id)
|
||||
)
|
||||
end
|
||||
|
||||
it 'can return questions already asked in the game using snake_case question_id' do
|
||||
sign_in_as admin
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする