Skip to content

Commit

Permalink
Commit 10:
Browse files Browse the repository at this point in the history
Done:

· Standings controller renders all teams or a link for teams creation if there are not enough teams in the database (tested).
· Added custom find methods for standing
· The standings created on tournament creation now have contiguous dates instead of the start date for that tournament, thus validating the uniqueness of sceduled date for a standing.
· Done some standings edit stuff


git-svn-id: http://svn2.assembla.com/svn/fs/trunk/fpt@10 d4c3aac1-5b85-48de-b3bb-3a454bd87b0a
  • Loading branch information
lmarcucci committed Feb 7, 2008
1 parent 6d66874 commit b8e7ccb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 45 deletions.
18 changes: 4 additions & 14 deletions app/controllers/standings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class StandingsController < ApplicationController

def show
@standing = Standing.find(params[:id],
:include => [ :tournament, :matches,
{ :matches => [ :home_team, :away_team ] }] )
@standing = Standing.find_with_tournament_matches_teams(params[:id])
@tournament = @standing.tournament
end

def edit
@standing = Standing.find(params[:id], :include => [ :tournament] )
@standing = Standing.find_with_tournament_matches_teams(params[:id])
@tournament = @standing.tournament
end

def update
Expand All @@ -19,13 +18,4 @@ def update
render :action => 'edit'
end
end

def destroy
if Standing.find(params[:id]).destroy
flash[:notice] = "Standing went kaboom."
else
flash[:notice] = "Something went wrong."
end
redirect_to :action => 'index'
end
end
17 changes: 11 additions & 6 deletions app/models/standing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ class Standing < ActiveRecord::Base
has_many :matches, :dependent => :destroy

validate :scheduled_date_too_early?, :scheduled_date_too_late?

validates_uniqueness_of :name, :scope => :tournament_id
validates_presence_of :tournament_id
# validates_uniqueness_of :scheduled_date
validates_uniqueness_of :scheduled_date

def self.find_by_tournament(tournament_id)
self.find(:all, :conditions => ["tournament_id = ?", tournament_id],
:include => :tournament,
:order => "standings.scheduled_date")


def self.find_with_tournament_matches_teams(id)
self.find(id, :include => [ :tournament, :matches,
{ :matches => [ :home_team, :away_team ] }],
:order => "standings.scheduled_date" )
end

def self.find_with_tournament(id)
self.find(id, :include => :tournament, :order => "standings.scheduled_date")
end


Expand Down
2 changes: 1 addition & 1 deletion app/models/tournament.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def add_standings
end
self.standings.create(
:name => fecha,
:scheduled_date => self.start_date,
:scheduled_date => self.start_date + i.days,
:tournament_id => self.id
)
end
Expand Down
1 change: 0 additions & 1 deletion app/views/layouts/futstat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
.fieldWithErrors {
padding: 2px;
background-color: red;
display: table;
}
#errorExplanation {
width: 400px;
Expand Down
39 changes: 22 additions & 17 deletions app/views/standings/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<h3>Torneo <%= get_tournament_type(@standing.tournament) %>
<%= @standing.tournament.season.year %></h3>
<%= link_to 'tournaments', tournaments_path %> &gt;
<%= link_to "#{get_tournament_type(@tournament)}" + " " +
"#{@tournament.season.year}", tournament_path(@tournament) %> &gt;
<%= @standing.name.capitalize %>:

<h3>
Torneo <%= get_tournament_type(@tournament) %>
<%= @tournament.season.year %>
</h3>

<h4><%= @standing.name.capitalize %></h4>
<h4>Partidos:</h4> <%= @standing.matches.size %>
<h4>
<%= @standing.name.capitalize %>
</h4>

<% if @standing.matches.nil? %>
<% if @standing.matches.empty? %>
<p>
There are no matches for this standing. In the future, this will redirect to
new_team_path.
Click
<%= link_to "here", edit_tournament_standing_path(@standing.tournament,
@standing) %> to edit this standing's matches.
</p>
<% else %>
<% for match in @standing.matches %>
<p>
<%= match.home_team.short_name %>
<%= match.home_team_score %> vs <%= match.away_team_score %>
<%= match.away_team.short_name %>
(<%= match.played_date.to_formatted_s(:rfc822) %>)
</p>
<p>
<%= match.home_team.short_name %>
<%= match.home_team_score %> vs <%= match.away_team_score %>
<%= match.away_team.short_name %>
(<%= match.played_date.to_formatted_s(:rfc822) %>)
</p>
<% end %>
<% end %>

<%= link_to 'tournaments', tournaments_path %> &gt;
<%= link_to "#{get_tournament_type(@standing.tournament)}" + " " + "#{@standing.tournament.season.year}",
tournament_path(@standing.tournament) %>
6 changes: 3 additions & 3 deletions app/views/tournaments/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= link_to 'Tournaments', tournaments_path %> &gt; <%= get_tournament_type(@tournament) %> <%= @tournament.season.year %>

<h3>Torneo <%= get_tournament_type(@tournament) %> <%= @tournament.season.year %></h3>


Expand All @@ -12,10 +14,8 @@
</p>
<% @standings.each do |standing| %>
<p>
<%=h standing.name %>
<%=h standing.name.capitalize %>
(<%=h standing.scheduled_date.to_formatted_s(:rfc822) %>)
<%= link_to "ver", tournament_standing_path(standing.tournament, standing) %>
</p>
<% end %>

<%= link_to 'tournaments', tournaments_path %>
16 changes: 13 additions & 3 deletions test/functional/standings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
class StandingsController; def rescue_action(e) raise e end; end

class StandingsControllerTest < ActionController::TestCase
fixtures :tournaments
fixtures :tournaments, :standings, :matches, :teams

def setup
@controller = StandingsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

@standing = standings(:fecha1a07)

end

def test_should_render_edit_link_for_emtpy_matches_on_standing_show
get :show, {'id' => standings(:fecha2a07),
'tournament_id' => tournaments(:apertura07)}
assert_response :success
end

def test_should_render_all_matches_on_standing_show
get :show, {'id' => standings(:fecha1a07),
'tournament_id' => tournaments(:apertura07)}
assert_response :success
end
end

0 comments on commit b8e7ccb

Please sign in to comment.