Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Old, non-existant database table causes tests to error

I've been trying to run a "truth" unit test, mac_test.rb in the Rails app I've recently been put in charge of. It looks like this:

    require 'test_helper'

    class MacTest < ActiveSupport::TestCase
      # Replace this with your real tests.
      test "the truth" do
        assert true
      end
    end

I've run rake db:test:prepare and I'm trying to run the test using ruby -I test test/unit/mac_test.rb.

However, I get the following abbreviated error output:

    Loaded suite test/unit/mac_test
    Started
    EEEEEEEEEEEEEEE
    Finished in 0.377261 seconds.

      1) Error:
    test_datas(ActionController::IntegrationTest):
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1


      2) Error:
    testjigs(ActionController::IntegrationTest):
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1


      3) Error:
    test_datas(ActionController::TestCase):
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1

    <more errors here>

    15 tests, 0 assertions, 0 failures, 15 errors

All of the 15 errors are similar to the first three - they complain about a missing vendors table. Vendor apparently used to exist - there were some leftover files like vendor_helper and there was also a map.resources :vendor in the routes.rb file. I've deleted the old vendor files and deleted the map.resources :vendor line.

So there is no model, view, controller, test, database table or anything that named vendor/vendors. Using TextMate to search the project (case-insensitive) for "vendor", there was only one occurrence of "vendor" that wasn't in a comment, a log file, the README, or the boot.rb file, and that was in the Capfile. (Which I don't think should affect the tests?)

I've tried using rake db:reset to see if it was some weird database thing, but it's still exploding.

If I try to use rake test:units --trace, (just to get the trace, I don't know how to get the trace with the individual test) I get the abbreviated output:

    ** Invoke test:units (first_time)
    ** Invoke db:test:prepare (first_time)
    ** Invoke db:abort_if_pending_migrations (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute db:abort_if_pending_migrations
    ** Execute db:test:prepare
    ** Invoke db:test:load (first_time)
    ** Invoke db:test:purge (first_time)
    ** Invoke environment 
    ** Execute db:test:purge
    ** Execute db:test:load
    ** Invoke db:schema:load (first_time)
    ** Invoke environment 
    ** Execute db:schema:load
    ** Execute test:units
    /usr/local/bin/ruby -I"lib:test" "/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/auth_code_test.rb" "test/unit/cal_data_test.rb" "test/unit/calibration_test.rb" "test/unit/helpers/auth_codes_helper_test.rb" "test/unit/helpers/jn_macs_helper_test.rb" "test/unit/jn_mac_test.rb" "test/unit/log_entry_test.rb" "test/unit/mac_test.rb" "test/unit/option_test.rb" "test/unit/q_test_test.rb" "test/unit/serial_test.rb" "test/unit/source_test.rb" "test/unit/test_data_test.rb" "test/unit/testjig_test.rb" 
    Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
    Started
    EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    Finished in 1.06271 seconds.

      1) Error:
    test_datas(ActionController::IntegrationTest):
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: vendors: DELETE FROM "vendors" WHERE 1=1

    <more similar errors>

    52 tests, 0 assertions, 0 failures, 52 errors
    rake aborted!
    Command failed with status (1): [/usr/local/bin/ruby -I"lib:test" "/usr/loc...]
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:995:in `sh'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1010:in `call'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1010:in `sh'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1094:in `sh'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1029:in `ruby'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1094:in `ruby'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/testtask.rb:117:in `define'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/testtask.rb:102:in `define'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
    /usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
    /usr/local/bin/rake:19:in `load'
    /usr/local/bin/rake:19

I'm at a loss for how to get this to not explode. Can anyone help me find a way to get Rails to realize that there should no longer be any "vendors"?

Edit: I'm using Rails 2.3.2 and ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0]

like image 522
roris Avatar asked Jun 02 '11 23:06

roris


2 Answers

Check the test folder for a fixture file called vendors.yml. If it's there and you don't have a vendors tabler, you'll get those errors because Rails is, by default, trying to populate your vendors table with data from that file.

like image 61
Brian Hogan Avatar answered Nov 15 '22 20:11

Brian Hogan


It's possible that your {RAILS_ROOT}/db/schema.rb file still has some information in it about that prior vendors table. Information in that file is used to build the test environment. If it does contain vendors table info, you can run a rake db:schema:dump to refresh that file, then try your tests again.

like image 20
Yardboy Avatar answered Nov 15 '22 18:11

Yardboy