Unit tests fail with sqlite3 and rails 1.1

Hello all,

I’m kinda going through a rocky upgrade to rails 1.1 and I can’t find
much on google about this. When I run my tests I get this:

$ rake
(in /home/www/art2)
/usr/bin/ruby -Ilib:test
“/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb”
“test/functional/panoramas_controller_test.rb”
“test/functional/links_controller_test.rb”
“test/functional/articles_controller_test.rb”
“test/functional/categories_controller_test.rb”
“test/functional/rss_controller_test.rb”
“test/functional/photos_controller_test.rb”
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader
Started

Finished in 0.833814 seconds.

42 tests, 160 assertions, 0 failures, 0 errors
rake aborted!
Test failures

(See full trace by running task with --trace)

Obviously this error message makes a lot of sense to me because it
says 0 failures, 0 errors, then two lines down it says there’s test
failures. Oddly, it’s only doing functional tests, no unit tests. So I
run it again with --trace like it says and it tells me a whole lot of
nothing particularly useful (it’s showing the trace for the functional
tests, which work fine. it’s still just skipping and ignoring the unit
tests). So, I google around and find this trickery to force it to run
the unit tests:

$ rake test:units --trace
(in /home/www/art2)
** Invoke test:units (first_time)
** Invoke db:test:prepare (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:test:prepare
** Invoke db:test:clone (first_time)
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
** Execute db:test:clone
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
rake aborted!
SQLite3::SQLException: object name reserved for internal use:
sqlite_autoindex_categories_1: CREATE UNIQUE INDEX
sqlite_autoindex_categories_1 ON categories (name)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract_adapter.rb:120:in
log' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/sqlite_adapter.rb:137:inexecute’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/sqlite_adapter.rb:335:in
catch_schema_changes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/sqlite_adapter.rb:137:inexecute’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:196:in
add_index' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:272:inmethod_missing’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:256:in
say_with_time' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:256:in
say_with_time' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/migration.rb:270:inmethod_missing’
./db/schema.rb:14
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/schema.rb:43:in
define' ./db/schema.rb:5 /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:140:inload’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/tasks/databases.rake:31
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in invoke' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/tasks/databases.rake:72 /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:ininvoke’
/usr/lib/ruby/1.8/thread.rb:135:in synchronize' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:ininvoke’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/tasks/databases.rake:139
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:364:ininvoke_prerequisites’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:999:in each' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:363:ininvoke_prerequisites’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:356:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/usr/bin/rake:18

The important part of that error message, of course, being this:

** Execute db:schema:load
rake aborted!
SQLite3::SQLException: object name reserved for internal use:
sqlite_autoindex_categories_1: CREATE UNIQUE INDEX
sqlite_autoindex_categories_1 ON categories (name)

I’ve googled around for this and I can NOT find any information at
all. Simply googling sqlite_autoindex_categories_1 gives absolutely
nothing.

So, what am I missing here? I’m using Ubuntu, and one problem I had
was that Ubuntu only had ruby 1.8.3, where the new rails demanded
1.8.4, so I completely uninstalled all ubuntu ruby packages and
compiled & installed ruby from source. is there some package I’m
missing then? I know one thing that tripped me up was having to
reinstall rubygems, the sqlite3 driver, & etc so maybe there’s some
other dependency that I’m missing? Otherwise I have no idea what’s
going on, aside from some vague notion that rails’ unit tests are
doing something that sqlite3 doesn’t like at all.

Otherwise, my site seems to be running fine, but I say “seems” because
it’s not running the unit tests so I don’t know for sure if it’s
running fine or not. I’m not comfortable pushing this to production
until the tests run!

Thanks.

On 5/10/06, Rob P. [email protected] wrote:

** Execute db:schema:load
rake aborted!
SQLite3::SQLException: object name reserved for internal use:
sqlite_autoindex_categories_1: CREATE UNIQUE INDEX
sqlite_autoindex_categories_1 ON categories (name)

Anybody?

On 5/13/06, Rob P. [email protected] wrote:

On 5/10/06, Rob P. [email protected] wrote:

** Execute db:schema:load
rake aborted!
SQLite3::SQLException: object name reserved for internal use:
sqlite_autoindex_categories_1: CREATE UNIQUE INDEX
sqlite_autoindex_categories_1 ON categories (name)

Anybody?

Alright, I played around with this some more, and I finally got it
“working” by brute force.

The problem is due to rails trying to create the unique index where
sqlite3 (I’m assuming) already does that on it’s own, so essentailly
rails was trying to create an index that was already automatically
created.

My “fix” was to go through the entire database and remove all the
unique indexes, figuring that rails will handle the unique constraint
anyway, that it doesn’t need to be in the db as well. Now the tests
pass and everything is looking good.