views:

13

answers:

1

I generated a model file but then chose to let it single table inherit from another model. I had to run no migration, because the columns all were already there.

Now whenever I want to run tests, I get complaints that the table for the model does not exist.

So I have Product < Article < ActiveRecord::Base, product has no own table (does not have it in the schema neither), but still I get

test_should_update_article(ArticlesControllerTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: products: DELETE FROM "products" WHERE 1=1
    AR/active_record/connection_adapters/abstract_adapter.rb:202:in `rescue in log'
    AR/active_record/connection_adapters/abstract_adapter.rb:194:in `log'
    AR/active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
    AR/active_record/connection_adapters/abstract/database_statements.rb:269:in `update_sql'
    AR/active_record/connection_adapters/sqlite_adapter.rb:139:in `update_sql'
    AR/active_record/connection_adapters/abstract/database_statements.rb:274:in `delete_sql'
    AR/active_record/connection_adapters/sqlite_adapter.rb:145:in `delete_sql'
    AR/active_record/connection_adapters/abstract/database_statements.rb:54:in `delete'
    AR/active_record/connection_adapters/abstract/query_cache.rb:16:in `delete'
    AR/active_record/fixtures.rb:551:in `delete_existing_fixtures'
    AR/active_record/fixtures.rb:513:in `block (4 levels) in create_fixtures'
    AR/active_record/fixtures.rb:513:in `each'
    AR/active_record/fixtures.rb:513:in `block (3 levels) in create_fixtures'
    AR/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    AR/active_record/fixtures.rb:512:in `block (2 levels) in create_fixtures'
    AR/active_record/connection_adapters/abstract_adapter.rb:104:in `disable_referential_integrity'
    AR/active_record/fixtures.rb:503:in `block in create_fixtures'
    AS/active_support/benchmarkable.rb:55:in `silence'
    AR/active_record/fixtures.rb:502:in `create_fixtures'
    AR/active_record/fixtures.rb:961:in `load_fixtures'
    AR/active_record/fixtures.rb:926:in `setup_fixtures'
    AS/active_support/callbacks.rb:419:in `_run_setup_callbacks'
    AS/active_support/testing/setup_and_teardown.rb:34:in `run'

AR is a shorthand for /Users/janlimpens/.rvm/AS/ruby-1.9.2-rc2@rails3/AS/activerecord-3.0.0.rc/lib AS for /Users/janlimpens/.rvm/AS/ruby-1.9.2-rc2@rails3/AS/activesupport-3.0.0.rc/lib/

I wonder what I could do...

A: 

Assuming you are using Single Table Inheritance, as Product model inherits from Article Model.

For this to work you need a "type" column in Article Table, which will be filled by "Product" or any other class that inherits Article model.

Add that and the sql query would look like

select * from articles where articles.type = "Product"

Rishav Rastogi
There already is such a column and persisting Products (the type column reads 'Product') works. This query must come from somewhere else...
Jan Limpens
some place which did not automatically learn that product is an article now and not an activerecord::base
Jan Limpens
Hmm.. Some problem with the Test, Can you paste the test code here. as well. Also, when you write controller tests decouple it from models using mocks and stubs :)
Rishav Rastogi