Rails 3 in test env won't allow records to save, even with latest sqlite3 - ruby-on-rails-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.

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:
Remove the corresponding line gem 'sqlite3' from your Gemfile
Run bundle install
Run gem uninstall sqlite3
Return the line gem 'sqlite3' to your Gemfile
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.

Related

Rails friendly_id: undefined method `slug` on production

I'm trying to introduce dynamic_sitemaps over resources with friendly_id. The issue is the production rails (rake / rails c) doesn't see the slug method. I've try to specify it by force by specifying an attr_accessible :slug, but it doesn't help either.
$ rake sitemap:generate
Generating sitemap...
rake aborted!
undefined method `slug' for #<Article:0xa9e4d14>
The funny thing it works smoothly on the local environment, and it should not be so much different with the capistrano/rvm deployment.
The column exists in the DB and is used by the rails app itself (which works fine too).
Added: it should be tied to either the environment or the specific gem version issue, but I'm not sure which one is the trouble, and how to debug it. The same pair works good for a different project with a pretty similar libraries bundle.
As the capistrano always do the dirty work, I forgot about the RAILS_ENV environment variable - so the console and cron job tried to operate against the dev DB and obviously failed.

Rails 3.2.11 performance testing issue: Don't know how to build task 'test:benchmark'

I'm following this railscast on performance testing, but I'm immediately running into an issue.
My app is rails 3.2.11, so according to the railscast it should include performance testing, but I don't have a folder called 'test' at all. When I run 'rails generate performance_test homepage' nothing happens or is generated. So I created one manually (to exactly match the railscast source code), but when I run rake test:benchmark I get the error
Don't know how to build task 'test:benchmark'
If I add the 'rails-perftest' gem to my gemfile and run bundle, then again try to generate a performance_test nothing happens, and when I then run rake test:benchmark, it throws a different error of
uninitialized constant Rails::SubTestTask
I've been sure to include the following dependencies in my gem file:
gem 'ruby-prof', group: :test
gem 'test-unit', group: :test
Could anyone help advise me what I'm doing wrong? Thanks!
I am not 100% certain on this, but I am guessing that you might not have your application.rb file configured accordingly. Also check your Gemfile.lock file and run the command bundle install because it could also be something funky going on with your Gems and dependencies.

no such file to load -- map_by_method

This question was asked before here, but can't say that the answer helps me. I am using Rails 3.1.3. When I run rails console on my local dev machine, I get the following message:
no such file to load -- map_by_method
The message doesn't prevent the irb session from launching, so it's benign. But I'd like to get rid of it. At one point in time I had the map_by_method gem installed, but I removed it from the Gemfile and gemset -- yet the message still appears. Any idea how to vanquish it?
there might be some causes for this:
there might be some other gem which has it as a dependency
you might have a require 'map_by_method' in your code
you might have a require in your .irbrc
the .irbrc can be located in your user home or in the current working directory.
have a look at an example .irbrc here: http://matthewhutchinson.net/2010/9/19/rails-3-bash-aliases-and-irbrc-configs
Probably the gem map_by_method has done some permanent changes on your system. Try re-installing it. It should fixed your problem. Same thing happened to me once. If it doesn't, try specifying it in development section of gemfile.

Custom Model - "no such file to load -- odbc"

I'm trying to create a custom model to interface with a database that isn't supported navtively by Rails or through the OpenLink ODBC driver. For some reason, I'm getting the following error:
no such file to load -- odbc
I'm at a lost as to why this is occurring as the ruby-odbc gem is in the GEM_PATH and I have a small script that tests this to ensure that the connection works and it worked perfectly. Does Rails ignore the gem_path? Is there something else I need to configure? I checked the GEM_PATH in Rails by writing it out to the browser and it matches what I saw in a terminal window.
FYI: I'm using rvm to manage ruby and all of my gems. Not sure if this makes any difference, though it really shouldn't from what I can tell.
Does your Gemfile include something like the following
gem 'ruby-odbc'

Prologue with Ruby on Rails 3

I'm a total newbie to RoR and am trying to get the Prologue gem up and running. I've downloaded the prologue zip file from github.com/quickleft/prologue and am trying to follow the instructions in the associated readme file. I have encountered a number of issues....
Q1: What do I actually do with the extracted zip file? For instance, am I supposed to place the extracted files inside specific rails application directories or what ?
I've been able to install the gem by executing "gem install prologue". However, I cannot create a new application using the "prologue new my_app" command - the following message is displayed at the command prompt when I execute that command:
*C:/Ruby192/lib/ruby/gems/1.9.1/gems/prologue-0.3.10/lib/prologue/cli.rb:58:in ``
': No such file or directory - git config --global user.name (Errno::ENOENT)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/prologue-0.3.10/lib/prologue/cli.rb:58:in `git_user_name'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/prologue-0.3.10/lib/prologue/cli.rb:33:in new'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22 :inrun'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in invoke_task'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor.rb:263:in dispatch'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:38
9:instart'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/prologue-0.3.10/bin/prologue:4: in <top (required)>'
from C:/Ruby192/bin/prologue:19:inload'
from C:/Ruby192/bin/prologue:19:in `'*
Q2: Does anyone have any advice on how to overcome this problem?
Q3: Also, when attempting to get prologue up and running is it possible to do this without integrating it into an existing rails application? If so, how?
(I have ruby 1.9.2 and rails 3.0.0 installed on a Windows Vista machine)
Advice/feedback on the above issues would be greatly welcome!
It seems that Prologue needs 'thor', another gem. You can install all dependencies with the command 'bundle install'.
You can integrate Prologue in a new Rails app, but you definitely need some (existing or new) Rails app to run it.