DatabaseCleaner / database_cleaner-active_record

Strategies for cleaning databases using ActiveRecord. Can be used to ensure a clean state for testing.
MIT License
64 stars 63 forks source link

0.7.1 fails with superclass mismatch on JRuby #32

Closed michaelklishin closed 1 year ago

michaelklishin commented 12 years ago

Recently released 0.7.1 seems to break on JRuby (both 1.8 and 1.9 modes). Here's travis-ci.org build link.

$ bundle exec rake
183/home/vagrant/.rvm/rubies/jruby-1.6.5.1/bin/jruby -S rspec ./spec/irc_client_spec.rb ./spec/github_spec.rb ./spec/travis/github_api_spec.rb ./spec/travis/config_spec.rb ./spec/travis/renderer_spec.rb ./spec/travis/mailer/build_spec.rb ./spec/travis/mailer/helper/build_spec.rb ./spec/travis/notifications/secure_config_spec.rb ./spec/travis/notifications/handler/pusher_spec.rb ./spec/travis/notifications/handler/campfire_spec.rb ./spec/travis/notifications/handler/archive_spec.rb ./spec/travis/notifications/handler/email_spec.rb ./spec/travis/notifications/handler/worker_spec.rb ./spec/travis/notifications/handler/irc_spec.rb ./spec/travis/notifications/handler/webhook_spec.rb ./spec/travis/notifications/handler/worker/payload_spec.rb ./spec/travis/model/job_spec.rb ./spec/travis/model/user_spec.rb ./spec/travis/model/repository_spec.rb ./spec/travis/model/ssl_key_spec.rb ./spec/travis/model/request_spec.rb ./spec/travis/model/service_hook_spec.rb ./spec/travis/model/build_spec.rb ./spec/travis/model/worker_spec.rb ./spec/travis/model/token_spec.rb ./spec/travis/model/artifact/log_spec.rb ./spec/travis/model/build/matrix_spec.rb ./spec/travis/model/build/states_spec.rb ./spec/travis/model/build/notifications_spec.rb ./spec/travis/model/build/denormalize_spec.rb ./spec/travis/model/request/states_spec.rb ./spec/travis/model/request/branches_spec.rb ./spec/travis/model/request/payload/github_spec.rb ./spec/travis/model/job/tagging_spec.rb ./spec/travis/model/job/cleanup_spec.rb ./spec/travis/model/job/queue_spec.rb ./spec/travis/model/job/test/states_spec.rb ./spec/travis/model/job/configure/states_spec.rb ./spec/travis/model/worker/states_spec.rb ./spec/json/worker/job_test_spec.rb ./spec/json/worker/job_configure_spec.rb ./spec/json/webhook/build_finished_spec.rb ./spec/json/pusher/job_finished_spec.rb ./spec/json/pusher/job_created_spec.rb ./spec/json/pusher/job_log_spec.rb ./spec/json/pusher/build_started_spec.rb ./spec/json/pusher/worker_spec.rb ./spec/json/pusher/job_started_spec.rb ./spec/json/pusher/build_finished_spec.rb
184TypeError: superclass mismatch for class PostgreSQLAdapter
185  ConnectionAdapters at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/active_record/truncation.rb:80
186        ActiveRecord at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/active_record/truncation.rb:7
187              (root) at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/active_record/truncation.rb:6
188             require at org/jruby/RubyKernel.java:1038
189             require at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240
190     load_dependency at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223
191    new_constants_in at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640
192    new_constants_in at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:639
193     load_dependency at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223
194             require at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240
195        orm_strategy at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/active_record/truncation.rb:98
196     create_strategy at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/base.rb:34
197           strategy= at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/base.rb:48
198           strategy= at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/configuration.rb:42
199                each at org/jruby/RubyArray.java:1612
200           strategy= at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/database_cleaner-0.7.1/lib/database_cleaner/configuration.rb:42
201              (root) at /home/vagrant/builds/travis-ci/travis-core/spec/support/active_record.rb:18
202             require at org/jruby/RubyKernel.java:1038
203              (root) at /home/vagrant/builds/travis-ci/travis-core/spec/support/active_record.rb:2
204                load at org/jruby/RubyKernel.java:1063
205     load_spec_files at /home/vagrant/builds/travis-ci/travis-core/spec/travis/renderer_spec.rb:698
206             collect at org/jruby/RubyArray.java:2318
207     load_spec_files at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698
208                 run at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22
209      run_in_process at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80
210                 run at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69
211             autorun at /home/vagrant/.rvm/gems/jruby-1.6.5.1/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10
212                call at org/jruby/RubyProc.java:270
213                call at org/jruby/RubyProc.java:224
erich commented 12 years ago

same for rails-3.2.0, even master branch for github

bowsersenior commented 12 years ago

I ran into a similar problem with MySQL when upgrading to Rails 3.2 . I was able to fix by patching the code in the installed gem (ugly I know!):

    # lib/database_cleaner/active_record/truncation.rb line 177
    if defined?(AbstractMysqlAdapter) && MysqlAdapter < AbstractMysqlAdapter
      MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractMysqlAdapter
    else
      MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
    end

    if defined?(AbstractMysqlAdapter) && Mysql2Adapter < AbstractMysqlAdapter
      MYSQL2_ADAPTER_PARENT = AbstractMysqlAdapter
    else
      MYSQL2_ADAPTER_PARENT = AbstractAdapter
    end

You may be able to pull off a similar trick for the Postgres adapter. (I just use bundle show database_cleaner to find out where the gem is installed and then edit in place--you can also install gem_open and then do bundle open database_cleaner).

The trouble is that the patch above causes the specs to database_cleaner gem's specs to fail since MysqlAdapter is not defined at this point. I don't think this approach in the code is good. If there was a way to do a class_eval, that would get around the problem with determining the parent class. Seems like there has been quite a bit of discussion about this previously:

Hope this info sheds some light and helps you solve your issue!

ldonnet commented 11 years ago

I work on a web application using jruby 1.8.7 and want to use database_cleaner 1.1.1 with capybara for tests. But it fails when I execute tests and look similar to your bug :

/home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:185: uninitialized constant ActiveRecord::ConnectionAdapters::JdbcAdapter (NameError)
    from /home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/base.rb:129:in `orm_strategy'
    from /home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/base.rb:33:in `create_strategy'
    from /home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/base.rb:37:in `clean_with'
    from /home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/configuration.rb:85:in `clean_with'
    from /home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/configuration.rb:85:in `each'
    from /home/luc/.rbenv/versions/1.8.7-debian/gems/gems/database_cleaner-1.1.1/lib/database_cleaner/configuration.rb:85:in `clean_with'
    from /home/luc/projects/chouette2/spec/spec_helper.rb:40

This bug was fixed and it 's a new one or not?

etagwerker commented 9 years ago

Unfortunately this is still an issue. I've started working on the code to add jruby support but it might take a while.

If anyone is interested in helping with this, please let me know.

etagwerker commented 1 year ago

Closing this for now because JRuby is not supported by this gem.