tournament 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 3.2.1 / 2009-03-14
2
+ * Fix teams selection controller to not care about the order of
3
+ input seedings.
4
+
1
5
  == 3.2.0 / 2009-03-14
2
6
  * Fix team selection page to not jump around when using arrow keys
3
7
  with the autocomplete pop ups.
data/lib/tournament.rb CHANGED
@@ -7,7 +7,7 @@ unless defined? Tournament
7
7
  module Tournament
8
8
 
9
9
  # :stopdoc:
10
- VERSION = '3.2.0'
10
+ VERSION = '3.2.1'
11
11
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
12
12
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
13
13
  # :startdoc:
@@ -47,24 +47,13 @@ class TeamsController < ApplicationController
47
47
  logger.debug("SAVING NEW TEAM for region #{region_idx}, seed: #{seeding_hash[:seed]}, name: #{team.name}, short: #{team.short_name}")
48
48
  team.save!
49
49
  end
50
- existing_region = @pool.region_seedings.find{|rn, rs| rn == region_name}
51
- existing_team = nil
52
- if existing_region
53
- existing_team = existing_region[1][seeding_hash[:seed].to_i - 1]
50
+ logger.debug "Finding Seeding for region #{region.name}, seed #{seeding_hash[:seed]}"
51
+ existing_seeding = @pool.seedings.find_or_create_by_region_and_seed(region.name, seeding_hash[:seed])
52
+ if existing_seeding.team_id != team.id
53
+ logger.debug " ==> TEAMS ARE DIFF, CHANGING SEEDING: #{existing_seeding.inspect}"
54
+ existing_seeding.team_id = team.id
55
+ existing_seeding.save!
54
56
  end
55
- if existing_team
56
- logger.debug "COMPARING existing team #{existing_team.inspect} with new team #{team.inspect}"
57
- if existing_team != team
58
- # Change team ...
59
- existing_seeding = @pool.seedings.find(:first, :conditions => {:team_id => existing_team.id, :region => region_name})
60
- logger.debug " ==> TEAMS ARE DIFF, CHANGING SEEDING: #{existing_seeding.inspect}"
61
- existing_seeding.team_id = team.id
62
- existing_seeding.save!
63
- end
64
- else
65
- logger.debug("SAVING NEW SEEDING for region #{region_idx}, seed: #{seeding_hash[:seed]}, team name: #{team.name}, short: #{team.short_name}, team id: #{team.id}")
66
- @pool.seedings.create(:team_id => team.id, :region => region_name, :seed => seeding_hash[:seed])
67
- end
68
57
  end
69
58
  @pool.save!
70
59
  end
@@ -50,8 +50,8 @@ Region Name: <input type="text" name="region<%=index%>[name]" value="<%=region_n
50
50
  :after_update_element => 'function(element, value) {name_id = element.id.replace("short_name", "team_name"); $(name_id).value = value.readAttribute("name")}'
51
51
  %>
52
52
  </td>
53
- </tr>
54
53
  <input type="hidden" name="region<%=index%>[seedings][][seed]" value="<%=seed_idx + 1%>">
54
+ </tr>
55
55
  <% end -%>
56
56
  </table>
57
57
  </div>
@@ -298,4 +298,37 @@ class TeamsControllerTest < ActionController::TestCase
298
298
  assert_equal 64, team_list.size, "OOPS! There should be 64 teams."
299
299
  assert_equal 64, pool.teams.size, "OOPS! There should be 64 teams."
300
300
  end
301
+
302
+ # Test that completely reording the world works
303
+ test "reorder entire region" do
304
+ input = {"id" => 1, "region0"=>{"name"=>"West",
305
+ "seedings"=>[{"name"=>"UCLA", "seed"=>"1", "short_name"=>"ULA"},
306
+ {"name"=>"Duke", "seed"=>"2", "short_name"=>"Duk"},
307
+ {"name"=>"Xavier", "seed"=>"3", "short_name"=>"Xav"},
308
+ {"name"=>"Connecticut", "seed"=>"4", "short_name"=>"Con"},
309
+ {"name"=>"Drake", "seed"=>"5", "short_name"=>"Dra"},
310
+ {"name"=>"Purdue", "seed"=>"6", "short_name"=>"Pur"},
311
+ {"name"=>"West Virginia", "seed"=>"7", "short_name"=>"WVa"},
312
+ {"name"=>"BYU", "seed"=>"8", "short_name"=>"BYU"},
313
+ {"name"=>"Texas A&M", "seed"=>"9", "short_name"=>"A&M"},
314
+ {"name"=>"Arizona", "seed"=>"10", "short_name"=>"UA"},
315
+ {"name"=>"Baylor", "seed"=>"11", "short_name"=>"Bay"},
316
+ {"name"=>"W. Kentucky", "seed"=>"12", "short_name"=>"WKy"},
317
+ {"name"=>"San Diego", "seed"=>"13", "short_name"=>"SD"},
318
+ {"name"=>"Georgia", "seed"=>"14", "short_name"=>"UG"},
319
+ {"name"=>"Belmont", "seed"=>"15", "short_name"=>"Bel"},
320
+ {"name"=>"Mis. Valley St", "seed"=>"16", "short_name"=>"MVS"}]}}
321
+ login_as :admin
322
+ post :change, input
323
+ pool = Pool.find(1)
324
+ assert_equal 16, pool.region_seedings[0][1].uniq.size, "OOPS! There are dupe teams in region 0 teams list"
325
+ assert_equal input["region0"]["seedings"].map {|h| h["short_name"]}, pool.region_seedings[0][1].uniq.map{|t| t.short_name}, "Teams are out of order or otherwise not equal"
326
+
327
+ input["region0"]["seedings"] = input["region0"]["seedings"].sort_by { rand }
328
+ input["region0"]["seedings"].each_with_index {|s, idx| s["seed"] = idx + 1}
329
+ post :change, input
330
+ pool = Pool.find(1)
331
+ assert_equal 16, pool.region_seedings[0][1].uniq.size, "OOPS! There are dupe teams in region 0 teams list"
332
+ assert_equal input["region0"]["seedings"].map {|h| h["short_name"]}, pool.region_seedings[0][1].uniq.map{|t| t.short_name}, "Teams are out of order or otherwise not equal"
333
+ end
301
334
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 2
8
- - 0
9
- version: 3.2.0
8
+ - 1
9
+ version: 3.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Douglas A. Seifert