Skip to content

Commit

Permalink
More testing, all releasable.
Browse files Browse the repository at this point in the history
  • Loading branch information
leanucci committed Oct 11, 2008
1 parent a4a38f7 commit 70611b7
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/models/tournament.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Tournament < ActiveRecord::Base

has_many :participations
has_many :participations, :dependent => :destroy
has_many :teams, :through => :participations
has_many :standings, :dependent => :destroy, :order => "scheduled_date"

Expand Down
6 changes: 3 additions & 3 deletions public/stylesheets/fpt.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ a:link, a:visited {color: #7D7D7D; text-decoration: none;}
margin: 0;
padding: 5px;
border: 2px solid #8B2B23;
width: 200px;
width: 175px;
float: left;
min-height: 266px;
}

#included {
margin-left: 10px;
width: 756px;
width: 676px;
float: left;
}
#teamslist {
Expand All @@ -190,7 +190,7 @@ a:link, a:visited {color: #7D7D7D; text-decoration: none;}
}
#eliminator {
text-align: center;
width: 752px;
width: 672px;
color: grey;
float: left;
height: 100px;
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/participations.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#one:
# id:
# team_id:
# tournament_id:
one:
id: 1
team_id: 1
tournament_id: 1
5 changes: 5 additions & 0 deletions test/fixtures/slugs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ river:
name: river
sluggable_type: Team
sluggable_id: 13

argentinos:
name: argentinos-jrs
sluggable_type: Team
sluggable_id: 1
27 changes: 24 additions & 3 deletions test/functional/teams_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,35 @@ class TeamsControllerTest < ActionController::TestCase
end

context "On PUT to :update" do
setup {@team = teams(:river)}
setup {@river = teams(:river)}
context "with valid data" do
setup {put :update, :id => @team.to_param, :team => {:short_name => "River"}}
setup {put :update, :id => @river.to_param, :team => {:short_name => "River"}}
should_set_the_flash_to /Saved/
should_redirect_to "teams_url"
should_assign_to :team
should "change the record" do
assert_equal Team.find(@team.to_param).short_name, "River"
assert assigns(:team).valid?
assert_equal Team.find(@river.to_param).short_name, "River"
end
end

context "with invalid data" do
setup {put :update, :id => @river.to_param, :team => {:short_name => nil}}
should_not_set_the_flash
should_respond_with :success
should_render_template :edit
should_assign_to :team
should "not change the record" do
deny assigns(:team).valid?
assert_equal Team.find(@river.to_param).short_name, "river plate"
end
end
end

context "On DELETE to :destroy" do
setup {delete :destroy, :id => teams(:river).to_param}
should_change "Team.count", :by => -1
should_set_the_flash_to /kaboom/
should_redirect_to "teams_url"
end
end
189 changes: 124 additions & 65 deletions test/functional/tournaments_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,150 @@
require File.dirname(__FILE__) + '/../test_helper'
class TournamentsControllerTest < ActionController::TestCase
fixtures :tournaments, :standings, :matches, :teams, :slugs
fixtures :tournaments, :standings, :matches, :teams, :slugs, :participations

context "On GET to :index" do
setup do
get :index
context "An existing tournament" do
setup do
@apertura = tournaments(:apertura07)
end
context "On GET to :show" do
setup do
get :show, :id => @apertura.to_param
end
should_respond_with :success
should_assign_to :tournament
should_assign_to :teams
end
should_respond_with :success
should_assign_to :tournaments
end

context "On GET to :show" do
setup do
@tournament = tournaments(:apertura07)
get :show, :id => @tournament.to_param
context "On GET to :edit" do
setup do
get :edit, :id => @apertura.to_param
end
should_assign_to :tournament
should_respond_with :success
should_render_a_form
end

context "On PUT to :update" do
context "with valid data" do
setup do
put :update, :id => @apertura.to_param,
:tournament => {:start_date => "2007-08-06"}
end
should_set_the_flash_to /Saved/
should_redirect_to "tournaments_url"
should_assign_to :tournament
should "change the record" do
assert assigns(:tournament).valid?
assert_equal Tournament.find(@apertura.to_param).start_date.to_s, "2007-08-06"
end
end
context "with invalid data" do
setup do
put :update, :id => @apertura.to_param,
:tournament => {:start_date => "2006-01-01"}
end
should_assign_to :tournament
should_not_set_the_flash
should_render_template :edit
should_not_change "@apertura.start_date"
end
end

context "On DELETE to :destroy" do
setup do
delete :destroy, :id => @apertura.to_param
end
should_assign_to :tournament
should_redirect_to "tournaments_path"
should_set_the_flash_to /kaboom/
should_change "Tournament.count", :by => -1
should "delete the tournament and its associates" do
assert Participation.find_by_tournament_id(@apertura.to_param).nil?
end
end

context "On GET to :edit_teams" do
setup do
get :edit_teams, :id => @apertura.to_param
end
should_assign_to :tournament
should_assign_to :teams
should_assign_to :excluded
should_assign_to :included
should_respond_with :success

should "fetch right collection of teams" do
assert_equal assigns(:teams).size, Team.count
assert_equal assigns(:included).size, assigns(:tournament).teams.size
assert_equal assigns(:excluded).size, assigns(:teams).size - assigns(:tournament).teams.size
end
end

context "On PUT to :push_team" do
context "to an incomplete tournament" do
setup do
put :push_team, :id => @apertura.to_param, :team => teams(:river).to_param
end
should_assign_to :team, :tournament
should_change "@apertura.teams.count", :by => 1
should "remove the team from excluded and move it to included" do
assert_select_rjs :remove, "team_#{teams(:river).to_param}"
assert_select_rjs :replace_html, "teamslist" do
assert_select "DIV#team_#{teams(:river).to_param}.excluded_teams", false
assert_select "DIV#team_#{teams(:river).to_param}.competitors"
end
end
end
context "to a complete tournament" do
setup do
@apertura.teams << Team.find(:all, :limit => 19, :offset => 1)
put :push_team, :id => @apertura.to_param, :team => Team.last.to_param
end
should_assign_to :team, :tournament
should_not_change "@apertura.teams"
should "set the notice" do
assert_select_rjs :replace_html, "notice"
assert_select_rjs :show, "team_#{assigns(:team).to_param}"
end
end
end

context "On PUT to :remove_team" do
setup do
put :remove_team, :id => @apertura.to_param, :team => teams(:argentinos).to_param
end
should_assign_to :team, :tournament
should_change "@apertura.teams.count", :by => -1
should "remove the team from included and move it to excluded" do
assert_select_rjs :replace_html, "excluded" do
assert_select "DIV#team_#{teams(:argentinos).to_param}.competitors", false
assert_select "DIV#team_#{teams(:argentinos).to_param}.excluded_teams"
end
end
end
should_respond_with :success
should_assign_to :tournament
should_assign_to :teams
end

context "On GET to :edit" do
setup do
@tournament = tournaments(:apertura07)
get :edit, :id => @tournament.to_param
context "On GET to :index" do
setup do
get :index
end
should_assign_to :tournament
should_respond_with :success
should_render_a_form
should_assign_to :tournaments
end

context "On GET to :new" do
setup do
get :new
end

should_assign_to :tournament
should_render_a_form
should_respond_with :success

should "assign to new tournament" do
assert assigns(:tournament).new_record?
end
end

context "On POST to :create" do
setup do
@old_count = Tournament.count
end

context "with a valid tournament" do
setup do
post :create, :tournament => {:t_type => 1,
Expand All @@ -59,11 +155,8 @@ class TournamentsControllerTest < ActionController::TestCase
should_redirect_to "tournaments_path"
should_assign_to :tournament
should_set_the_flash_to /successfully/
should "actually create the tournament" do
assert_equal @old_count + 1, Tournament.count
end
should_change "Tournament.count", :by => 1
end

context "with an invalid tournament" do
setup do
post :create, :tournament => {:t_type => 1,
Expand All @@ -74,41 +167,7 @@ class TournamentsControllerTest < ActionController::TestCase
should_redirect_to "new_tournament_path"
should_assign_to :tournament
should_set_the_flash_to /foobar/
should "not create the tournament" do
assert_equal @old_count, Tournament.count
end
end
end

context "On DELETE to :destroy" do
setup do
@tournament = tournaments(:apertura07)
@old_count = Tournament.count
delete :destroy, :id => @tournament.to_param
end
should_assign_to :tournament
should_redirect_to "tournaments_path"
should_set_the_flash_to /kaboom/
should "actually delete the tournament" do
assert_equal @old_count - 1, Tournament.count
end
end

context "On GET to :edit_teams" do
setup do
@tournament = tournaments(:apertura07)
get :edit_teams, :id => @tournament.to_param
end
should_assign_to :tournament
should_assign_to :teams
should_assign_to :excluded
should_assign_to :included
should_respond_with :success

should "fetch right collection of teams" do
assert_equal assigns(:teams).size, Team.count
assert_equal assigns(:included).size, assigns(:tournament).teams.size
assert_equal assigns(:excluded).size, assigns(:teams).size - assigns(:tournament).teams.size
should_not_change "Tournament.count"
end
end
end

0 comments on commit 70611b7

Please sign in to comment.