7

When i run

$rspec "/any_file"

rspec loads in the schema.rb file to setup the database.

My understanding is that when it comes to this line

create_table "queue_classic_jobs", force: true do |t|; end

Rspec runs a

DROP TABLE "queue_classic_jobs"

command.

It trows this error

PG::DependentObjectsStillExist: ERROR:  cannot drop table queue_classic_jobs because 
other objects depend on it (ActiveRecord::StatementInvalid)
DETAIL:  function lock_head(character varying) depends on type queue_classic_jobs
function lock_head(character varying,integer) depends on type queue_classic_jobs
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
: DROP TABLE "queue_classic_jobs"

It looks to me like I have to make rspec

DROP TABLE "queue_classic_jobs" CASCADE

But how?

4

1 回答 1

10

你在运行 Rails >= 4.1 吗?有一个新功能,ActiveRecord 会尝试使您的测试模式与 schema.rb 保持同步,而无需重新加载整个数据库。你可以在这里阅读:http: //guides.rubyonrails.org/4_1_release_notes.html#railties-notable-changes

不幸的是,它不适用于外键:https ://github.com/rails/rails/issues/14708 。您可以通过在 config/environments/test.rb 末尾添加此行来禁用它:

config.active_record.maintain_test_schema = false
于 2014-04-16T15:14:43.603 回答