如何使用RSPEC在控制器方法中测试条件重定向
我的控制器中有该方法,
def promotional_sales
redirect_to plans_path and return unless promotional_campaign_active?
config_meta_tags({}, {
title: "Subscription promotion in our website",
description: "Do you want to know more about our website promotions? Stay on top of all promotions and guarantee your discount"
})
if control_flag[:phase] == "captation"
setup_promotional_campaign
render :promotion_3
end
if control_flag[:phase] == "sales"
setup_courage_hotsite
render :hotsite_1
end
end
end
如果将促销活动不活跃并且有效时,请编写一个RSPEC测试,如果重定向Plane_path
将发生。
拜托,您能指导我如何编写此测试?
I have that method in my controller
def promotional_sales
redirect_to plans_path and return unless promotional_campaign_active?
config_meta_tags({}, {
title: "Subscription promotion in our website",
description: "Do you want to know more about our website promotions? Stay on top of all promotions and guarantee your discount"
})
if control_flag[:phase] == "captation"
setup_promotional_campaign
render :promotion_3
end
if control_flag[:phase] == "sales"
setup_courage_hotsite
render :hotsite_1
end
end
end
I would like do write a RSpec test that cover if the redirection to plans_path
is happening when promotional campaign is inactive and if is active goes to the next block.
Please, can you guide me how do I write this test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 redirect_to Matcher。根据您的状况,您可以期望
在促销活动不活动时会重定向吗?
You can use the redirect_to matcher. Based on your condition you can expect response to be redirected or not
when promotional campaign is inactive