Skip to content

Instantly share code, notes, and snippets.

public class ObjectComparer : System.Collections.IComparer
{
private const int COMPARE_EQUAL = 0;
private const int COMPARE_GREATERTHAN = 1;
private const int COMPARE_LESSTHAN = -1;
private string _propertyNames = string.Empty;
//params string[] names
public ObjectComparer(string propertyName){
this._propertyNames = propertyName;
}
Sequel.connect(:adapter => 'oracle', :user => 'something', :password => 'secret', :database => '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<somehost>)(PORT=<someport>))(CONNECT_DATA=(SID=<somesid>)))')
# 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)
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
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 '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
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
module GamesHelper
def friendly_team_name(team)
if team.nil?
''
else
team.name
end
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