Skip to content

Instantly share code, notes, and snippets.

#Here is a hint for the view
@team.home_games.all(:conditions => #...fill in the rest
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
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
module GamesHelper
def friendly_team_name(team)
if team.nil?
''
else
team.name
end
end
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
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
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
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
# 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)