Skip to content

Add ending time to challenges #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
10 changes: 9 additions & 1 deletion app/models/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ def challenge_open?
state.eql? 'open'
end

def before_close?
unless challenge_end.nil?
time = Time.now.utc
return time < challenge_end
end
true
end

def open?
challenge_open? && game.open?
challenge_open? && before_close? && game.open?
end

def display_point_value(_ = nil)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200624162213_add_challenge_end_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddChallengeEndTime < ActiveRecord::Migration[6.0]
def change
add_column :challenges, :challenge_end, :datetime
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_06_23_173255) do
ActiveRecord::Schema.define(version: 2020_06_24_162213) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -48,6 +48,7 @@
t.integer "solved_decrement_period", default: 1
t.boolean "design_phase", default: false
t.bigint "game_id"
t.datetime "challenge_end"
t.boolean "sponsored", default: false, null: false
t.text "sponsor", default: ''
t.text "sponsor_logo", default: '', null: false
Expand Down
7 changes: 7 additions & 0 deletions test/models/challenge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ class ChallengeTest < ActiveSupport::TestCase
assert_equal chal2, chal1.next_challenge
assert_nil chal3.next_challenge
end

test 'game is closed when its passed closing time' do
game = create(:active_game)
challenge = create(:standard_challenge, challenge_end: Time.current - 1.days)

assert_not challenge.before_close?
end
end