Sha256: 3a34740591f9535a1436d9a1cf66118f96a22cddd673749dbd70bbc0d1d26f9f

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

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)

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
    ActsAsJoinable::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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts-as-joinable-0.1.0 test/test_helper.rb