Skip to content

Commit

Permalink
ClanScoreHistory should be created on value changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaak committed Jun 10, 2015
1 parent a3d4d7a commit 6e23aeb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/junethack/trophy_calculations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ def history_clans
ClanScoreEntry.all.each {|e|
h = ClanScoreHistory.first(:trophy => e.trophy, :clan_name => e.clan_name, :order => :created_at.desc)
# only record when points or rank has changed
if not h or h.points != e.points or h.rank != e.rank
c = ClanScoreHistory.create(e.attributes)
if not h or h.points != e.points or h.rank != e.rank or h.value != e.value
ClanScoreHistory.create(e.attributes)
end
}
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

def clean_database
ClanScoreEntry.destroy!
ClanScoreHistory.destroy!
Individualtrophy.destroy!
Scoreentry.destroy!
NormalizedDeath.destroy!
Expand Down
15 changes: 15 additions & 0 deletions spec/unittests/trophies_achievements/clan_scores_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ def update_games
ClanScoreEntry.first(:trophy => :most_medusa_kills).value.should == 1
ClanScoreHistory.all(:trophy => :most_medusa_kills).count.should == 1
end

it "creates clan score history entries if the value of the trophy changes" do
attributes = { version: 'v1', server_id: 1, achieve: "0x800", points: 9000, endtime: 1000, death: 'ascended', turns: 1023 }
Game.create(attributes)
update_games
ClanScoreEntry.first(:trophy => :most_medusa_kills).value.should == 1
ClanScoreHistory.all(:trophy => :most_medusa_kills).count.should == 1

Game.create(attributes)
update_games

ClanScoreEntry.first(:trophy => :most_medusa_kills).value.should == 2
ClanScoreHistory.all(:trophy => :most_medusa_kills).count.should == 2
ClanScoreHistory.all(:trophy => :most_medusa_kills).map(&:value).sort == [1, 2]
end
end

0 comments on commit 6e23aeb

Please sign in to comment.