のために失敗しました。私はそれがどのように影響を受けるのか分かりません。私は次のセットアップでDatabaseCleanerを持っている:RSpecのテストは、私は以下のRSpecのテストを持っている奇妙な理由
config.before(:all) do
DatabaseCleaner.clean_with :truncation # clean DB of any leftover data
Rails.application.load_seed
end
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
[OK]をので、私たちはbinding.pryラインであり、そして我々は、ユーザーが持っている:私たちはget(suggestions_path)
を入力した場合
$ user.inspect
#<User id: 15, organization_id: 1, (...params...)>
ただし、このテストはで失敗しますこのエラー:
$ get(suggestions_path)
Module::DelegationError: User#used_trial? delegated to organization.used_trial?, but organization is nil: User id: 38, email: "[email protected]", organization_id: 16, (...params...) from .../app/models/user.rb:34:in `rescue in used_trial?'
私は再びそれを実行すると、それが正常に動作します:
get(suggestions_path) => 302
ID = 38のこのユーザーは存在しません。そのユーザーはDatabaseCleanerによって削除されたようです。しかし、私はget(suggestions_path)リクエストをした瞬間になぜそれがまだ存在するのか分かりません。私はconfig.cache_classes = false
を試してみましたが、それはまだ失敗
:(
'let(:user)'を 'let!(:user)'に変更した場合、バグは消えますか? –
'user'と' organization'モデルのコードを追加できますか? – VAD