[英]How can I remove a single route in test environment?
So, I've a test where I create an action on a controller to test certain thing. 所以,我有一个测试,我在控制器上创建一个动作来测试某些东西。 To do this I added the action on my controller and create a route for my action as follows:
为此,我在控制器上添加了操作,并为我的操作创建了一个路由,如下所示:
before do
test_routes = Proc.new do
get 'mocked_action', to: 'custom_controller#mocked_action', as: :mocked_action
end
MyApp::Application.routes.send :eval_block, test_routes
end
Well, how do I remove this route in specific? 好吧,我该如何删除这条路线?
after do
#Remove my temp route here
end
You could switch setting up the temporary routes by using dynamic contraints: http://raysrashmi.com/2014/07/23/rails-routes-constraints/ 您可以使用动态约束来切换设置临时路线: http : //raysrashmi.com/2014/07/23/rails-routes-constraints/
Enabling and disabling through before and after hooks can be done by setting flags etc. In general I wonder if your test setup should be done this way. 可以通过设置标志等来完成挂钩之前和之后的启用和禁用。一般来说,我想知道您的测试设置是否应该以这种方式完成。 In my opinion depending on a user role would be more straight forward.
在我看来,取决于用户角色会更直接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.