My code.. :
after_save :handle_test
private
def handle_test
if parent.try(:is_test)
Resque.enqueue UnpackTestOnS3, parent.id
end
end
我正在尝试制定测试此模型逻辑的最佳方法。
我测试雷斯克是否收到了什么?我测试parent.try(:is_test)
是否属实?如果是这样,那将有点愚蠢,因为在测试本身中,我将不得不存根或update_attribute。这是否太精细而无法测试?我应该只是测试文件是否出现在 S3 上吗?我不确定单元测试实际将某些内容上传到 S3 是否有意义。
所有策略都受到热烈欢迎。
您可以测试在创建或更新模型时有一个作业排队等待解包的事实
it "should enqueue job to unpack test on s3 on creating <model_name>" do
Resque.should_receive(:enqueue).with(UnpackTestOnS3, <parent_id>)
end
it "should enqueue job to unpack test on s3 on updating <model_name>" do
Resque.should_receive(:enqueue).with(UnpackTestOnS3, <parent_id>)
end
it "should not enqueue job to unpack test on s3 when the <model_name>'s parent is not for test" do
Resque.should_not_receive(:enqueue).with(UnpackTestOnS3, <parent_id>)
end