Permalink
Browse files

Make testing easier by removing rails app from test directory and jus…

…t load ActiveRecord/AcitionView manually
  • Loading branch information...
1 parent 254728e commit b0c493aa02ea5430c0cc2373cb23628ac43d2771 @bkeepers bkeepers committed Sep 27, 2008
View
@@ -1,4 +1,5 @@
require 'rake'
+require "load_multi_rails_rake_tasks"
require 'rake/testtask'
require 'rake/rdoctask'
View
@@ -1,10 +0,0 @@
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
-
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-require 'tasks/rails'
@@ -1,10 +0,0 @@
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
-
- # See ActionController::RequestForgeryProtection for details
- # Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery # :secret => '012cbaf0c3d36504f3b1bc397b838d24'
-end
@@ -1,3 +0,0 @@
-# Methods added to this helper will be available to all templates in the application.
-module ApplicationHelper
-end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__)+'/../test_helper'
+require File.dirname(__FILE__)+'/test_helper'
class AssociatedFormHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormHelper
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require File.dirname(__FILE__) + '/test_helper'
class CommentTest < ActiveSupport::TestCase
should_belong_to :photo
View
@@ -1,97 +0,0 @@
-# Don't change this file!
-# Configure your app in config/environment.rb and config/environments/*.rb
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-module Rails
- class << self
- def boot!
- pick_boot.run unless booted?
- end
-
- def booted?
- defined? Rails::Initializer
- end
-
- def pick_boot
- (vendor_rails? ? VendorBoot : GemBoot).new
- end
-
- def vendor_rails?
- File.exist?("#{RAILS_ROOT}/vendor/rails")
- end
- end
-
- class Boot
- def run
- load_initializer
- Rails::Initializer.run(:set_load_path)
- end
- end
-
- class VendorBoot < Boot
- def load_initializer
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
- end
- end
-
- class GemBoot < Boot
- def load_initializer
- self.class.load_rubygems
- load_rails_gem
- require 'initializer'
- end
-
- def load_rails_gem
- if version = self.class.gem_version
- gem 'rails', "=#{version}"
- else
- gem 'rails'
- end
- rescue Gem::LoadError => load_error
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
- exit 1
- end
-
- class << self
- def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
- end
-
- def gem_version
- if defined? RAILS_GEM_VERSION
- RAILS_GEM_VERSION
- elsif ENV.include?('RAILS_GEM_VERSION')
- ENV['RAILS_GEM_VERSION']
- else
- parse_gem_version(read_environment_rb)
- end
- end
-
- def load_rubygems
- require 'rubygems'
-
- unless rubygems_version >= '0.9.4'
- $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
- exit 1
- end
-
- rescue LoadError
- $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
- exit 1
- end
-
- def parse_gem_version(text)
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([\d.]+)'/
- end
-
- private
- def read_environment_rb
- File.read("#{RAILS_ROOT}/config/environment.rb")
- end
- end
- end
-end
-
-# All that for this:
-Rails.boot!
@@ -1,15 +0,0 @@
-development:
- adapter: mysql
- encoding: utf8
- database: attribute_fu_test
- username: root
- password:
- socket: /tmp/mysql.sock
-
-test:
- adapter: mysql
- encoding: utf8
- database: attribute_fu_test
- username: root
- password:
- socket: /tmp/mysql.sock
@@ -1,15 +0,0 @@
-$:.reject! { |e| e.include? 'TextMate' }
-RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
-
-require File.join(File.dirname(__FILE__), 'boot')
-
-Rails::Initializer.run do |config|
- config.action_controller.session = {
- :session_key => '_test_session',
- :secret => '012cbaf0c3d36504f3b1bc397b838d24'
- }
-
- config.load_paths += %W( #{RAILS_ROOT}/../lib )
-end
-
-require "#{RAILS_ROOT}/../init"
@@ -1,18 +0,0 @@
-# Settings specified here will take precedence over those in config/environment.rb
-
-# In the development environment your application's code is reloaded on
-# every request. This slows down response time but is perfect for development
-# since you don't have to restart the webserver when you make code changes.
-config.cache_classes = false
-
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
-
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_controller.perform_caching = false
-config.action_view.cache_template_extensions = false
-config.action_view.debug_rjs = true
-
-# Don't care if the mailer can't send
-config.action_mailer.raise_delivery_errors = false
@@ -1,22 +0,0 @@
-# Settings specified here will take precedence over those in config/environment.rb
-
-# The test environment is used exclusively to run your application's
-# test suite. You never need to work with it otherwise. Remember that
-# your test database is "scratch space" for the test suite and is wiped
-# and recreated between test runs. Don't rely on the data there!
-config.cache_classes = true
-
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
-
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_controller.perform_caching = false
-
-# Disable request forgery protection in test environment
-config.action_controller.allow_forgery_protection = false
-
-# Tell ActionMailer not to deliver emails to the real world.
-# The :test delivery method accumulates sent emails in the
-# ActionMailer::Base.deliveries array.
-config.action_mailer.delivery_method = :test
View
@@ -1,35 +0,0 @@
-ActionController::Routing::Routes.draw do |map|
- # The priority is based upon order of creation: first created -> highest priority.
-
- # Sample of regular route:
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # map.resources :products
-
- # Sample resource route with options:
- # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
-
- # Sample resource route with sub-resources:
- # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
-
- # Sample resource route within a namespace:
- # map.namespace :admin do |admin|
- # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
- # admin.resources :products
- # end
-
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
- # map.root :controller => "welcome"
-
- # See how all your routes lay out with "rake routes"
-
- # Install the default routes as the lowest priority.
- map.connect ':controller/:action/:id'
- map.connect ':controller/:action/:id.:format'
-end
View
@@ -0,0 +1,18 @@
+sqlite3:
+ adapter: sqlite3
+ dbfile: awesome_nested_set.sqlite3.db
+sqlite3mem:
+ :adapter: sqlite3
+ :dbfile: ":memory:"
+postgresql:
+ :adapter: postgresql
+ :username: postgres
+ :password: postgres
+ :database: awesome_nested_set_plugin_test
+ :min_messages: ERROR
+mysql:
+ :adapter: mysql
+ :host: localhost
+ :username: root
+ :password:
+ :database: awesome_nested_set_plugin_test
@@ -1,14 +0,0 @@
-class CreatePhotos < ActiveRecord::Migration
- def self.up
- create_table :photos do |t|
- t.string :title
- t.text :description
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :photos
- end
-end
@@ -1,15 +0,0 @@
-class CreateComments < ActiveRecord::Migration
- def self.up
- create_table :comments do |t|
- t.integer :photo_id
- t.string :author
- t.text :body
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :comments
- end
-end
View
@@ -1,29 +1,16 @@
-# This file is auto-generated from the current state of the database. Instead of editing this file,
-# please use the migrations feature of ActiveRecord to incrementally modify your database, and
-# then regenerate this schema definition.
-#
-# Note that this schema.rb definition is the authoritative source for your database schema. If you need
-# to create the application database on another system, you should be using db:schema:load, not running
-# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
-# you'll amass, the slower it'll run and the greater likelihood for issues).
-#
-# It's strongly recommended to check this file into your version control system.
-
ActiveRecord::Schema.define(:version => 2) do
- create_table "comments", :force => true do |t|
- t.integer "photo_id"
- t.string "author"
- t.text "body"
- t.datetime "created_at"
- t.datetime "updated_at"
+ create_table :comments, :force => true do |t|
+ t.integer :photo_id
+ t.string :author
+ t.text :body
+ t.timestamps
end
- create_table "photos", :force => true do |t|
- t.string "title"
- t.text "description"
- t.datetime "created_at"
- t.datetime "updated_at"
+ create_table :photos, :force => true do |t|
+ t.string :title
+ t.text :description
+ t.timestamps
end
end
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require File.dirname(__FILE__) + '/test_helper'
class PhotoTest < ActiveSupport::TestCase
should_have_many :comments
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
-require 'commands/console'
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
-require 'commands/destroy'
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
-require 'commands/generate'
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
-require 'commands/server'
@@ -1,6 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
-require 'test_help'
-require 'mocha'
-
-class Test::Unit::TestCase; end
View
@@ -0,0 +1,23 @@
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+plugin_test_dir = File.dirname(__FILE__)
+
+require 'rubygems'
+require 'multi_rails_init'
+require 'active_record'
+require 'action_view'
+require 'test/unit'
+require 'shoulda/rails'
+
+require 'attribute_fu'
+require 'attribute_fu/associations'
+require 'attribute_fu/associated_form_helper'
+require plugin_test_dir + '/../init.rb'
+
+ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
+
+ActiveRecord::Base.configurations = YAML::load(IO.read(plugin_test_dir + "/db/database.yml"))
+ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem")
+ActiveRecord::Migration.verbose = false
+load(File.join(plugin_test_dir, "db", "schema.rb"))
+
+Dir["#{plugin_test_dir}/models/*.rb"].each {|file| require file }
Oops, something went wrong. Retry.

0 comments on commit b0c493a

Please sign in to comment.