Forum: Ruby on Rails Unit tests fail with sqlite3 and rails 1.1

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rob P. (Guest)
on 2006-05-11 09:40
(Received via mailing list)
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:in
`execute'
/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:in
`execute'
/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:in
`method_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:in `measure'
/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:in
`method_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:in
`load'
/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:in `execute'
/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:in `synchronize'
/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:in `execute'
/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:in `invoke'
/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:in `invoke'
/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:in `execute'
/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:in `synchronize'
/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:in
`invoke_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:in
`invoke_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:in `synchronize'
/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:in `run'
/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.
Rob P. (Guest)
on 2006-05-13 10:46
(Received via mailing list)
On 5/10/06, Rob P. <removed_email_address@domain.invalid> 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?
Rob P. (Guest)
on 2006-05-13 21:15
(Received via mailing list)
On 5/13/06, Rob P. <removed_email_address@domain.invalid> wrote:
> On 5/10/06, Rob P. <removed_email_address@domain.invalid> 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.
This topic is locked and can not be replied to.