brandonhilkert / sucker_punch

Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
MIT License
2.65k stars 114 forks source link

Database Empty on Test with MiniTest Rails 4.1.6 #100

Closed titopandub closed 9 years ago

titopandub commented 9 years ago

I have a problem, my test is failing on calling ActiveRecord inside perform method in job. It is said ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: .... Here is my test_helper.rb

require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'database_cleaner'
require 'sucker_punch/testing/inline'

class ActiveSupport::TestCase
  self.use_transactional_fixtures = false
  fixtures :all

  # Add more helper methods to be used by all tests here...

  DatabaseCleaner.strategy = :truncation

  def setup
    DatabaseCleaner.start
  end

  def teardown
    DatabaseCleaner.clean
  end
end

and here is my Job

class InviteMeetingJob
  include SuckerPunch::Job

  def perform(invitation_id, user_id, locale = :en)
    invitation = Invitation.find(invitation_id)
    current_user = User.find(user_id)

    InvitationMailer.invite_meeting(invitation, current_user, locale).deliver
  end
end

If I use ActiveRecord::Base.connection_pool.with_connection block inside perform, the test that using this code will fail and other test that execute after this that using database will also fail. If not, then only test that using this code that fail.

brandonhilkert commented 9 years ago

Can you post a sample app where this is happening that I can play with?

titopandub commented 9 years ago

Hi Brandon,

I'm so sorry, this test failing because I'm using in memory database for testing. When I switch into file (sqlite3) database, then everything is working okay. Thank you very much for this gem. :+1:

brandonhilkert commented 9 years ago

Great to hear you got it worked out. Thanks for the follow up.