Skip to content

complite task timer#38

Open
PavelPo99 wants to merge 5 commits intobadgefrom
timer
Open

complite task timer#38
PavelPo99 wants to merge 5 commits intobadgefrom
timer

Conversation

@PavelPo99
Copy link
Owner

No description provided.

class TestPassagesController < ApplicationController
before_action :authenticate_user!
before_action :set_test_passage, only: %i[ show result update ]
before_action :check_timer, only: [ :update ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять с отступами м/у скобок бардак. Используй рубокоп.


def check_timer
@test_passage = TestPassage.find(params[:id])
if @test_passage.time_over?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверка времени это часть бизнес логики. Размазывать эту логику м/у контроллером и моделью плохая идея. Тем более уже есть метод отвечающий за завершение теста. Стоит доработать его.


const redirectUrl = timerElement.dataset.timeoutUrl;
if (redirectUrl && redirectUrl !== 'undefined') {
window.location.href = redirectUrl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут правильней и проще будет просто сабмитеть форму.

created_at + (test.timer * 60) if test.timer.present?
end
def remaining_time
return unless timer_enabled?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже хочеться рубокоп запустить

flash[:alert] = t("test_passages.times_up")

redirect_to result_test_passage_path(@test_passage)
elsif @test_passage.question_any?(params)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если нет вопросов, значит тест завершился. А для этого есть уже подходящий метод #completed? который просто должен отвечать завершился ли тест. И не важно закончились вопросы и время. А сейчас получается что логику завершения теста не много размазали по коду


if @test_passage.time_over?
flash[:alert] = t("test_passages.times_up")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

внутри if код разделяют отступами

if @test_passage.time_over?
  flash[:alert] = t("test_passages.times_up")
elsif
  @test_pass...
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants