我有一个哈希数组,为了论证的缘故,这样:
[{"foo"=>"1", "bar"=>"1"}, {"foo"=>"2", "bar"=>"2"}]
Run Code Online (Sandbox Code Playgroud)
使用Rspec,我想测试"foo" => "2"数组中是否存在,但我不在乎它是第一项还是第二项.我试过了:
[{"foo" => "1", "bar" => "2"}, {"foo" => "2", "bar" => "2"}].should include("foo" => "2"))
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为哈希应该完全匹配.有没有办法部分测试每个哈希的内容?
我在从 Azure DevOps 中的另一个管道触发管道时遇到问题。我有一个 CI 管道,我想在 CI 通过主分支时触发一个部署管道。这在技术上似乎是可行的,但文档不清楚。
我看到以下内容:
# this is being defined in app-ci pipeline
resources:
pipelines:
- pipeline: securitylib
source: security-lib-ci
trigger:
branches:
- releases/*
- master
Run Code Online (Sandbox Code Playgroud)
但不清楚 a) 这是否进入触发管道(在我的情况下为 CI 管道)或触发管道(在我的情况下为部署管道)。
也不清楚 thepipeline和source指的是什么,以及我如何找出这些变量?它们都是管道的名称吗?我尝试了各种不同的排列,但似乎没有任何效果。
我正在使用Twitter Bootstrap typeahead库的这个分支,它允许异步数据源以及onselect事件.到目前为止,它对我来说非常好用,但是当用户选中该字段时(即没有主动选择下拉条目),会激活onselect事件(在我的情况下,将用户重定向到另一个页面).如果用户没有点击,有什么方法可以阻止onselect事件被触发?这是我到目前为止所得到的(在CoffeeScript中):
$(document).ready ->
$('#inspection_name').typeahead(
source: (typeahead, query) ->
$.ajax(
url: "/inspections/search.json?name="+query
success: (data) =>
return_list = []
$(data.results.inspections).each ->
return_list.push("<span data-url='" + this.uri + "/edit'>" + this.name + ", " + this.town + "</span>")
typeahead.process(return_list)
)
onselect: (obj) =>
window.location.href = $(obj).attr("data-url")
)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用jQuery的slideToggle函数来显示或隐藏使用CSS位置隐藏的面板,而不是display:none(因为这会导致我的某个面板中的Google Map出现问题).
目前我只是隐藏并显示这样的面板,但有些动画会很好:
$('.panel').addClass('hidden');
$('.head > span').addClass('closed');
$('.head').click(function() {
$(this).next('.panel').toggleClass('hidden');
$(this).children('span').toggleClass('open');
});
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
对于我们组织的仪表板,我想保留所有存储库中所有开放PR的计数.目前,我所拥有的只是循环遍历所有的回购,并计算每个回购中的所有打开的PR,如此(这通常会导致速率限制错误):
connection = Github.new oauth_token: MY_OAUTH_TOKEN
pulls = 0
connection.repos.list(:org => GITHUB_ORGANISATION).each do |repo|
pulls += connection.pull_requests.list(:user => repo['owner']['login'], :repo => repo['name']).count
end
Run Code Online (Sandbox Code Playgroud)
我知道必须有一个更好的方法围绕这个.有任何想法吗?(除了屏幕刮擦!)
我正在使用带有HTTParty的Buffer App API尝试通过/ updates/create方法添加帖子,但是API似乎忽略了我的"text"参数并引发了错误.如果我在命令行上通过cURL这样做,它可以很好地工作.这是我的代码:
class BufferApp
include HTTParty
base_uri 'https://api.bufferapp.com/1'
def initialize(token, id)
@token = token
@id = id
end
def create(text)
BufferApp.post('/updates/create.json', :query => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
end
end
Run Code Online (Sandbox Code Playgroud)
我正在运行这样的方法:
BufferApp.new('{access_token}', '{profile_id}').create('{Text}')
Run Code Online (Sandbox Code Playgroud)
我已经添加debug_output $stdout到课程中,它似乎发布好了:
POST /1/updates/create.json?text=Hello%20there%20why%20is%20this%20not%20working%3F&profile_ids[]={profile_id}&access_token={access_token} HTTP/1.1\r\nConnection: close\r\nHost: api.bufferapp.com\r\n\r\n"
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误.我错过了什么吗?
我正在通过Google Drive Ruby gem使用Google Drive API并使用VCR来记录请求。
我正在通过 JWT 进行身份验证,并希望过滤掉 JWT 请求和返回的不记名令牌。
由于我不知道 Google 在运行时给我的 JWT 令牌或不记名令牌,因此我无法使用filter_sensitive_data. 因此,在测试运行后,我需要过滤以下乱七八糟的代码,以便对我的磁带进行消毒:
after(:each) do |example|
# Filter out JWT and bearer tokens from requests
if VCR.current_cassette.recording?
interactions = VCR.current_cassette.new_recorded_interactions
# Remove JWT token
interactions.first.request.body.gsub! /(?<=assertion\=).*/, '<JWT_TOKEN>'
# Get and replace access token from body
body = JSON.parse(interactions.first.response.body)
access_token = body['access_token']
body['access_token'] = '<ACCESS_TOKEN>'
interactions.first.response.body = body.to_json
# Replace access token in each auth request
interactions.drop(1).each do |i|
i.request.headers['Authorization'][0].gsub!(access_token, '<BEARER_TOKEN>') …Run Code Online (Sandbox Code Playgroud) 我一直在使用wicked_pdf在Rails中生成一些PDF,并且它在我的开发环境中工作正常,但是当我尝试在我的生产环境中生成一个错误时,我得到500错误(但我的日志中没有特定错误).我注意到的第一件事是wkhtmltopdf二进制文件位于我的生产盒上的不同位置,所以我将以下内容添加到我的wicked_pdf.rb初始化程序中:
if Rails.env == "production"
WickedPdf.config = {
:exe_path => '/usr/bin/wkhtmltopdf'
}
end
Run Code Online (Sandbox Code Playgroud)
这是我在控制器中调用它的方式:
def certificate
@inspection = Inspection.find(params[:id])
@council = Council.find(@inspection.councilid)
respond_to do |format|
format.pdf do
render :pdf => @inspection.slug,
:show_as_html => params[:debug].present?,
:margin => {:top => 0,
:bottom => 0,
:left => 0,
:right => 0}
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的观点的内容:
# certificate.pdf.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {
margin: 0;
padding: 0; …Run Code Online (Sandbox Code Playgroud) ruby ×5
javascript ×2
animation ×1
arrays ×1
azure ×1
azure-devops ×1
buffer ×1
coffeescript ×1
github ×1
github-api ×1
hash ×1
httparty ×1
jquery ×1
rspec ×1
typeahead ×1
vcr ×1
wicked-pdf ×1