Skip to content
Browse files

actually writing data files; added test data files

  • Loading branch information...
1 parent 09b34bf commit eb043938b08f27de6b6170e3ed7c437370802e6d @jrsacks committed Jan 22, 2012
Showing with 22 additions and 11 deletions.
  1. +1 −0 data/players.json
  2. +1 −0 data/teams.json
  3. +6 −2 lib/fantasyMarchMadness.rb
  4. +3 −3 lib/scoreboard.rb
  5. +11 −6 spec/scoreboard_spec.rb
View
1 data/players.json
@@ -0,0 +1 @@
+{"88689":{"name":"Eso Akunne","team":"Michigan Wolverines","points":{},"alive":true},"88690":{"name":"Josh Bartelstein","team":"Michigan Wolverines","points":{},"alive":true},"110140":{"name":"Max Bielfeldt","team":"Michigan Wolverines","points":{},"alive":true},"110137":{"name":"Carlton Brundidge","team":"Michigan Wolverines","points":{},"alive":true},"110138":{"name":"Trey Burke","team":"Michigan Wolverines","points":{"201201170357":20},"alive":true},"97335":{"name":"Colton Christian","team":"Michigan Wolverines","points":{},"alive":true},"81997":{"name":"Stu Douglass","team":"Michigan Wolverines","points":{"201201170357":9},"alive":true},"88286":{"name":"Jordan Dumars","team":"Michigan Wolverines","points":{},"alive":true},"97332":{"name":"Tim Hardaway Jr.","team":"Michigan Wolverines","points":{"201201170357":10},"alive":true},"97333":{"name":"Jon Horford","team":"Michigan Wolverines","points":{},"alive":true},"88691":{"name":"Blake McLimans","team":"Michigan Wolverines","points":{"201201170357":0},"alive":true},"88692":{"name":"Jordan Morgan","team":"Michigan Wolverines","points":{"201201170357":4},"alive":true},"81998":{"name":"Zack Novak","team":"Michigan Wolverines","points":{"201201170357":10},"alive":true},"84239":{"name":"Corey Person","team":"Michigan Wolverines","points":{},"alive":true},"97334":{"name":"Evan Smotrycz","team":"Michigan Wolverines","points":{"201201170357":5},"alive":true},"110139":{"name":"Sai Tummala","team":"Michigan Wolverines","points":{},"alive":true},"88694":{"name":"Matt Vogrich","team":"Michigan Wolverines","points":{"201201170357":2},"alive":true},"110405":{"name":"Dwaun Anderson","team":"Michigan State Spartans","points":{},"alive":true},"97678":{"name":"Keith Appling","team":"Michigan State Spartans","points":{"201201170357":10},"alive":false},"97679":{"name":"Russell Byrd","team":"Michigan State Spartans","points":{},"alive":true},"101812":{"name":"Dan Chapman","team":"Michigan State Spartans","points":{},"alive":true},"110403":{"name":"Branden Dawson","team":"Michigan State Spartans","points":{"201201170357":4},"alive":false},"97680":{"name":"Alex Gauna","team":"Michigan State Spartans","points":{},"alive":true},"82020":{"name":"Draymond Green","team":"Michigan State Spartans","points":{"201201170357":7},"alive":false},"89779":{"name":"Anthony Ianni","team":"Michigan State Spartans","points":{},"alive":true},"110402":{"name":"Brandan Kearney","team":"Michigan State Spartans","points":{"201201170357":6},"alive":false},"88942":{"name":"Derrick Nix","team":"Michigan State Spartans","points":{"201201170357":13},"alive":false},"97677":{"name":"Adreian Payne","team":"Michigan State Spartans","points":{"201201170357":4},"alive":false},"82019":{"name":"Delvon Roe","team":"Michigan State Spartans","points":{},"alive":true},"114558":{"name":"Joe Sweeny","team":"Michigan State Spartans","points":{},"alive":true},"73151":{"name":"Austin Thornton","team":"Michigan State Spartans","points":{"201201170357":8},"alive":false},"110404":{"name":"Travis Trice","team":"Michigan State Spartans","points":{"201201170357":3},"alive":false},"111571":{"name":"Keenan Wetzel","team":"Michigan State Spartans","points":{},"alive":true},"114559":{"name":"Colby Wollenman","team":"Michigan State Spartans","points":{},"alive":true},"73120":{"name":"Brandon Wood","team":"Michigan State Spartans","points":{"201201170357":4},"alive":false}}
View
1 data/teams.json
@@ -0,0 +1 @@
+[{"id":1,"team":"Jeff's Team","players":["88692"]}]
View
8 lib/fantasyMarchMadness.rb
@@ -17,7 +17,9 @@
end
get '/game/:id' do |id|
- settings.importer.game(id).to_json
+ game = settings.importer.game(id)
+ settings.scoreboard.update_game(id, game)
+ game.to_json
end
get '/date/:id' do |id|
@@ -29,5 +31,7 @@
end
get '/players/:id' do |id|
- settings.importer.players_on_team(id).to_json
+ players = settings.importer.players_on_team(id)
+ settings.scoreboard.add_players players
+ players.to_json
end
View
6 lib/scoreboard.rb
@@ -25,15 +25,15 @@ def new_team(team_data)
team_data["id"] = new_id
@teams << team_data
end
- File.open(@team_file).puts @teams.to_json
+ File.open(@team_file, 'w') { |f| f.puts @teams.to_json }
end
def add_players(new_players)
new_players.each do |player|
full_player_info = {player[:id] => {"name" => player[:name], "team" => player[:team], "points" => {}, "alive" => true}}
@players.merge! full_player_info
end
- File.open(@player_file).puts @players.to_json
+ File.open(@player_file, 'w') { |f| f.puts @players.to_json }
end
def new_id
@@ -64,6 +64,6 @@ def update_game(game_id, box_score)
box_score[:players].each do |player|
@players[player[:id]]["points"].merge!({game_id => player[:points]})
end
- File.open(@player_file).puts @players.to_json
+ File.open(@player_file, 'w') { |f| f.puts @players.to_json }
end
end
View
17 spec/scoreboard_spec.rb
@@ -38,7 +38,7 @@
new_team = {"team" => "new team", "players" => []}
new_team_with_id = new_team.merge({"id" => 2})
both_teams = teams << (new_team_with_id)
- File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'teams.json'))).and_return teams_file
+ File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'teams.json')), 'w').and_yield teams_file
teams_file.should_receive(:puts).with both_teams.to_json
scoreboard.new_team new_team
end
@@ -48,24 +48,29 @@
team["team"] = "changed name"
updated_team = team
- File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'teams.json'))).and_return teams_file
+ File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'teams.json')), 'w').and_yield teams_file
teams_file.should_receive(:puts).with [updated_team].to_json
scoreboard.new_team updated_team
end
it "can add a players" do
new_players = [{:id => "12346", :name => "Eso Akunne", :team => "Michigan Wolverines"}]
updated_players = players.merge({"12346" => {:name => "Eso Akunne", :team => "Michigan Wolverines", :points => {}, :alive => true}})
- File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'players.json'))).and_return players_file
+ File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'players.json')), 'w').and_yield players_file
players_file.should_receive(:puts).with updated_players.to_json
scoreboard.add_players new_players
end
describe "updating a game" do
- before(:each) do
+ def add_player(info)
players_file.stub(:puts)
- scoreboard.add_players [{:id => "12346", :name => "D Rose", :team => "Memphis Tigers"}]
- File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'players.json'))).and_return players_file
+ File.stub(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'players.json')), 'w').and_yield players_file
+ scoreboard.add_players info
+ end
+
+ before(:each) do
+ add_player [{:id => "12346", :name => "D Rose", :team => "Memphis Tigers"}]
+ File.should_receive(:open).with(File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'players.json')), 'w').and_yield players_file
end
after(:each) do

0 comments on commit eb04393

Please sign in to comment.
Something went wrong with that request. Please try again.