3

I saw this post:

Rails/ActiveRecord/SQLite3: Can't save records in test environment

And after upgrading my sqlite version to the very latest (3.7.17), I am still getting the following error:

ActiveRecord::StatementInvalid: SQLite3::SQLException: near "SAVEPOINT": syntax error: SAVEPOINT active_record_1

Any time I try to create anything at all. If all I do is load my fixtures, everything is fine.

I have confirmed that rails is using the updated sqlite3 version by running "rails db".

In my development environment, I can create objects all day long with no errors (I can even have an object create another object after create).

What is special about my test environment that this is happening? How can I fix it?

Edit:

If I delete my test database, and redo rake:db:create and rake:db:migrate, I still get the same issues.

Doing "rails console test" lets me use the test environment just fine, and I can create objects all day long and see existing fixtures. It's only when I type "rake test:units" that I get the errors... (originally I had errors, but one error was legitimate (I don't know why I wasn't getting it in the development environment, and the adapter error was because apparently you aren't supposed to do "rails console RAILS_ENV="test", so it was looking for an adapter for an envrionment called "RAILS_ENV=test")

Edit: When I type "gem uninstall sqlite3" it uninstalls. When I then type "bundle install" it has a problem reinstalling...working on it now.

    /home/jenny/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb --with-sqlite3-dir=/usr/local/bin/sqlite3 checking for sqlite3.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.  Check

the mkmf.log file for more details. You may need configuration options.

If I type "gem install sqlite3" separately, it works just fine, and then "bundle install" it works. However, "rake test:units" has the same errors.

Edit: When I type "which sqlite3" it prints out "/usr/local/bin/sqlite3"

I wasn't even aware sqlite3 headers were a thing, so I doubt I installed them. I'll try to figure out how to confirm this and see if it helps.

Edit:

I don't see anywhere to download sqlite3 headers on the main site...just source and the precompiled linux binary. There doesn't seem to be a special header in the source, but even if there was, wouldn't it be included in the precompiled binary?

EDIT: link to bundler sqlite3 install error that don't happen when i manually install the gem

http://pastie.org/8063577

EDIT: Not a devise problem. I thought it was, but it turned out I was just creating another object in fixtures, not in the test code.

So, I can create devise User or any other type of object in fixtures all day long, but if I attempt to create one in the unit test, I get the save point error. Same thing for trying to save a fixture in a unit test.

Community
  • 1
  • 1
J.R.
  • 5,789
  • 11
  • 55
  • 78
  • Have you done a `rake db:test:prepare`? – spullen Jun 18 '13 at 13:49
  • What's your OS? Have you reinstalled your gem after updating your local sqlite? – Marcelo De Polli Jun 18 '13 at 13:50
  • Seems like [this](http://stackoverflow.com/questions/7367274/rails-3-1-app-cant-install-sqlite3-gem-because-libraries-are-out-of-date) might be the solution to your problem. – spullen Jun 18 '13 at 13:52
  • doing another "bundle install" after updating the local sqlite does nothing. If I do gem update sqlite3 i get "nothing to update". The attached "this" link doesn't seem relevant, as my sqlite3 version is already up to date. rake db:test:prepare seems to change nothing, with the exact same errors upon doing rake test:units – J.R. Jun 18 '13 at 16:18
  • I'm running under open suse linux. – J.R. Jun 18 '13 at 19:37
  • The second error might be resolved by doing a `rake db:test:prepare`. Have you tried uninstalling the gem then reinstalling it? – spullen Jun 20 '13 at 13:46
  • Is `/usr/local/bin/sqlite3` where you're sqlite resides? Do a sanity check to make sure. Also did you install the headers for sqlite version? – spullen Jun 20 '13 at 14:07
  • At this point, I'm wondering if sqlite3 is just fine, but there's something wrong with rails' unit tests. – J.R. Jun 20 '13 at 15:46
  • If the gem doesn't install with `bundle install` then I wouldn't look anywhere else for the problem. – Marcelo De Polli Jun 20 '13 at 16:24

1 Answers1

0

Your problem is most likely related to the fact that you updated your local sqlite but after that you haven't reinstalled your sqlite3 gem.

I'd recommend you follow these steps:

  1. Remove the corresponding line gem 'sqlite3' from your Gemfile
  2. Run bundle install
  3. Run gem uninstall sqlite3
  4. Return the line gem 'sqlite3' to your Gemfile
  5. Run bundle install one more time

If you simply gem uninstall and then bundle install, it will install the same version and dependencies that were recorded in Gemfile.lock. But since you're now using a different and more updated local version, it's safer to allow Bundler to install a new version if needed.

Marcelo De Polli
  • 28,123
  • 4
  • 37
  • 47
  • When I follow your steps, running bundle install after uninstalling sqlite3 gets me the line 'An error occurred while installing sqlite3 (1.3.7), and Bundler cannot continue. Make sure that `gem install sqlite3 -v '1.3.7'` succeeds before bundling. '. If I manually say 'gem install sqlite3 -v '1.3.7' it installs correctly, and i can run bundle install with no problem. When I run "rake test:units", I get the same errors. – J.R. Jun 20 '13 at 15:42
  • Things to try: completely reset your RVM gemset (`rvm gemset empty`), update Bundler (`gem update bundler`), update rubygems (`gem update --system` – Marcelo De Polli Jun 20 '13 at 16:03
  • updating bundler seemed to be redundant, as I had to reinstall it after updating rubygems. Once reinstalled, I ran bundle install again. Again I had the sqlite3 error, and again it suggested I install the gem manually (printing out the appropriate command). It also had configuration options I could potentially use, and said there was a "mkmf.log" file I could check somewhere. I'll look into this. – J.R. Jun 20 '13 at 16:35
  • Another idea: `gem pristine sqlite3` – Marcelo De Polli Jun 24 '13 at 04:30
  • Nope, same error. I'm close to giving up on this. It would be ideal to be able to run unit tests... Maybe I can just try a fresh install on another machine. – J.R. Jun 24 '13 at 13:37