burke / zeus

Boot any rails app in under a second.
MIT License
3.33k stars 231 forks source link

use with sqlite in memory database #200

Open linojon opened 11 years ago

linojon commented 11 years ago

zeus fails all rspecs when setup to use sqlite in memory database. I'm hoping there's a way to configure my spec_helper to handle it but haven't figured out a way. Runs fine without zeus.

database.yml

test:                                                                                                                              
  adapter: sqlite3                                                                                                                 
  database: ":memory:"                                                                                                             
  pool: 5                                                                                                                          
  timeout: 5000  

spec_helper.rb

load_schema = lambda {
  load "#{Rails.root.to_s}/db/schema.rb"                                                          
  ActiveRecord::Migrator.up('db/migrate')
}
silence_stream(STDOUT, &load_schema)

When i run it acts like no tables exist in the database, e.g

     Failure/Error: u1 = FactoryGirl.create :admin_user
     ActiveRecord::StatementInvalid:
       Could not find table 'admin_users'

Running rake db:test:prepare either before or after zeus start does not help.

cromulus commented 10 years ago

bump. Having the same issue here.

Blue-Dog-Archolite commented 10 years ago

bump here as well.

Blue-Dog-Archolite commented 10 years ago

test_helper.rb

ENV["RAILS_ENV"] = "test"

require File.expand_path('../../config/environment', __FILE__)

require "rails/test_help"
require "minitest/rails"

require "minitest/rails/capybara"
require 'resque_unit_scheduler'
require 'resque_unit'
require 'action_controller/test_case'
require 'machinist'
require 'machinist/active_record'
require 'mocha/setup'
require 'turn'
require 'vcr'

begin
  require 'pry-rescue/minitest'
rescue LoadError => e
end

load_schema_from_file = lambda {
  load "#{Rails.root.to_s}/db/schema.rb" # use db agnostic schema by default
}
silence_stream(STDOUT, &load_schema_from_file)

inside of my test_helper.rb sorted out this error for me.

If you are using Machinist, make sure the silence_streams call is before your

Dir["#{File.expand_path(File.dirname(__FILE__))}/blueprints/*.rb"].each { |f| require f }
burke commented 10 years ago

Ah yes, this would not work. It's because we disconnect/reconnect from the database several times while booting the app in zeus. I'm not too sure how/if-possible to work around this. Simply not disconnecting might actually solve the problem. I guess we could test for whether the AR connection is an in-memory SQLite DB to determine whether to reconnect or not.

gregory commented 9 years ago

same issue here ... :(

RajRoR commented 9 years ago

+1 same issue