使用对象参数和额外ID模拟POST请求(Simulate a POST request with the object parameters and an extra id)
我在ROR应用程序中进行RSpec测试,我需要模拟一个post动作以测试控制器。
正常使用是这样的:
post :candidate, candidate: FactoryGirl.attributes_for(:candidate)
我的问题是我还需要传递来自url的id。 动作网址是这样的:
candidates POST /positions/:id/candidate(.:format) positions#candidate
所以我需要的是这样的:
post :candidate, candidate: FactoryGirl.attributes_for(:candidate), id: position.id
如何使用对象属性和id来模拟发布请求?
在正常使用中,rails服务器中的输出是这样的:
Parameters: {"utf8"=>"✓", "candidate"=>{"first_name"=>"John", "last_name"=>"Doe", "email"=>"john@gmail.com", "phone_number"=>"+351911111111", "skype_id"=>"qwe", "linkedin_url"=>"qwe", "why_work_with_us"=>"qwe", "resume_url"=>"qwe", "portfolio_url"=>"qwe"}, "id"=>"2"}
I'm doing RSpec tests in a ROR application and I need to simulate a post action in order to test a controller.
The normal use is like this:
post :candidate, candidate: FactoryGirl.attributes_for(:candidate)
My problem is that I also need to pass an id that comes from the url. The action url is this one:
candidates POST /positions/:id/candidate(.:format) positions#candidate
So what I need is something like this:
post :candidate, candidate: FactoryGirl.attributes_for(:candidate), id: position.id
How can I simulate a post request with object attributes and also an id?
In the normal use the output in the rails server is this:
Parameters: {"utf8"=>"✓", "candidate"=>{"first_name"=>"John", "last_name"=>"Doe", "email"=>"john@gmail.com", "phone_number"=>"+351911111111", "skype_id"=>"qwe", "linkedin_url"=>"qwe", "why_work_with_us"=>"qwe", "resume_url"=>"qwe", "portfolio_url"=>"qwe"}, "id"=>"2"}
原文:https://stackoverflow.com/questions/32126471
最满意答案
您可以使用Enumerable.Intersect方法从两个列表中获取公共值。
IEnumerable<string> commonValues = projects.Intersect(sheetNames);
You can use Enumerable.Intersect method to get the common values from the two lists.
IEnumerable<string> commonValues = projects.Intersect(sheetNames);
相关问答
更多-
或者在三元运算符中,使用&&(OR in ternary operator, using &&)[2023-07-17]
只需使用括号来防止运算符优先于&& over || (a === 0 || b === 0) && console.log('aloha amigo') 如果没有括号,您将获得(现在显示优先级)不同的结果。 a === 0 || (b === 0 && console.log('aloha amigo')) ^^^^^^^ first evaluation ^^^^^^^^^^^^^^^^^^^^ ... -
c ++三元运算符(c++ ternary operator)[2024-02-03]
A)是的,这是标准的一部分。 B)它没有被广泛认识,尽管它可能在这里。 有一个原因被认为是C ++的隐藏特性:C ++的隐藏特性? 。 C)没有评论。 :) 就我个人而言,我建议您避免使用此功能。 这比使用if / else语句更不直观,显然不是每个人都知道它。 违反我自己的警告,我实际上曾尝试在个人项目中使用过这种方法,并且因错过括号而浪费了30分钟,试图发现错误。 A) Yes, this is part of the standard. B) It's not widely realized, tho ... -
那么,checkstyle是正确的,括号是没有用的执行。 但对于执行而言无用并不意味着对代码的良好读取毫无用处。 如果阅读更有意义,你应该离开它们。 我认为这段代码不需要更多的括号: int number = (myBoolean)? 1 : 2; 但在你的情况下, return关键字和你的布尔值是一个表达式的事实可以改变你阅读语句的方式。 Well, checkstyle is right, the parentheses are useless for the execution. But usele ...
-
h.className = h.className + (h.className ? ' error' : 'error') 您希望操作员为h.className工作,更好地具体说明。 当然, h.className += ' error'不会有任何伤害,但这是另一回事。 另外请注意, +优先于三元运算符: JavaScript运算符优先级 h.className = h.className + (h.className ? ' error' : 'error') You want the operat ...
-
字符串连接是问题,而不是在三元组中使用trim。 $mainJob = ($user->getMainJob() != null) ? "-a-".trim($user->getMainJob()) : null; The string concatentation is the issue, not the usage of trim within a ternary. $mainJob = ($user->getMainJob() != null) ? "-a-".trim($user->getMai ...
-
您可以使用Enumerable.Intersect方法从两个列表中获取公共值。 IEnumerable
commonValues = projects.Intersect(sheetNames); You can use Enumerable.Intersect method to get the common values from the two lists. IEnumerable commonValues = projects.Intersect(sheetName ... -
那样做: a = a > 10 ? 5 : a; 或者干脆: if (a > 10) a = 5; That will do it: a = a > 10 ? 5 : a; or simply: if (a > 10) a = 5;
-
三元运算符和GET条件(Ternary operator and GET condition)[2022-03-11]
$currentPage = (isset($_GET['page']) && $_GET['page'] > 1) ? $_GET['page'] : 1; 采取自由来调整逻辑一点。 请注意,这更难阅读,代码通常比书面阅读更频繁。 $currentPage = (isset($_GET['page']) && $_GET['page'] > 1) ? $_GET['page'] : 1; Taken the liberty to adjust the logic a bit. Please take in ... -
你不只是在做 (true ? $w = 100 xor $r = 200 : $w = 300) xor $r = 400; aren't you just doing (true ? $w = 100 xor $r = 200 : $w = 300) xor $r = 400;
-
三元运算符意外结果(Ternary Operator Unexpected Result)[2024-02-01]
建议与DBNull进行比较,使用DBNull.Value.Equals方法,如本页所述: http : //msdn.microsoft.com/en-us/library/system.dbnull.value.aspx ShipmentId = DBNull.Value.Equals(SQLDataReader["ShipmentId"]) ? 0 : Int32.Parse(SQLDataReader["ShipmentId"].ToString()); It's recommended that ...