在我的一个rspec测试中,我正在从同一个工厂定义创建多个对象
例如
FactoryBot.create(:model_1)
FactoryBot.create(:model_1)
FactoryBot.create(:model_1)
Run Code Online (Sandbox Code Playgroud)
是否有一种方法factory_bot可以在一行中完成此操作
我知道我能做到
3.times {FactoryBot.create(:model_1)}
Run Code Online (Sandbox Code Playgroud)
但我正在寻找factory_bot能够创建相同模型的多个对象的东西.
是否有Mercurial相当于git pull --rebase?
我在我的工厂里有两个特性,我希望在创建对象时包含其中一个特征,而不是默认为一个(因此随机选择特征).这是我正在做的事情:
FactoryGirl.define do
factory :follow_up do
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
phone { Faker::PhoneNumber.cell_phone.gsub(/[^\d]/, '').gsub(/^1/, '2')[0..9] }
email { Faker::Internet.email }
email_preferred true
consent false
if [1, 2].sample == 1
by_referral
else
by_provider
end
trait :by_referral do
association :hospital
association :referral
source { FollowUp::REFERRAL}
end
trait :by_provider do
association :provider
source { FollowUp::PROVIDER }
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是,它似乎忽略了if语句并直接转向by_provider trait.谁知道我怎么做?
我有一个Windows服务器,我们运行一些项目管理服务.我通常将远程桌面放入其中来管理服务.
该服务变得非常慢,文档说不建议在VM上运行该服务.
现在我怎么知道Windows安装是否在VM上运行?
我正在使用ElasticSearchJava客户端来查询弹性搜索.我每次打电话时都在初始化传输客户端.这是正确的方法还是应该在应用程序启动期间初始化一次并在关闭时关闭它.
以下是初始化客户端的代码
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", Config.getEsClusterName()).put("client.transport.ignore_cluster_name", true).build();
Client esClient = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(Config.getEsHost(), Config.getEsPort()));
Run Code Online (Sandbox Code Playgroud) 我从控制台发出以下curl请求来测试我的一个REST API
curl -X GET "http://localhost/api/v1/user/search.json?search_model[first_name]=abc&auth_token=xyzf"
Run Code Online (Sandbox Code Playgroud)
但它失败了以下错误
curl: (3) [globbing] error: bad range specification after pos 58
Run Code Online (Sandbox Code Playgroud)
我用端口封装了,"因为&它用于在控制台中执行珍贵的命令.我还缺少什么?为什么我会收到此错误?
我们的团队最近搬到了Git.我已被烧了几次,因为我的鳕鱼不知何故最终没有像我希望的那样进入开发分支.从那时起,我已经停止删除我每天处理代码的分支,以防我以后需要这些分支.
我现在每天都有许多我不想在SourceTree中查看的分支.但是,我仍然想保存这些分支以防万一.有什么方法可以保存我的旧分支但是将它们放在一边以免污染我的Git存储库?
如果autoflush_log设置为true,是否可能具有高内存利用率?
我有一个像这样的自定义生产环境(暂存)设置
require Rails.root.join("config/environments/production")
Calamus::Application.configure do
config.action_mailer.default_url_options = {:protocol => 'https', :host => xx.xx.xx.xx }
end
Run Code Online (Sandbox Code Playgroud)
这是记录 sql 语句。所以我将日志级别设置为 info
config.log_level = :info
Run Code Online (Sandbox Code Playgroud)
但是添加上面的行导致独角兽进程占用太多内存并且机器在内存上运行得非常高
当我添加这一行时
config.autoflush_log = false
Run Code Online (Sandbox Code Playgroud)
内存利用率恢复正常。任何人都可以看到连接吗?为什么会autoflushing造成内存利用率高?
我添加了项目符号 gem来建议我开发中的任何 N+1 查询(Rails 4.0.2),它建议急切地加载模型的两个父关联,在其中显示其所有记录。
在急切加载这些所属关联之一之前:
Completed 200 OK in 5252ms (Views: 1.8ms | ActiveRecord: 114.1ms)
Run Code Online (Sandbox Code Playgroud)
急切加载后:
Completed 200 OK in 6741ms (Views: 2.1ms | ActiveRecord: 146.0ms)
Run Code Online (Sandbox Code Playgroud)
此外,通过急切加载,浏览器会在控制台显示已完成后挂起,并且在一段时间内(大约 6 秒)不会更新。服务器生产没有这种冻结问题,但在这种情况下,急切加载仍然是一个糟糕的建议。
急切加载会变慢是否有意义?该视图确实访问(预先加载的)父记录。
此外,由于某种原因,子弹宝石不显示调用堆栈。
<% form_ tag user_path(@user), :method => :put do %>
Run Code Online (Sandbox Code Playgroud)
这是我的表单,所以我希望它访问我的UsersController的更新方法,我设置了map.resources:users,以及生成的RESTful路径:
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create",:controller=>"users"}
new_ user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
Run Code Online (Sandbox Code Playgroud)
所以我尝试使用PUT HTTP方法发送到user_path(@user),它返回:
Unknown action
No action responded to 1. Actions: create, destroy, edit, index, logged?, new, show and update
Run Code Online (Sandbox Code Playgroud)
显然我不知道如何做这项工作,所以提前谢谢.
我有一个谷歌图表,点击时会将您带到另一个页面.我想在图表上方悬停时更改光标样式以指示其可点击.我正在听这个onmouseover事件,我在处理程序中有这个代码
$('#div_id path').css("cursor", "pointer")
Run Code Online (Sandbox Code Playgroud)
我可以看到应用于路径元素的样式.但光标不会改变.如何在谷歌图表上悬停时更改光标样式?
我不知道这是FactoryGirl的错误,还是我做错了
我有两个工厂定义
factory :employee do
name "name1"
association :department
end
factory :department do
name "department1"
end
Run Code Online (Sandbox Code Playgroud)
我希望以下内容可以构建员工和部门
FactoryGirl.build(:employee, :name => "employee")
Run Code Online (Sandbox Code Playgroud)
但它构建了员工对象并在数据库中创建了部门.我相信它可以用于一些旧版本的FactoryGirl.
我正在使用factory_girl版本4.2.0.
如何使其构建关联对象而不是创建一个?
这是我在js文件中的ajax调用部分:
$("#sign_submit").click(function(){
email_id = $("#user_email").val();
password = $("#user_password").val();
data = {email: email_id, password: password };
url = user/sign_in';
$.ajax({
url: url,
data: data,
cache: false,
type: "post",
success: function(data){
console.log(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的控制器动作:
def create
@user = User.find_by_email(params['email'])
if @user.nil?
respond_to do |format|
format.json {render :json => {:response => 'User is invalid'} } #how to pass json response here.
end
end
if @user.check_valid_user?(params['password'])
set_dashboard_location
set_current_user(session[:customer_id])
render js: %(window.location.href='#{session["spree_user_return_to"]}')
else
#redirect_to '/' and return
#how to psas json response here. …Run Code Online (Sandbox Code Playgroud) factory-bot ×3
git ×2
rest ×2
rspec ×2
ajax ×1
autoflush ×1
conditional ×1
console ×1
curl ×1
forms ×1
git-branch ×1
git-rebase ×1
java ×1
jquery ×1
logging ×1
mercurial ×1
mousehover ×1
production ×1
rails-bullet ×1
ruby ×1
unicorn ×1
windows ×1