acts_as_authentic not works with observer #337

Open
emeraldMaster opened this Issue Nov 19, 2012 · 0 comments

1 participant

@emeraldMaster

Hi, I faced this sad issue:
I have a model named User, which has following code:

class User < ActiveRecord::Base
  acts_as_authentic do |config|
    config.login_field = false
    config.require_password_confirmation = false
    config.ignore_blank_passwords = true
  end
....

I have an observer for User too, with 1 callback method(after_create)
When I'm trying to do

RAILS_ENV=test rake db:drop
RAILS_ENV=test rake db:create db:migrate

I'm getting this error:

rake aborted!
You must establish a database connection before using acts_as_authentic

going deeper, exception was thrown in acts_as_authentic, in !db_setup? with this message:

rake aborted!
Mysql2::Error: Table 'platform_test.users' doesn't exist: SHOW FULL FIELDS FROM `users`

absolutely agree with this message! BUT users table does not exists because db:migrate is not executed yet!

As workaround, I stopped at this variant:

class User < ActiveRecord::Base

  acts_as_authentic do |config|
    config.login_field = false
    config.require_password_confirmation = false
    config.ignore_blank_passwords = true
  end if ActiveRecord::Base.connection.tables.include?(self.table_name) # workaround
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment