如何测试Rails 4.x中不存在路由(How to test that a route does not exist in Rails 4.x)
如果我有一个未定义的路由,我该如何测试它返回404?
这是routes.rb的相关部分
resources :reservations, only: [:index,:create,:destroy]
您可以创建,销毁和列出预订,但不能更改它们。
那么测试是:
patch :update, id: @reservation, reservation: { somefield: "data" } assert_response :missing
这应该通过,因为缺少路由应返回404.相反,我得到一个UrlGenerationError:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"reservations", :id=>"980190962", :reservation=>{:somefield=>"data"}}
我知道了; 来自测试的
patch
调用无法生成URL。 那么如何测试这样的URL调用会产生404?If I have a route not defined, how do I test that it returns a 404?
Here is the relevant part of routes.rb
resources :reservations, only: [:index,:create,:destroy]
You can create, destroy and list reservations, but not change them.
The test then is:
patch :update, id: @reservation, reservation: { somefield: "data" } assert_response :missing
This should pass, since the lack of a route should return a 404. Instead, I get a UrlGenerationError:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"reservations", :id=>"980190962", :reservation=>{:somefield=>"data"}}
I get it; the
patch
call from the test cannot generate a URL. So how do I test that such a URL call would generate a 404?
原文:https://stackoverflow.com/questions/30262023
最满意答案
无论你用于聊天(轨道,websockets?)应该能够检测会话超时。
Whatever you're using for chat (orbited, websockets?) should be able to detect a session timeout.
相关问答
更多-
你试过这个代码吗 window.onbeforeunload = function (event) { var message = 'Important: Please click on \'Save\' button to leave this page.'; if (typeof event == 'undefined') { event = window.event; } if (event) { event.returnValue = ...
-
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); if($.browser.chrome){ ............ } 更新:(10x到@Mr。Bacciagalupe) jQuery已经从1.9及其最新版本中删除了$.browser 。 但是,您仍然可以使用$ .browser作为独立插件,在这里找到 $.browser.chrome = /chrom(e|ium)/.test(naviga ...
-
如果我让你正确,你想知道一个标签/窗口何时被有效地关闭。 那么,AFAIK是Javascript唯一的方式来检测这种东西是onunload和onbeforeunload事件。 不幸(或者幸运的是),当您通过link或浏览器返回按钮离开网站时,这些事件也会被触发。 所以这是我可以给出的最好的答案,我不认为你可以在Javascript中本机检测到一个纯粹的close 。 纠正我,如果我错了这里。 If I get you correctly, you want to know when a tab/window ...
-
jQuery 1.6浏览器检测(jQuery 1.6 Browser detection)[2023-10-28]
你想避免浏览器检测,而是做功能detection.browser检测可以很容易伪造,因此是不可靠的。 John Resig在这个问题上发表了一篇不错的文章 。 有关更多详细信息,Google针对“ 浏览器检测与功能检测 ” You want to avoid browser detection & instead do feature detection.browser detection can be easily faked & therefore is unreliable. see a nice p ... -
通过jquery获取浏览器名称(Get browser name by jquery)[2022-10-17]
请参考以下链接,它可能会对您有所帮助。 http://pupunzi.open-lab.com/2013/01/16/jquery-1-9-is-out-and-browser-has-been-removed-a-fast-workaround/ Please refer below link, it might help you. http://pupunzi.open-lab.com/2013/01/16/jquery-1-9-is-out-and-browser-has-been-removed-a ... -
您可以使用client.sessions()检查会话是否仍然存在。 你可以用这个 describe('check if session still exist', function() { it('should check if session still exist', function() { return browser.sessions().then(function(sessionid){ var id1 = sessionid console.log(id1); ...
-
寻找一个jquery插件来调整/扩大浏览器,如果太小?(Looking for a jquery plugin to resize/expand browser if too small? [closed])[2023-10-23]
不要这样做 ,大多数浏览器都会阻止这种情况的发生,理由很充分。 你想让我把你的电子邮件客户端扩展到两个显示器上,这样你就无法工作了吗? 为什么应该以不同的方式处理网络浏览器? 有些决定是针对用户的,这绝对是其中之一。 用户期望浏览网页,做这样的事情打破了这些期望。 如果我在Chrome中打开了20个选项卡(并且经常在几个窗口中打开),我不希望您的站点调整其他19个选项。但是,它确实使我想用沙拉叉狩猎您并将其刺入您的眼。 Don't do this, most browsers prevent this fr ... -
无论你用于聊天(轨道,websockets?)应该能够检测会话超时。 Whatever you're using for chat (orbited, websockets?) should be able to detect a session timeout.
-
您可以在HTML中使用此标记: 参考 。 You can use this mark-up in your HTML: Refere ...
-
如何在jQuery中使用webkit的浏览器上检测空闲状态(How to detect idle state on the browser which use webkit in jQuery)[2022-04-30]
我现在找到了它的解决方案。 在idle-timer.js中,我将其更新为以下1 /搜索以下代码 var idle = false, //indicates if the user is idle tId = -1, //timeout ID enabled = false, //indicates if the idle timer is enabled timeout = 30000; ...