Skip to content

Commit

Permalink
add create trophies method
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Dec 9, 2024
1 parent f031638 commit 31a7244
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/models/shrimpo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ def voting_completion user
((voted_count.to_f / total_count.to_f) * 100).round(2)
end

def create_category_trophies!
self.shrimpo_voting_categories.each do |category|
gold = Trophy.create! name: "gold #{category.name}"
silver = Trophy.create! name: "silver #{category.name}"
bronze = Trophy.create! name: "bronze #{category.name}"
category.update! gold_trophy: gold, silver_trophy: silver, bronze_trophy: bronze
end
end

private
def start_at_cannot_be_in_the_past
if start_at < Time.current
Expand Down
7 changes: 3 additions & 4 deletions spec/models/shrimpo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@
dj4 = User.create! role: 'dj', username: 'djgoodbye', email: "[email protected]", password: "2boobies", time_zone: "UTC"
shrimpo = Shrimpo.new start_at: @start_at, duration: "3 months", title: "Shrimp Champions 2000 mega", rule_pack: "dont use pokemon samples", user: dj1, emoji: ":bgs:", shrimpo_type: :mega, gold_trophy: gold_trophy, silver_trophy: silver_trophy, bronze_trophy: bronze_trophy, consolation_trophy: consolation_trophy
shrimpo.save_and_deposit_fruit_tickets!

categories.each do |category|
gold = Trophy.create! name: "gold #{category}"
silver = Trophy.create! name: "silver #{category}"
bronze = Trophy.create! name: "bronze #{category}"
ShrimpoVotingCategory.create! shrimpo: shrimpo, name: category, emoji: ":#{category}:", gold_trophy: gold, silver_trophy: silver, bronze_trophy: bronze
ShrimpoVotingCategory.create! shrimpo: shrimpo, name: category, emoji: ":#{category}:"
end
shrimpo.create_category_trophies!

entry1 = shrimpo.shrimpo_entries.create! title: "zolo zoodo", user: dj1
entry2 = shrimpo.shrimpo_entries.create! title: "mega banger 4000", user: dj2
Expand Down

0 comments on commit 31a7244

Please sign in to comment.