require "rubygems" require "ruby-debug" gem 'test-unit' require "test/unit" require 'active_support' require 'active_support/test_case' require 'active_record' require 'active_record/fixtures' require 'shoulda' require 'shoulda/active_record' require 'logger' this = File.expand_path(File.dirname(__FILE__)) #ActiveRecord::Base.logger = Logger.new(STDOUT) # b.class.reflect_on_all_associations.detect {|i| i.name == :child_location_relationship} require File.expand_path(File.join(this, '/../lib/acts-as-joinable')) require File.join(this, "database") ActsAsJoinable.models = Dir["#{this}/lib/*.rb"].collect { |f| File.basename f, '.rb' } Dir["#{File.dirname(__FILE__)}/../app/models/*"].each { |c| require c if File.extname(c) == ".rb" } Dir["#{this}/lib/*"].each { |c| require c if File.extname(c) == ".rb" } require "#{this}/lib/group" ActiveRecord::Base.class_eval do def self.detonate delete_all end end ActiveSupport::TestCase.class_eval do def create_models(parent = 1, child = 2) return unless Post.all.empty? parent.times do |i| post = Post.create!(:title => "title-#{i.to_s}") child.times do |j| position = (i + 1) * (j + 1) asset = Asset.create!(:title => "asset-title-#{position.to_s}") tag = Tag.create!(:name => "tag-name-#{position.to_s}") asset.tags << tag post.tags << tag post.assets << asset end end end def destroy_models Post.detonate Tag.detonate Asset.detonate Page.detonate Relationship.detonate Group.detonate Asset.detonate end end ActiveRecord::Base.connection.class.class_eval do IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /SHOW FIELDS/] def execute_with_query_record(sql, name = nil, &block) $queries_executed ||= [] $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r } execute_without_query_record(sql, name, &block) end alias_method_chain :execute, :query_record end