提问人:user1185081 提问时间:11/7/2023 更新时间:11/7/2023 访问量:22
如何使用 RSpec 3.12 检查记录停用?
How to check a record de-activation with RSpec 3.12?
问:
My Playground 控制器并没有真正删除记录,如果有人想要删除 Playground,它会将它们标记为非活动状态:
def destroy
@playground.set_as_inactive(current_login)
respond_to do |format|
format.html { redirect_to playgrounds_url, notice: t('.Success') } #'Playground was successfully deleted.'
format.json { head :no_content }
end
end
其中set_as_inactive方法只是将 is_active 标志设置为 false,并跟踪执行更改的人员。
此功能在应用程序中按预期工作,但是当我尝试在 Playgrounds 请求中测试它时,is_active标志似乎未设置为 false:
describe "DELETE /destroy" do
let(:playground_tbd) { create(:playground) }
it "destroys the requested playground" do
expect {
delete playground_url(playground_tbd)
}.to change(Playground.visible, :count).by(-1)
expect(response).to have_http_status 302
expect(response).to redirect_to(playgrounds_url)
end
it "renders the expected status" do
get playground_url(playground_tbd)
expect(playground_tbd.is_active).to eq(false)
end
end
我的解释:
- playground_tbd是专门为此测试创建的,之后将进行删除
- Playground.visible 仅返回活动的游乐场 - 计数已更改(删除 1 个),这让我认为测试确实有效
- 当我重新加载并检查playground_tbd时,它说is_active是真的?!
我在这里错过了什么?
答: 暂无答案
评论
{Playground.visible.count}
playground_tbd
playground_tbd