diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 6567dfa6..aaea5d27 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -12,6 +12,7 @@ class Challenge < ApplicationRecord before_create { |challenge| challenge.flag = BCrypt::Password.create(flag) } + default_scope { order(title: :asc) } scope :active, -> { where(active: true) } class String < SimpleDelegator diff --git a/app/models/submission.rb b/app/models/submission.rb index a41047b3..58af6d1b 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -8,4 +8,6 @@ class Submission < ApplicationRecord validates :submission_hash, presence: true, uniqueness: true validates :user, :team, :challenge, :category, presence: true + + scope :valid, -> { where(valid_submission: true) } end diff --git a/app/models/team.rb b/app/models/team.rb index 54906dd7..5de0ed35 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -9,4 +9,8 @@ class Team < ApplicationRecord uniqueness: { case_sensitive: false } include Tokenable + + def solved_challenges + submissions.valid + end end diff --git a/spec/factories.rb b/spec/factories.rb index ae13e2f5..829723ee 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -27,7 +27,7 @@ end factory :category do - name { 'web' } + sequence(:name) { |n| "category-#{n}" } end factory :challenge do @@ -53,7 +53,7 @@ factory :submission do challenge - category + category { challenge.category } flag { 'flag{invalid}' } user team diff --git a/spec/models/challenge_spec.rb b/spec/models/challenge_spec.rb index d542761d..cc738761 100644 --- a/spec/models/challenge_spec.rb +++ b/spec/models/challenge_spec.rb @@ -63,4 +63,13 @@ expect(@challenge.description.to_md).to eq("