Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions app/models/game_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion app/models/player_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#
class PlayerAnswer < ApplicationRecord

NO_ANSWER_ID = -1

belongs_to :answer, optional: true
belongs_to :game_player
belongs_to :game_question
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/game_player_answers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down