Forum: Ruby on Rails SQLite in-memory

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.
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2005-12-23 18:38
(Received via mailing list)
I left ":memory:" in database.yml for testing and the most simple
tests in the Agile book do not work (see trace below for test_truth).
Since that's what comes with the distributed database.yml I suppose
it's me doing something wrong.

Did someone get SQLite ":memory:" working? How does it grab the schema?

-- fxn

% rake test_units
(in /Users/fxn/study/rails/depot)
/usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/
rake-0.6.2/lib/rake/rake_test_loader.rb" "test/unit/
line_item_test.rb" "test/unit/order_test.rb" "test/unit/
product_test.rb" "test/unit/user_test.rb"
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/
rake_test_loader
Started
FFE/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/
errors.rb:94:in `check': cannot rollback - no transaction is active
(SQLite3::SQLException)
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/resultset.rb:76:in `check'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/resultset.rb:68:in `commence'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/resultset.rb:61:in `initialize'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/statement.rb:158:in `execute'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/database.rb:211:in `execute'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/database.rb:186:in `prepare'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/database.rb:210:in `execute'
         from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/
lib/sqlite3/database.rb:620:in `rollback'
          ... 11 levels...
         from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:200:in
`run'
         from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:13:in
`run'
         from /usr/local/lib/ruby/1.8/test/unit.rb:285
         from /usr/local/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/
rake_test_loader.rb:5
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 Dick Davies (Guest)
on 2005-12-24 11:32
(Received via mailing list)
On 23/12/05, Xavier Noria <fxn@hashref.com> wrote:
> I left ":memory:" in database.yml for testing and the most simple
> tests in the Agile book do not work (see trace below for test_truth).
> Since that's what comes with the distributed database.yml I suppose
> it's me doing something wrong.

Lazy guess, but have you tried toggling the

  self.use_transactional_fixtures

setting in

  test/test_helper.rb

?

--
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2005-12-24 12:20
(Received via mailing list)
On Dec 24, 2005, at 11:30, Dick Davies wrote:

> setting in
>
>   test/test_helper.rb
>
> ?

If we set that to false (so actual insertions and deletions are
done), the test tries to delete the products table and fails there,
which seems to suggest that the schema was not created. See output
below.

The piece I think I am missing is how to create the schema in that
database. In files one does it explicitly, but since that database is
created by the testing framework in memory I don't now how it figures
the schema out (I would expect it to run the equivalent of "rake
clone_structure_to_test" behind the scenes), or whether some hook is
provided I don't know about.

If I was right, do you know by any chance what should I do? This in-
memory database for testing looks really handy.

-- fxn

% ruby test/unit/product_test.rb
Loaded suite test/unit/product_test
Started
EE
Finished in 0.079896 seconds.

   1) Error:
test_read_with_fixture_variable_as_instance(ProductTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:
products: DELETE FROM products WHERE 1=1
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/abstract_adapter.rb:88:in `log'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/sqlite_adapter.rb:133:in `execute'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/sqlite_adapter.rb:143:in `delete'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:279:in `delete_existing_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:252:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:252:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/abstract/database_statements.rb:
51:in `transaction'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:251:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/base.rb:831:in `silence'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:244:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:540:in `load_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:496:in `setup_with_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:522:in `setup'

   2) Error:
test_read_with_hash(ProductTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:
products: DELETE FROM products WHERE 1=1
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/abstract_adapter.rb:88:in `log'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/sqlite_adapter.rb:133:in `execute'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/sqlite_adapter.rb:143:in `delete'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:279:in `delete_existing_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:252:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:252:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/abstract/database_statements.rb:
51:in `transaction'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:251:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/base.rb:831:in `silence'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:244:in `create_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:540:in `load_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:496:in `setup_with_fixtures'
     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/fixtures.rb:522:in `setup'

2 tests, 0 assertions, 0 failures, 2 errors
This topic is locked and can not be replied to.