所以,关于使用Capybara和RSpec的集成测试,我知道我可以这样做:
page.driver.browser.manage.window.resize_to(x,y)
Run Code Online (Sandbox Code Playgroud)
每如何设置Rspec的(硒)浏览器窗口大小的特定RSpec的测试,但有没有办法在全球范围内做到这一点使每一个被媒体查询测试的影响没有定义呢?
设置:Rails 3.2.18,Postgres
我有两个对象,例如起见,打电话给他们Author,并Article具有以下设置:
class Author
has_many :articles
...
end
class Article
belongs_to :author
class << self
def published_over_one_year_ago
where(arel_table[:published_at].lt(1.year.ago))
end
end
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试查找一年前发布所有相关记录的所有Author记录.这段代码:Article
Author.joins(:article).merge(Article.published_over_one_year_ago)
Run Code Online (Sandbox Code Playgroud)
...返回一年前发布至少一个关联的Author对象,但我只需要记录所有关联记录超过一年的记录.这是可能的arel/ActiveRecord,还是我必须使用原始SQL?Article AuthorArticle
潜在的"工作"SQL解决方案:
query = ERB.new(<<-SQL_END).result(binding)
'author'.id in (
select art.author_id
from articles art
group by art.author_id
having sum(case (art.published_at::date >= current_date) when true then 1 else 0 end) = 0 AND
sum(case(art.published_at::date < current_date) when true …Run Code Online (Sandbox Code Playgroud) 在Rails中创建一个对象时,我想自动从资产目录中为它分配一个库存图像,以后用户可以覆盖它.
因此,我在创建对象时执行以下私有方法:
def save_stock_image
image_path = Dir.glob(<list-of-images-from-directory>).sample
File.open(image_path) do |file|
self.image = file
self.save!
end
end
Run Code Online (Sandbox Code Playgroud)
但是,经过6次RSpec测试后,我开始收到以下错误:
Failure/Error: let(:object) { create(:object) }
Errno::EMFILE:
Too many open files - /tmp/16020130822-36578-q8j9v9.jpg
# ./app/models/object.rb:502:in `block in save_stock_image'
# ./app/models/object.rb:501:in `open'
# ./app/models/object.rb:501:in `save_stock_image'
# ./spec/controllers/object_controller_spec.rb:318:in `block (3 levels) in <top (required)>'
# ./spec/controllers/object_controller_spec.rb:344:in `block (4 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
上述错误在60次测试中约有40次.我已经看了几个SO问题,以及https://github.com/thoughtbot/paperclip/issues/1122和https://github.com/thoughtbot/paperclip/issues/1000.我能找到的最接近的答案是确保文件描述符正在关闭.在我File.open在块中使用之前,我明确地关闭了文件file.close- 这也没有用.
显而易见的是我做错了?有没有更好的方法来完成我想要做的事情?
UPDATE
看起来它与Paperclip上传到S3之前创建的临时文件有关.关闭那些我错过的临时文件有什么东西吗?
我目前有以下代码:
- @alpha = Glossary.find(:all, :order =>"title ASC").group_by{|u| u.title[0]}
- @glossary = Glossary.find(:all, :order =>"title ASC")
- @alpha.each do|a|
%h1= a[0]
- @glossary.each do |g|
%p display stuff
Run Code Online (Sandbox Code Playgroud)
这显示了每个字母下的所有术语表术语,而不仅仅是以字母开头的术语.我尝试过一些东西,但我不确定如何选择正确的东西.
我们有一个 API 端点,可以在其中上传图像文件以及文件名(字符串)和描述(字符串)。
养蜂场/API 蓝图不允许我拥有类似的东西:
+ Request (multipart/form-data)
+ Headers
Authorization: [key]
+ Attributes
+ name (string, required) - A human-readable name of the Catalog Item
+ description (string, optional) - A human readable description of the Catalog Item
+ image (file, optional) - An image file corresponding to the Catalog Item
Run Code Online (Sandbox Code Playgroud)
我得到:
base type 'file' is not defined in the document
有没有办法在 API 蓝图中表示多部分/表单数据(例如上面的内容)?
我目前正在尝试通过基本授权向REST API(Cloudsight)设置POST请求。到目前为止,我的代码是:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://api.cloudsightapi.com/image_requests", true);
xhr.setRequestHeader("Authorization:", "CloudSight [key]");
xhr.setRequestHeader("Content-Type", "http://previews.123rf.com/images/valzann/valzann1412/valzann141200061/34262193-cigarette-end-on-a-white-background-Stock-Photo.jpg");
xhr.send(null);
console.log(xhr.status);
console.log(xhr.statusText);Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,出现错误:Uncaught SyntaxError:无法在'XMLHttpRequest'上执行'setRequestHeader':'Authorization:'不是有效的HTTP标头字段名称。
有人知道代码有什么问题吗?我是Java和API的新手,但是非常感谢您提供答案。(如果有帮助,这里是指向Cloudsight文档的链接:https ://cloudsight.readme.io 我仔细检查了一下,试图找到其他未成功的Authorization HTTP Header Javascript示例。)
我正在尝试为一个非常具体的搜索参数构建一个简单的评论网站,我可以从Google Places API中提取信息.我知道除了Google所说的我之外我无法存储任何信息,而且听起来我只能存储"reference"参数和"id"参数.
在为Google返回的地点创建评论后,我需要存储一些标识符,以便当其他人通过我的网站搜索Google地方信息时,我可以对我的数据库进行AJAX调用,并为该地点提取所有评论.
最终,我的问题是,我应该存储哪个密钥?或两者?
rspec ×2
ruby ×2
api ×1
apiary ×1
apiary.io ×1
apiblueprint ×1
capybara ×1
cloudsight ×1
haml ×1
header ×1
http ×1
javascript ×1
loops ×1
paperclip ×1
postgresql ×1
select ×1
selenium ×1