查询参数和assert_generates/assert_routing - 我缺少什么?

2024-05-12

我想我已经介绍了使用查询参数测试路由的排列,但没有一种方法通过。

在我的 paths.rb 中,我有以下内容:

resources :items

然后对于我的功能测试我有:

require 'ruby-debug'
require 'test_helper'

class ItemsControllerTest < ActionController::TestCase
  # Failure: test_assert_generates_using_params_and_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:7]: The generated path <"/items/1/edit"> did not match <"/items/1/edit?q=abc">
  test "assert_generates using params and extras" do
    assert_generates '/items/1/edit?q=abc',
                     { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' },
                     {},
                     { :q => 'abc' }
  end

  # Failure: test_assert_generates_using_only_params(ItemsControllerTest) [test/functional/items_controller_test.rb:15]: found extras <{:q=>"abc"}>, not <{}>
  test "assert_generates using only params" do
    assert_generates '/items/1/edit?q=abc',
                     { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' }
  end

  # Failure: test_assert_generates_using_using_only_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:21]: found extras <{}>, not <{:q=>"abc"}>
  test "assert_generates using using only extras" do
    assert_generates '/items/1/edit?q=abc',
                     { :controller => 'items', :action => 'edit', :id => '1' },
                     {},
                     { :q => 'abc' }
  end

  # Failure: test_assert_routing_using_params_and_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:29]: The generated path <"/items/1/edit"> did not match <"/items/1/edit?q=abc">
  test "assert_routing using params and extras" do
    assert_routing '/items/1/edit?q=abc',
                     { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' },
                     {},
                     { :q => 'abc' }
  end

  # Failure: test_assert_routing_using_only_params(ItemsControllerTest) [test/functional/items_controller_test.rb:37]: found extras <{:q=>"abc"}>, not <{}>
  test "assert_routing using only params" do
    assert_routing '/items/1/edit?q=abc',
                     { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' }
  end

  # Failure: test_assert_routing_using_using_only_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:43]: found extras <{}>, not <{:q=>"abc"}>  
  test "assert_routing using using only extras" do
    assert_routing '/items/1/edit?q=abc',
                     { :controller => 'items', :action => 'edit', :id => '1' },
                     {},
                     { :q => 'abc' }
  end
end

我本希望 *_using_params_and_extras 测试能够通过 - 我错过了什么?


也许你已经明白了这一点。我今天遇到了同样的问题,直到我发现这个问题,注意到额外选项的存在,最后再次阅读了assert_routing的文档。您必须从 url 中删除 q=abc 并将其放入 extras 哈希和 options 哈希中。

所以尝试这样的事情:

assert_routing(
  'items/1/edit',
  {:controller => 'items', :action => 'edit', :id => '1', :q => 'abc'},
  {},
  {:q => 'abc'}
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

查询参数和assert_generates/assert_routing - 我缺少什么? 的相关文章

随机推荐

  • void、VOID、C 和 C++

    我有以下代码 typedef void VOID int f void int g VOID 它在 C 中编译得很好 在 Fedora 10 上使用 gcc 4 3 2 编译为 C 的相同代码给出以下错误 void c 3 error
  • 使用 JPype - 如何访问 JDBC 元数据函数

    我在用着杰 德贝API https launchpad net jaydebeapi它使用 JPype 加载 FileMaker 的 JDBC 驱动程序并提取数据 但我也希望能够获取所有表的列表在数据库中 In the JDBC 文档 ht
  • 动态 SQL 和 where case 哪个更好?

    我需要创建一个带有 12 个参数的存储过程 并使用这些参数的不同组合来过滤查询 所有 12 个参数都不是强制性的 就好像我传递 3 5 或 12 个参数取决于用户输入的搜索输入一样 我可以通过两种方式创建 即使用动态 SQL 查询或使用 C
  • C#.NET 将解决方案中各个项目的 settings.settings 文件编译为 1 个配置文件

    我有一个解决方案 其中一个项目是业务层 另一个项目是Web前端 其中有BL项目作为参考 它们每个都有自己的 settings settings 文件 但在构建时 BL 配置文件不会复制到 bin 目录中 我们之前解决这个问题的方法是将 BL
  • Google App Engine 实例未启动

    我有一个 GAE 申请 通常 当我部署应用程序的某个版本时 几乎会自动为其创建一个实例 但有时 GAE 不会启动新实例 我可以等24小时 但什么也没发生 我必须多次部署相同的版本 直到最终 GAE 为其创建一个实例 坦率地说 这很烦人 这种
  • 从 DecorView@2da7146[MyActivity] 中找不到 ViewTreeLifecycleOwner

    从撰写更新后alpha 11 to alpha 12 or beta 01 每当我打开具有撰写视图的活动或片段时 我都会遇到此崩溃 我在用AppCompatActivity它实现了LifecycleOwner 所以这非常奇怪 java la
  • 为什么 Windows 批处理文件“exit”不能与“||”一起使用?

    批处理 命令脚本中的通常建议是使用exit b设置时退出ERRORLEVEL来指示错误 然而这与 CMD 的配合不太好 and 运营商 如果我在 CMD 命令行运行这些 C gt echo exit b 1 gt foo cmd C gt
  • Firefox 中的文件下载对话框

    我正在使用firefox进行selenium python编程 自动开始下载并保存文件 我已经完成了所有操作 但无法下载csv文件 我的python版本是2 6 6 我的selenium版本是最新版本 我也尝试使用以下链接 即 fp web
  • “AnonymousUser”对象不可迭代

    if not request user is authenticated return None try return ClientProfile objects get user request user except ClientPro
  • solr + haystack + django 我在哪里放置 schema.xml?

    我刚刚安装Solr and Haystack for a Django我正在做的项目 下列的this http docs haystacksearch org dev tutorial html Haystack教程 我创建了一个 sche
  • Ocaml 模块和包的区别

    我基本上是在尝试遵循这篇文章中的 stackoverflow 答案 OCaml 中 HttpRequest 的最佳模块是什么 https stackoverflow com questions 14134116 what is the be
  • ASP.NET MVC 6 中的属性路由正则表达式约束错误

    我添加以下路由属性 HttpGet Route add Route id int inn regex 0 9 incBalance range 0 1 dateSet datetime dateNext datetime public IA
  • Leiningen 在构建可用的 uberjar 时遇到问题

    我们正在尝试与 Leiningen 一起构建我们的 Clojure 项目 我们通过执行以下操作成功创建了 uberjar 前提条件 project clj 文件列出了依赖项 main my project core在项目 clj中 core
  • 归一化互相关的基础知识

    我正在尝试使用范数校正2 归一化互相关 http en wikipedia org wiki Cross correlation Normalized cross correlation 来自 MATLAB 用于计算发育中胚胎中移动形状的速
  • 获取行名以 ABC111 开头的所有行

    我们有以下数据框 col1 col2 col3 ABC111001 12 12 13 ABC111002 3 4 5 ABC000111 7 6 1 ABC000112 9 23 1 如何获取行名以 开头的所有行ABC111 如下 ABC1
  • 使用 OAuth 的 Vkontakte API 不适用于验证码

    Vkontakte API 拒绝使用验证码的请求 这就是我所做的例子 在第三个请求之后我得到 验证码错误 14 需要验证码 根据添加就足够了captcha sid and captcha key参数到原始请求并重复请求 但回应依然是Capt
  • PowerShell 和 StringBuilder

    我是 PowerShell 新手 但熟悉 NET 类 我在用System Text StringBuilder在 PowerShell 脚本中 脚本是这样的 Function MyStringFunc String line r New O
  • 英镑符号在商店中显示为未知字符

    对于商店中每次出现的英镑符号 我都会看到一个 黑色菱形中的问号符号 谷歌搜索得到了字符集的建议 我的设置为 utf 8 如下 我相信这家商店最初是在 Os commerce 中开设的 在货币表中 我使用了 pound 的 ascii 代码
  • 安全转义表名/列名

    我在 php 中使用 PDO 因此无法使用准备好的语句转义表名或列名 以下是我自己实现它的万无一失的方法 tn str replace REQUEST tn column str replace REQUEST column sql SEL
  • 查询参数和assert_generates/assert_routing - 我缺少什么?

    我想我已经介绍了使用查询参数测试路由的排列 但没有一种方法通过 在我的 paths rb 中 我有以下内容 resources items 然后对于我的功能测试我有 require ruby debug require test helpe