From c78ff9039ad008835583ab965349ceb0b669e104 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 28 Apr 2015 10:26:23 -0400 Subject: [PATCH] contributers test --- app.rb | 1 + models/raid.rb | 4 ++++ views/bossfight.erb | 3 +++ 3 files changed, 8 insertions(+) diff --git a/app.rb b/app.rb index c20d5fb..bc05664 100644 --- a/app.rb +++ b/app.rb @@ -36,6 +36,7 @@ get '/bossfight/?:username' do user_raids = Raid.for_user(@username) @first_negative = user_raids.first_negative @soldiers_lost_to_date = user_raids.soldiers_lost_to_date(@first_negative.created_at) + @contributers = user_raids.contributors(@first_negative.created_at) erb :bossfight end diff --git a/models/raid.rb b/models/raid.rb index a57ab7c..545ce10 100644 --- a/models/raid.rb +++ b/models/raid.rb @@ -20,4 +20,8 @@ class Raid < ActiveRecord::Base def self.soldiers_lost_to_date(date) where('created_at < ?', date).sum(:soldiers) end + + def self.contributers(date) + where('created_at < ?', date).group(:attacker).sum(:soldiers) + end end diff --git a/views/bossfight.erb b/views/bossfight.erb index 105cd3e..e68eef8 100644 --- a/views/bossfight.erb +++ b/views/bossfight.erb @@ -7,3 +7,6 @@ <% if @soldiers_lost_to_date %> Soliders killed before walls broken: <%= readable_number(@soldiers_lost_to_date) %> <% end %> + +<% require 'pp' %> +<% pp @contributers %>