我将 Spring 4.3.8.RELEASE 与 JUnit 4.12 和 Mockito 1.10.18 一起使用。我有一个发布事件的服务......
@Service("organizationService")
@Transactional
public class OrganizationServiceImpl implements OrganizationService, ApplicationEventPublisherAware
publisher.publishEvent(new ZincOrganizationEvent(id));
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher)
{
this.publisher = publisher;
}
...
@Override
public void save(Organization organization)
{
...
publisher.publishEvent(new ThirdPartyEvent(organization.getId()));
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何在 JUnit 测试中验证事件是否已实际发布?
@Test
public void testUpdate()
{
m_orgSvc.save(org);
// Want to verify event publishing here
Run Code Online (Sandbox Code Playgroud) 我将 RoR 5.0.1 与 PostGres 9.5 一起使用。我有以下查询根据日期从特定表(由相应模型表示)中获取不同记录
select distinct on (crypto_currency_id) t.*
from crypto_prices t
order by crypto_currency_id, last_updated desc;
Run Code Online (Sandbox Code Playgroud)
我的模型名称是 CryptoPrice,但我不清楚如何将上述转换为 finder 方法。这个
CryptoPrice.distinct.pluck(:crypto_currency_id)
Run Code Online (Sandbox Code Playgroud)
不做同样的事情,正如我发现的那样。
我正在使用 d3 v4。我想将表格移出我的饼图,让它们指向饼图(因为对于小楔子,无法读取标签)。我认为这会添加外部标签
// Now we'll draw our label lines, etc.
enteringLabels = labels.selectAll(".label").data(data).enter();
labelGroups = enteringLabels.append("g").attr("class", "label");
labelGroups.append("circle").attr({
x: 0,
y: 0,
r: 2,
fill: "#000",
transform: function (d, i) {
centroid = pied_arc.centroid(d);
return "translate(" + pied_arc.centroid(d) + ")";
},
'class': "label-circle"
});
Run Code Online (Sandbox Code Playgroud)
但标签没有出现在外部 - https://jsfiddle.net/2df75xj0/1/。我还需要做什么来外部化标签?
我正在使用Rails 5.我有这个文件,config/environment_variables.yml
development:
COINBASE_KEY: devkey
COINBASE_SECRET: devsecret
test:
COINBASE_KEY: testkey
COINBASE_SECRET: testsecret
production:
COINBASE_KEY: prodkey
COINBASE_SECRET: prodsecret
Run Code Online (Sandbox Code Playgroud)
我用文件config/initializers/environment_variables.rb加载它
module EnvironmentVariables
class Application < Rails::Application
config.before_configuration do
env_file = Rails.root.join("config", 'environment_variables.yml').to_s
if File.exists?(env_file)
YAML.load_file(env_file)[Rails.env].each do |key, value|
ENV[key.to_s] = value
end # end YAML.load_file
end # end if File.exists?
end # end config.before_configuration
end # end class
end # end module
Run Code Online (Sandbox Code Playgroud)
但是当我使用我的测试时
rails test test/services/crypto_currency_service_test.rb
Run Code Online (Sandbox Code Playgroud)
测试变量没有加载 - 而是来自开发环境的加载.下面是我的测试文件
require 'coinbase/wallet'
require 'minitest/mock'
class CryptoCurrencyServiceTest < ActiveSupport::TestCase
test 'sell' do
last_transaction = …Run Code Online (Sandbox Code Playgroud) testing ruby-on-rails environment-variables minitest ruby-on-rails-5
我尝试了这里推荐的解决方案——在 Ruby 中,获取数组中最大值索引的最简洁方法是什么?
array = [nil, nil, nil, nil, nil, 0.9655172413793104, nil, nil]
idx = array.each_with_index.max[1]
Run Code Online (Sandbox Code Playgroud)
但我得到了一些例外:
ArgumentError: comparison of Array with Array failed
from (irb):4:in `each'
from (irb):4:in `each_with_index'
from (irb):4:in `each'
from (irb):4:in `max'
from (irb):4
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.3/lib/rails/commands/console.rb:65:in `start'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.3/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Run Code Online (Sandbox Code Playgroud) 我正在使用Ruby 2.4.如何将复杂函数映射到我的字符串数组中的每个元素?功能是
elt.gsub!(/\A\p{Space}+|\p{Space}+\z/, '')
Run Code Online (Sandbox Code Playgroud)
假设"elt"是我的字符串数组中的一个元素.这是一个美化的"条带"功能.我想将它应用于我的数组中的每个项目.
我正在使用Mac High Sierra。我使用以下方法安装了PHP(带有GMP)
brew install php72-gmp
Run Code Online (Sandbox Code Playgroud)
按照给出的消息,一切都安装成功,但是看来我的机器上仍然有旧版本的PHP 7.1,因为运行时
localhost:php-7.2.1 davea$ which php
/usr/bin/php
localhost:php-7.2.1 davea$ /usr/bin/php -v
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Run Code Online (Sandbox Code Playgroud)
因此,我想找出将自制版本的PHP放在PATH中的位置,以便首先获取该版本。
我使用的是 Mac OS 10.13.3。我正在尝试对二进制文件进行 base64 编码,但遇到了一些问题。具体来说,我认为所有 base64 编码文件的长度必须是 4 的倍数。但是,当我对文件进行编码时,请注意长度不能被 4 整除......
localhost:lib davea$ openssl base64 -in myfile.binary -out ~/Downloads/myfile.base64
localhost:lib davea$ ls -al ~/Downloads/myfile.base64
-rw-r--r-- 1 davea staff 93162 May 31 14:22 /Users/davea/Downloads/myfile.base64
Run Code Online (Sandbox Code Playgroud)
另外当我查看base64文件的内容时,我没有看到末尾的传统“=”或“==”,这通常表示填充
localhost:lib davea$ cat ~/Downloads/myfile.base64
...
C9vgMjoKSQYkXMLTrGKRleR558g3bY3VTqlsVvTqZXquCLp4JS4cprTG6N10H0u9
i4pwPrVmSAP2DmE1V7mGwR2e4fiYEWnZjpSbHofpzlUo34yhiQ2/5kJoQZktD7BU
uxYBAgQIECBAgBs2
Run Code Online (Sandbox Code Playgroud)
我做错了什么,还是有其他方法可以对我的文件进行 base64 编码?
我正在使用Django和Python 3.7.我使用PyCharm创建了一个项目,它创建了以下目录结构(一些自定义添加是我自己的):
mainpage
__init__.py
__pycache__
admin.py
apps.py
fixtures
management
migrations
models.py
services.py
templates
mainpage
trending.html
tests.py
urls.py
views.py
mainpage_project
__init__.py
__pycache__
settings
wsgi.py
manage.py
templates
venv
Run Code Online (Sandbox Code Playgroud)
文件"urls.py"如下所示
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('trending', trending, name='trending'),
]
Run Code Online (Sandbox Code Playgroud)
我对"urls.py"应该去哪里以及应该包含什么感到困惑.当我启动我的服务器时,它给我以下错误("ModuleNotFoundError:没有名为'mainpage_project.urls'的模块")...
(venv) localhost:mainpage_project davea$ python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x103096950>
Traceback (most recent call last):
File "/Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File …Run Code Online (Sandbox Code Playgroud) 我正在使用 Django、Python 3.7 和 PostGres 9.5。为了加快特定查询的速度,我想创建这个功能索引,我通常会在 PostGres 中这样做......
CREATE INDEX my_article_idx ON article (regexp_replace(url, '\?.*$', ''))
Run Code Online (Sandbox Code Playgroud)
然而,在 Django 和自动生成的迁移的世界中,我不确定如何在 models.py 文件中注释我的类,以便自动生成这个基于函数的索引。我的模型中的相关字段看起来像这样......
class Article(models.Model):
...
url = models.TextField(default='', null=False)
Run Code Online (Sandbox Code Playgroud) arrays ×2
django ×2
postgresql ×2
python-3.x ×2
ruby ×2
base64 ×1
bash ×1
d3.js ×1
distinct ×1
django-views ×1
encoding ×1
events ×1
finder ×1
homebrew ×1
indexing ×1
junit ×1
label ×1
macos ×1
max ×1
migration ×1
minitest ×1
mockito ×1
path ×1
php ×1
php-7.2 ×1
pie-chart ×1
python ×1
ruby-2.4 ×1
spring ×1
spring-4 ×1
string ×1
strip ×1
svg ×1
testing ×1
url-mapping ×1