是否有可能使用RSpec测试Ruby的警告?
像这样:
class MyClass
def initialize
warn "Something is wrong"
end
end
it "should warn" do
MyClass.new.should warn("Something is wrong")
end
Run Code Online (Sandbox Code Playgroud) 是否可以在rails 3中的habtm关系上使用计数器缓存?
我真的需要它来加速我的应用程序.
我现在有这个脚本.
def r(this)
require this
puts "#{this} is now loaded."
rescue LoadError
puts "The gem '#{this}' is missing."
puts "Should I install it? [y/n]"
data = gets
if data =~ /yes|y/i
puts "Installing #{this}, hold on."
if `gem install #{this}` =~ /Successfully/i
load this
end
else
puts "Okey, goodbye."
end
end
Run Code Online (Sandbox Code Playgroud)
这使得可以动态地需要库.像这样:r "haml".
问题是我无法在安装后加载gem.使用load this或load File.expand_path("~/.irbrc")不工作.
这是一个例子.
>> r "absolutize"
The gem 'absolutize' is missing.
Should I install it? [y/n]
y
Installing absolutize, hold …Run Code Online (Sandbox Code Playgroud) 我的应用程序中的操作缓存到期时遇到了一些问题.
这是我的控制器:
class ToplistsController < ApplicationController
caches_action :songs, cache_path: :custom_cache_path.to_proc
def custom_cache_path
"#{params[:when]}-#{params[:what]}-#{params[:controller]}-#{params[:action]}"
end
def songs
# ...
end
end
Run Code Online (Sandbox Code Playgroud)
我不知何故需要能够重置自定义缓存路径,但我无法弄清楚如何.
我已经尝试过使用这种技术,但没有成功.它看起来像我的缓存引擎Dalli,不支持regexp匹配器.
我在尝试使用此代码时遇到此错误:
expire_fragment(/songs/)
ActiveSupport::Cache::DalliStore does not support delete_matched
我试图使用这行代码进行调试,但它被忽略了.
before_filter only: [:songs]
expire_fragment(custom_cache_path)
end
Run Code Online (Sandbox Code Playgroud)
我正在使用Rails 3.1.0.rc6,Dalli 1.0.5和Ruby 1.9.2.
如果我想引用一个使用markdown的人,我应该把作者放在哪里?
这与自述文件有关,因此我希望它与Stackoverflow的关系非常接近.
TL; DR如何flow从未声明的导入模块中导入类型定义@flow?
流接缝能够从不使用流语法的文件中派生类型(参见示例).
if(Math.random() < 0.5) {
var y = "hello";
} else {
var y = 2;
}
var i = y;
Run Code Online (Sandbox Code Playgroud)
if(Math.random() < 0.5) {
- var y = "hello";
+ var y: number | string = "hello";
} else {
- var y = 2;
+ var y: number | string = 2;
}
-var i = y;
+var i: number | string = y;
Run Code Online (Sandbox Code Playgroud)
它也可以用来列出特定文件中的所有导入flow …
我正在将我的用户重定向到上一页.
这是电影控制器中的更新方法的示例.
def update
@movie = Movie.find(params[:id])
if @movie.update_attributes(params[:movie])
flash[:notice] = "The given movie is now updated."
end
respond_with(@movie, location: :back)
end
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误.
undefined method 'hash_for_back_url' for #<Module:0x00000103eeaaa8>就respond_with行了.
我在Ruby 1.9中使用Rails 3.1 rc1.
在做这样的事情时它起作用.
respond_with(@movie, location: request.referer)
任何人都知道为什么这个:back论点不起作用?
我正在尝试使用Solr搜索一个部分单词,但我无法让它工作.
我在我的schema.xml文件中使用它.
<fieldType name="text" class="solr.TextField" omitNorms="false">
<analyzer type="index">
<tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="15" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.PorterStemFilterFactory"/>
<filter class="solr.WordDelimiterFilterFactory" stemEnglishPossessive="1" splitOnNumerics="1" splitOnCaseChange="1" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="1" preserveOriginal="1"/>
</analyzer>
</fieldType>
Run Code Online (Sandbox Code Playgroud)
搜索die h将无效,但会die hard返回一些结果.添加上述配置后,我重新编制了数据库索引.
这是搜索时的网址和输出die hard.调试器已打开.
这是搜索时的网址和输出die h.调试器已打开.
我正在使用Solr 3.3.这是schema.xml文件的其余部分.
我正在尝试使用rspec 2和rails 3在执行GET请求时传递cookie.
到目前为止我已经尝试了以下内容.
get "/", {}, {"Cookie" => "uuid=10"} # cookies[:uuid] is nil
request.cookies[:uuid] = 10 # request is nil
@request.env["Cookie"] = "uuid=10" # @request is nil
helper.request.cookies[:uuid] # helper is not defined
cookies[:uuid] = 10 # cookies[:uuid] is nil
controller.cookies[:uuid] = 10 # cookies is nil
Run Code Online (Sandbox Code Playgroud)
可能吗?
我不知道为什么,但我不能让这个工作.
var friends = new Backbone.Collection([
{name: "Athos", job: "Musketeer"},
{name: "Porthos", job: "Musketeer"},
{name: "Aramis", job: "Musketeer"},
{name: "d'Artagnan", job: "Guard"},
]);
friends.where({job: "Musketeer"}).toJSON()
Run Code Online (Sandbox Code Playgroud)
我到了Uncaught TypeError: Object [object Object] has no method 'toJSON'.
我做错了什么以及如何将过滤后的集合转换为JSON?
rspec ×2
ruby ×2
backbone.js ×1
flowtype ×1
irb ×1
javascript ×1
markdown ×1
rspec-rails ×1
rspec2 ×1
rubygems ×1
solr ×1
sunspot ×1
testing ×1
warnings ×1