- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Rails 4.2 和 RSpec 3.4。我正在尝试为包含 <%= button_to ... %>
的 View 编写 View 测试删除按钮。我的测试失败并出现此错误:
Failures:
1) projects/show.html.erb get secret project as nondisclosed devcomm user shows the obfuscated name and disclosed user
Failure/Error: <%= button_to "Delete this project and reassign all children to parent", {}, method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger" %>
ActionView::Template::Error:
No route matches {:action=>"show", :controller=>"projects"}
# ./app/views/projects/show.html.erb:13:in `_app_views_projects_show_html_erb___2105827750050220814_23458641445220'
# ./spec/views/projects/show.html.erb_spec.rb:23:in `block (3 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# ActionController::UrlGenerationError:
# No route matches {:action=>"show", :controller=>"projects"}
# ./app/views/projects/show.html.erb:13:in `_app_views_projects_show_html_erb___2105827750050220814_23458641445220'
测试如下:
require 'rails_helper'
RSpec.describe "projects/show.html.erb", type: :view do
fixtures :users, :projects
context "get secret project as disclosed user" do
it "shows the unobfuscated name and disclosed user" do
assign(:user, users(:nondevcomm1))
assign(:project, projects(:secretproject2))
render
expect(rendered).to match "Secret project 2"
expect(rendered).to match "Boo Wah, Another job title"
end
end
context "get secret project as nondisclosed devcomm user" do
it "shows the obfuscated name and disclosed user" do
assign(:user, users(:devcomm1))
assign(:project, projects(:secretproject2))
render ### This is where it fails
expect(rendered).to match "Project 3"
expect(rendered).to match "Boo Wah, Another job title"
end
end
end
第一个测试通过而第二个测试失败的原因是因为第一个测试中的用户是 nondevcomm,并且 View 有一个条件,如果用户是 devcomm,则只显示 button_to。
我找到了 this related StackOverflow question ,但因为导致问题的按钮会删除记录,所以我想将其保留为按钮而不是链接,所以我不能只将其更改为 link_to。
关于如何测试包含 button_to 的 View 有什么想法吗?
最佳答案
我发现了问题。在 View 中,我没有提供要采取行动的对象。我改变了 <%= button_to ... %>
为此,现在我的测试通过了:
<%= button_to "Delete this project and reassign all children to parent", @project, method: "delete", data: { confirm: "Are you sure?" }, class: "btn btn-danger"
%>
关于ruby-on-rails-4 - RSpec 3.4/Rails 4.2 : how to test view containing button_to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37149659/
我注意到 button_to 有一个奇怪的行为。我有一些程式化的按钮。当 button_to 生成时,输入提交字段被放置在按钮元素内。最终发生的是单击按钮的内边缘不会将用户重定向到新页面。用户被迫直接
我目前正在使用 link_to: 'btn' do %> Edit Webcast 但我想对 button_to 做同样的事情,但是 button_to 必须有一个传递给它的第一个标签
我使用此代码允许用户向另一个用户发送邮件: 这给了我以下 html: 还有这位电子邮件之王: 我尝试使用 &body 设置邮件正文,但它不
我试图通过按钮的 onclick 方法调用一个函数。这是代码: "show_back(), return false" %> 但它不起作用,每次我单击按钮时都会出现错误 "没有响应 29
似乎 :class 控制的是父表单的类,而不是按钮本身。 我想将 btn primary 类添加到按钮。 如果我不能直接做,我可以使用表单类和SASS来做吗? (使用@extend 或类似的东西)?
我的代码: 'submit', :class => 'submit'} , {}%> 我想这样结束: 但我得到的是: 如何设置类? 最佳答案 HTML 选项是根据 the documentati
查看此问题演变的更新 在我的网站上,每个用户都有一个仪表板,他/她可以在其中单击一个链接来接受或拒绝请求。根据单击的内容,请求记录随后会使用相关状态进行修补。为了让用户更轻松,我试图将此仪表板嵌入到发
目前,我使用以下代码将params [:id]传递给line_items创建 但是,它会将id参数附加在我不希望button_to进行的url查询上。我想要的是通过隐藏的表单字段传递id参数。我可以
这很愚蠢,但我只是不知道如何设置由Rails button_to创建的输入元素的样式-是的,我已经一遍又一遍地阅读文档并尝试了示例。 这是我的ERB代码: 这将产生以下HTML:
我实现了一个基于 ajax 的按钮,用于在用户的“愿望列表”中添加和删除日历事件。该按钮充当切换开关。如果该事件已在他们的愿望 list 上,则会将其删除;如果没有,则会添加它。 我的问题是,当页面首
一直在尝试设计我的 button_to按钮,但是没有运气。我查看了 CSS 文件并使用了 #button {color:red;} , button {color:red;}和 .button {co
在我看来有这个按钮: 'pages', :action => 'yes', :id => p.id, remote: true}, {class: "yes_button"} %> 在 .css 中
我需要提交并保存一些数据。我需要表单中的一些帖子 ID: def message_post_collection_params params.require(:message_post).pe
我在使用 button_to 设置 Bootstrap 按钮组的样式时遇到了问题。 如上所示,我希望在底部有类似的东西,但目前我在使用“button_to”助手时遇到“4”按钮的问题。 我的代码是这样
我正在尝试将一个类应用到 Rails 3 中由 button_to 生成的表单。 :class 选项设置提交按钮的类,因此 docs告诉我们使用 :form_class 将类应用于表单。 例如 :d
我目前正在使用 ruby on rails 3 中的表单。所以在我的项目表单中,我有一个按钮可以让用户退出该项目。然而,奇怪的是,button_to 标签关闭了我的整个表单,我不能再使用我的提交按
基本上,我试图从 rails button_to 获取下拉按钮,这是通过 ajax 完成的,当有人点击该按钮时,它显示渲染的购物车 通过 ajax 渲染标记。 自举: rails button_t
在我的 Rails 3.2.3 应用程序中,我使用 Ajax 和 jQuery。页面上有一个链接,我想用一个按钮替换它。下面的代码运行完美 "home", :action => "test_meth
编写我的第一个非常简单的 Rails 应用程序,一个简单的管理应用程序,用于跟踪我们一个部门的工作。为人们生成的索引页面上有一个 link_to 来添加一个新人。我试图将其更改为 button_to
我在我的 Rails 应用程序中使用 Bootstrap,我想创建一个按钮组,其中包含一个使用 生成的按钮. 这是我的: "), project_steps_path(@proje
我是一名优秀的程序员,十分优秀!