From 6aee4143fb6b4765c9b155c6703e2c7a956c6ff2 Mon Sep 17 00:00:00 2001 From: Georgi Ganchev Date: Wed, 26 Nov 2025 09:32:18 +0000 Subject: [PATCH 1/2] fix: failing CI --- app/models/game_question.rb | 5 +++-- app/models/player_answer.rb | 4 +++- test/controllers/game_player_answers_controller_test.rb | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/game_question.rb b/app/models/game_question.rb index 36ffc52..8cda4fc 100644 --- a/app/models/game_question.rb +++ b/app/models/game_question.rb @@ -52,13 +52,14 @@ def reward_players_if_completed all_players.find_each do |player| current_question_answer = player.player_answers.find_by(game_question_id: id) unless current_question_answer - player.player_answers.create(game_question: self, answer_id: -1, correct: false) + # player did not answer + player.player_answers.create!(game_question: self, answer_id: PlayerAnswer::NO_ANSWER_ID, correct: false) end if current_question_answer&.correct player.award_points!(question.points, current_question_answer.time_taken) else - player.update(current_streak: 0) + player.update!(current_streak: 0) end end diff --git a/app/models/player_answer.rb b/app/models/player_answer.rb index 743f4c2..e6cc2aa 100644 --- a/app/models/player_answer.rb +++ b/app/models/player_answer.rb @@ -21,6 +21,8 @@ # class PlayerAnswer < ApplicationRecord + NO_ANSWER_ID = -1 + belongs_to :answer, optional: true belongs_to :game_player belongs_to :game_question @@ -30,7 +32,7 @@ class PlayerAnswer < ApplicationRecord private def not_created_or_updated_after_game_question_completed - return unless game_question.completed? + return if !game_question.completed? || answer_id == NO_ANSWER_ID errors.add(:base, "cannot set or change answer after question completed") end diff --git a/test/controllers/game_player_answers_controller_test.rb b/test/controllers/game_player_answers_controller_test.rb index 6d5d53d..00aac99 100644 --- a/test/controllers/game_player_answers_controller_test.rb +++ b/test/controllers/game_player_answers_controller_test.rb @@ -7,8 +7,8 @@ class GamePlayerAnswersControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:one) @game = games(:one) - @game_question = game_questions(:one) - @correct_answer = answers(:correct) + @game_question = game_questions(:two) + @correct_answer = answers(:two) @incorrect_answer = answers(:incorrect) @game_player = game_players(:one) From c52b7bfed19cb15c902381f607b72b1c583ce293 Mon Sep 17 00:00:00 2001 From: Georgi Ganchev Date: Mon, 1 Dec 2025 20:21:18 +0000 Subject: [PATCH 2/2] chore: update brakeman --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index ec3e0f4..f097d07 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,7 +113,7 @@ GEM bindex (0.8.1) bootsnap (1.18.4) msgpack (~> 1.2) - brakeman (7.0.2) + brakeman (7.1.1) racc builder (3.3.0) capybara (3.40.0)