Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresSQLAdapter being used when using a SQLite3 database #224

Closed
josemotanet opened this issue Jun 20, 2013 · 36 comments
Closed

PostgresSQLAdapter being used when using a SQLite3 database #224

josemotanet opened this issue Jun 20, 2013 · 36 comments

Comments

@josemotanet
Copy link

I'm beginning using Cucumber along with database_cleaner in a Rails 4 app. I'm using sqlite3 as my testing database. A scenario I'm writing would pass if it weren't for this:

And I should see "This is a regular body."                # features/step_definitions/posts_steps.rb:8
      undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007f20d0112608> (NameError)
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:123:in `db_version'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:131:in `restart_identity'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:140:in `truncate_tables'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:234:in `block in clean'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/abstract_adapter.rb:307:in `disable_referential_integrity'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:230:in `clean'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/base.rb:86:in `clean'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/configuration.rb:79:in `block in clean'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/configuration.rb:79:in `each'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/configuration.rb:79:in `clean'
      /home/jose/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/cucumber-rails-1.3.0/lib/cucumber/rails/hooks/database_cleaner.rb:9:in `After'

My suspicion is that the connection adapter is being incorrectly set somewhere.
Let me know if there's any other info I can provide.

@DFrenkel
Copy link

DFrenkel commented Aug 2, 2013

I have similar symptoms for MySQL database and RSpec:

An error occurred in an after(:all) hook.
  NameError: undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x0000000692feb8>
  occurred at /usr/local/rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:123:in `db_version'

@pedroassumpcao
Copy link

I got some error as well using MySQL and RSpec, using truncation for features specs with js. Using Rails 3.1.6.

gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:123:in
`db_version': undefined local variable or method `postgresql_version'
for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x007fdc88e2a8d0> (NameError)

@funkenstrahlen
Copy link

I also have this problem. Do not know what to do:

/Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:123:in `db_version': undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007fa87a021500> (NameError)
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:131:in `restart_identity'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:140:in `truncate_tables'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:234:in `block in clean'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract_adapter.rb:168:in `disable_referential_integrity'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:230:in `clean'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/base.rb:40:in `clean_with'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/configuration.rb:85:in `block in clean_with'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/configuration.rb:85:in `each'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/database_cleaner-1.1.1/lib/database_cleaner/configuration.rb:85:in `clean_with'
    from /Users/stefan/Projects/reliveradio/spec/spec_helper.rb:45:in `block (2 levels) in <top (required)>'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:21:in `instance_eval'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:21:in `run'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:66:in `block in run'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:66:in `each'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:66:in `run'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/hooks.rb:427:in `run_hook'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:27:in `block in run'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/reporter.rb:58:in `report'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/command_line.rb:25:in `run'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:80:in `run'
    from /Users/stefan/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.14.4/lib/rspec/core/runner.rb:17:in `block in autorun'

I use database_cleaner (1.1.1) and sqlite. Rails is Rails 3.2.13.

@funkenstrahlen
Copy link

Similar problems in this issue: #209

@nepalez
Copy link

nepalez commented Aug 2, 2013

Same problem in Rails 4
Temporarily downgraded to gem database_cleaner, '< 1.1.0'

@funkenstrahlen
Copy link

@nepalez So it works for < 1.1.0 ?

@nepalez
Copy link

nepalez commented Aug 2, 2013

Yes

@pedroassumpcao
Copy link

Even downgrading didn't work for Rails 3.1.6.

@funkenstrahlen
Copy link

I downgraded to 1.0.1 and it works now.

@lucasuyezu
Copy link

+1. Using 1.0.1 until this is fixed.

Crunch09 added a commit to metaminded/tabulatr2 that referenced this issue Aug 4, 2013
@bosko
Copy link

bosko commented Aug 5, 2013

Same error occurs with Rails 4 and activerecord-sqlserver-adapter (fork https://github.com/arthrex/activerecord-sqlserver-adapter which currently only runs on Rails4).

@wanbok
Copy link

wanbok commented Aug 6, 2013

+1

@utx0
Copy link

utx0 commented Aug 9, 2013

+1

@t-siddharth
Copy link

@nepalez - Thanks! Downgrading the database cleaner gem helped.

@sdorunga
Copy link

@nepalez Thanks as well, tripped me up for a second.

@parndt
Copy link

parndt commented Aug 11, 2013

I've hit this problem, too, when running globalize3 specs. Downgrading to 1.0.1 removes this particular problem, per svenfuchs/globalize3@aae2c33

@bmabey I assume you saw this?

@bmabey
Copy link
Contributor

bmabey commented Aug 11, 2013

@parndt Yeah, I've seen the thread. I think 9bf038d is the only commit that would have caused this issue. I've been looking at the code and I can't spot the bug. It seems like it has to be in these lines:

https://github.com/bmabey/database_cleaner/blob/198843e0e7023621578ae4641ba3ea1254ab991d/lib/database_cleaner/active_record/truncation.rb#L192-L202

@cinnamonshop
Copy link

Are the following lines including the PostgreSQLAdapter code in the same JdbcAdapter or AbstractAdapter after the SQLiteAdapter include, overriding the truncate_table SQLite call in all cases (which calls truncate_tables, then cascade, db_version, postgresql_version...)?

https://github.com/bmabey/database_cleaner/blob/7effdb71cbab73f34bb459d089e795627ef015a2/lib/database_cleaner/active_record/truncation.rb#L199-L202

https://github.com/bmabey/database_cleaner/blob/7effdb71cbab73f34bb459d089e795627ef015a2/lib/database_cleaner/active_record/truncation.rb#L122-L146

@parndt
Copy link

parndt commented Aug 11, 2013

Yes, it looks like that to me too.

@Crunch09
Copy link

Yes, the problem is that PostgreSQLAdapter gets also included even if you use SQLite (or MySQL). If i remove this line everything works fine with SQLite. But i couldn't figure out a proper fix for it yet.

@parndt
Copy link

parndt commented Aug 11, 2013

How about we don’t run code for an adapter we’re not using?

@bmabey
Copy link
Contributor

bmabey commented Aug 11, 2013

That would handle the case for projects that only are using a single adapter but some projects use multiple DB adapters.

@tommeier
Copy link
Contributor

Does this help? #221

@indyarocks
Copy link

I also faced this issue with version 1.1.1 and also with "gem 'database_cleaner', github: 'bmabey/database_cleaner'" on rails 4.0. So moved back to "<1.1.0", which resolved the issue.

@moh-alsheikh
Copy link

I also faced the same problem with rails 3.2.12 move to 'database_cleaner', '< 1.1.0' fix the issue.

@melcher
Copy link

melcher commented Oct 2, 2013

+1

@MHMDhub
Copy link

MHMDhub commented Oct 3, 2013

+1 for 'database_cleaner', '< 1.1.0'

@parndt
Copy link

parndt commented Oct 3, 2013

What also fixes this problem is #221 by @tommeier -- can you please review using that instead of +1 downgrading?

@bmabey
Copy link
Contributor

bmabey commented Oct 3, 2013

Hi all, please point your Gemfiles to master, git://github.com/bmabey/database_cleaner.git, to see if that resolves your problems. I've merged in @tommeier's work on #221 and #241. I'll cut a release if it resolves the issue.

@seanlinsley
Copy link

Master is working for me 🐙

Thanks @bmabey & @tommeier

@parndt
Copy link

parndt commented Oct 3, 2013

Works on Refinery CMS!

@zerokarmaleft
Copy link

+1 for latest changes in master.

@lucasuyezu
Copy link

Master (commit 1ce7c99) works for me! Nice job!

@bosko
Copy link

bosko commented Oct 9, 2013

Works for me too.

@bmabey
Copy link
Contributor

bmabey commented Oct 9, 2013

Just pushed v1.2.0 so you can lock to that now. Thanks all for your feedback and patience. And again, thanks to @tommeier and co for resolving this issue.

@bmabey bmabey closed this as completed Oct 9, 2013
@seanlinsley
Copy link

🍻

fcheung pushed a commit to dressipi/rails_apps_composer that referenced this issue Nov 29, 2013
yoon pushed a commit to NUBIC/surveyor that referenced this issue Mar 24, 2014
The tests were failing with:
~/.rvm/gems/ruby-2.0.0-p247/gems/database_cleaner-1.1.0/lib/database_cleaner/active_record/truncation.rb:123:in `db_version': undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007fd28ac70df8> (NameError)

Here's the bug report: DatabaseCleaner/database_cleaner#224

Looks like it might be a while until a fix happens so for the time
being we'll pin database_cleaner to version 1.0.1 which appears to
work.
kaznum added a commit to kaznum/sanataro that referenced this issue Apr 22, 2014
tmock12 pushed a commit to tmock12/rails_apps_composer that referenced this issue Jun 19, 2014
vmatiyko pushed a commit to boundround/spree-add-on that referenced this issue Apr 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests