SQLite in-memory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SQLite in-memory

Xavier Noria
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

_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails
Reply | Threaded
Open this post in threaded view
|

Re: SQLite in-memory

Dick Davies-2
On 23/12/05, Xavier Noria <[hidden email]> 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/
_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails
Reply | Threaded
Open this post in threaded view
|

Re: SQLite in-memory

Xavier Noria
On Dec 24, 2005, at 11:30, Dick Davies wrote:

> On 23/12/05, Xavier Noria <[hidden email]> 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
>
> ?

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

_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails