contributers test

This commit is contained in:
Andrew Tomaka 2015-04-28 10:26:23 -04:00
parent 3cc029a7af
commit c78ff9039a
3 changed files with 8 additions and 0 deletions

1
app.rb
View file

@ -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

View file

@ -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

View file

@ -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 %>