This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Here is a hint for the view | |
@team.home_games.all(:conditions => #...fill in the rest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test 'upcoming games are games without a score' do | |
liverpool = Team.create!(:name => 'Liverpool') | |
arsenal = Team.create!(:name => 'Arsenal') | |
upcoming_liverpool_versus_arsenal = Game.create!(:home_team => liverpool, :away_team => arsenal) | |
played_liverpool_versus_arsenal = Game.create!(:home_team => liverpool, :away_team => arsenal, :home_score => 2, :away_score => 3) | |
assert liverpool.home_games.upcoming.include?(upcoming_liverpool_versus_arsenal) | |
assert_equal false, liverpool.home_games.upcoming.include?(played_liverpool_versus_arsenal) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test 'that teams can have away games' do | |
liverpool = Team.create!(:name => 'Liverpool') | |
arsenel = Team.create!(:name => 'Arsenel') | |
liverpool_versus_arsenel = Game.create!(:home_team => liverpool, :away_team => arsenel) | |
assert liverpool.home_games.include?(liverpool_versus_arsenel) | |
assert arsenel.away_games.include?(liverpool_versus_arsenel) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GamesHelper | |
def friendly_team_name(team) | |
if team.nil? | |
'' | |
else | |
team.name | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_filter :convert_team_name_parameters_to_models, :only => [:create, :update] | |
private | |
def convert_team_name_parameters_to_models | |
params[:game][:home_team] = Team.find_or_create_by_name(params[:game][:home_team]) | |
params[:game][:away_team] = Team.find_or_create_by_name(params[:game][:away_team]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class GameTest < ActiveSupport::TestCase | |
test 'that a team can be assigned to the game home team' do | |
liverpool = Team.create!(:name => 'Liverpool') | |
chelsea = Team.create!(:name => 'Chelsea') | |
upcoming_game = Game.create!(:home_team => liverpool, :away_team => chelsea) | |
assert_equal upcoming_game.home_team, liverpool | |
assert_equal upcoming_game.away_team, chelsea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= link_to @game.home_team, team_url(@game.home_team) %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
helper :all | |
helper_method :current_user_session, :current_user | |
filter_parameter_logging :password, :password_confirmation | |
protected | |
def current_user_session | |
return @current_user_session if defined?(@current_user_session) | |
@current_user_session = UserSession.find | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.join(File.dirname(__FILE__), '..', 'test_helper') | |
# See all assertions: http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/ | |
# Run all tests: rake test | |
# Run this test: ruby test/unit/ruby_test.rb | |
class RubyTest < ActiveSupport::TestCase | |
test "that true is the same as true" do | |
assert true == true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hook our MongoMapper model into Solr | |
module MongoAdapter | |
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter | |
def id | |
@instance.id | |
end | |
end | |
class DataAccessor < Sunspot::Adapters::DataAccessor | |
def load(id) |