我正在尝试使用rspec在我的current_user(使用修改的restful_authentication auth解决方案)上存根方法.我完全不确定如何在我的控制器规范中访问此方法.current_user本身不起作用.我需要首先获得控制器吗?我该怎么做呢?
使用rails 2.3.5,rspec 1.3.0和rspec-rails 1.3.2
# my_controller_spec.rb
require 'spec_helper'
describe MyController do
let(:foos){ # some array of foos }
it "fetches foos of current user" do
current_user.should_receive(:foos).and_return(foos)
get :show
end
end
Run Code Online (Sandbox Code Playgroud)
产生
NoMethodError in 'ChallengesController fetches foos of current user'
undefined method `current_user' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1::Subclass_2::Subclass_2:0x7194b2f4>
Run Code Online (Sandbox Code Playgroud) 我正试图在窗口上模拟鼠标点击.我目前的成功如下(我使用的是Python,但它应该适用于一般的win32):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,如果在我手动移动鼠标时发生单击,则光标位置会被抛弃.有没有办法直接将点击发送到给定(x,y)坐标而不将鼠标移动到那里?我尝试了类似下面的东西并没有太多运气:
nx = x*65535/win32api.GetSystemMetrics(0)
ny = y*65535/win32api.GetSystemMetrics(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | \
win32con.MOUSEEVENTF_ABSOLUTE,nx,ny)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP | \
win32con.MOUSEEVENTF_ABSOLUTE,nx,ny)
Run Code Online (Sandbox Code Playgroud) 链接有一个或多个标签,因此首先嵌入标签似乎很自然:
link = { title: 'How would you implement these queries efficiently in MongoDB?'
url: 'http://stackoverflow.com/questions/3720972'
tags: ['ruby', 'mongodb', 'database-schema', 'database-design', 'nosql']}
Run Code Online (Sandbox Code Playgroud)
如何有效地实现这些查询?
如上所述表示链接的想法基于MongoNY演示,幻灯片38.
如何使用检查生日输入的表达式匹配像dd/mm/yyyy这样的格式?以下是我到目前为止所发布的内容,但如果我把它放到99/99/9999那也需要这个!
if (!preg_match("/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/", $cnt_birthday))
{
$error = true;
echo '<error elementid="cnt_birthday" message="BIRTHDAY - Only this birthday format - dd/mm/yyyy - is accepted."/>';
}
Run Code Online (Sandbox Code Playgroud)
如何确保dd仅为01到31,mm为01到12?但我相信如何限制yyyy ...我认为理论9999应该是可以接受的......如果你有更好的主意,请告诉我!
谢谢,刘
可能重复:
在C#中使用三元运算符键入结果
我遇到了这种情况,似乎没有一种自然的方式来返回一个可以为空的int.下面的代码给出了编译错误,因为三元运算符不喜欢null.
public int? userId
{
get
{
int rv;
return int.TryParse(userIdString, out rv) ? rv : null;
}
}
Run Code Online (Sandbox Code Playgroud)
所以你(或只是我)真的必须一路走下去拼出一切:
public int? userId
{
get
{
int id;
if(int.TryParse(userIdString, out id)){
return id;
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:是否有更自然的实例化可空的方式,使三元运算符工作?
如何在Windows 7上将端口xxx上的incomming请求重定向到localhost:yyy?
Development Server(vs 2008)只允许从localhost访问,这不够好.我需要从各种计算机上测试我的应用程序.
Lucene查询vs过滤器?
他们都做类似的事情,如termquery过滤器的术语值,过滤器我猜是有类似的目的.
你什么时候使用过滤器和查询?
今天就开始使用lucene,试图清除概念
以前版本的Internet Explorer在超过2,083个字符的Web地址上出现错误(请参阅http://support.microsoft.com/kb/208427).同时,Firefox,Opera和Safari可以处理至少80,000个.
版本9带来了许多改进.URL长度是其中之一吗?
我有一个简单的问题,我无法通过互联网找到任何地方,如何在C中仅使用标准的lib将UTF-8转换为ASCII(大多数重音字符为相同的字符,无需重音)?我找到了大多数语言的解决方案,但特别是C语言.
谢谢!
编辑:评论的一些人让我仔细检查我需要什么,我夸大了.我只需要一个关于如何创建一个函数的想法:带有重音的char - >没有重音的char.:)
我正在尝试编写一个使用生成器语法生成DateTimes列表的函数:
let dateRange =
let endDate = System.DateTime.Parse("6/1/2010")
let startDate = System.DateTime.Parse("3/1/2010")
seq {
for date in startDate..endDate do
if MyDateClass.IsBusinessDay(date) then yield date
}
Run Code Online (Sandbox Code Playgroud)
但生成器('seq')块无法正确解析.它需要一个时间跨度.虽然生成器语法看起来非常适合我想要做的事情,但除了两个数字之外的任何东西都是非直观的.