我遵循Rails 4.1.1的指南http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures,并在https://github.com/codetriage/codetriage项目中相互使用命名的固定装置。但是,当我试图从另一个夹具引用时,它不起作用:
# fixtures/issues.rb
issue_triage_sandbox_issue:
id: 4
comment_count:
url: https://api.github.com/repos/bemurphy/issue_triage_sandbox/issues/1
last_touched_at: 2012-11-10 22:20:24.000000000 Z
number: 1
created_at: 2012-11-10 23:23:45.281189000 Z
updated_at: 2012-11-10 23:23:45.281189000 Z
repo: issue_triage_sandbox
title: first test issue in sinatra
html_url: https://github.com/sinatra/sinatra/issues/1
state: open和
# fixtures/users.rb
issue_triage_sandbox:
id: 1
user_name: bemurphy
name: issue_triage_sandbox
full_name: bemurphy/issue_triage_sandbox
language: ruby
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1您可以看到问题应该是加载回购issue_triage_sandbox回购。但在我的测试中不是:
issue = issues(:issue_triage_sandbox_issue)
puts issue.repo
# => nil
puts issue.inspect
#<Issue id: 4, comment_count: nil, url: "https://api.github.com/repos/bemurphy/issue_triage...", repo_name: nil, user_name: nil, last_touched_at: "2012-11-10 22:20:24", number: 1, created_at: "2012-11-10 23:23:45", updated_at: "2012-11-10 23:23:45", repo_id: 915227508, title: "first test issue in sinatra", html_url: "https://github.com/sinatra/sinatra/issues/1", state: "open", pr_attached: false> 有什么想法吗?为什么这个问题是通过引用一个不存在的回购而产生的?
发布于 2014-06-02 01:59:49
我认为它必须使用repos夹具中的id属性。我用的是yml装置。我把这个问题和回购问题加到了项目中现有的问题上。
issues.yml
issue_triage_sandbox:
user_name: bemurphy
name: issue_triage_sandbox
full_name: bemurphy/issue_triage_sandbox
language: ruby
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1repos.yml
issue_triage_sandbox:
user_name: bemurphy
name: issue_triage_sandbox
full_name: bemurphy/issue_triage_sandbox
language: ruby
created_at: 2012-11-10 21:50:48.351554000 Z
updated_at: 2012-11-10 21:50:48.351554000 Z
issues_count: 1从控制台:
rake db:夹具:load RAILS_ENV=test rails c#测试
irb(main):001:0> i = Issue.last=> #分流.“,repo_name: 0,user_name: 0,last_touched_at:"2012-11-10 22:20:24",数字: 1,created_at:"2012-11-10 23:23:45",updated_at:"2012-11-10 23:23:45",repo_id: 915227508,标题:“sinatra的第一个测试问题”,html_url:"https://github.com/sinatra/sinatra/issues/1",状态:“打开”,pr_attached: false>
irb(main):002:0> i.repo
发布于 2014-06-02 00:59:42
基于项目这里中的代码,Issues似乎属于Repos。我想知道这些固定装置在这种关系中是否有“倒退”的问题。
您可以尝试使用ERB获取适当夹具的ID,并将其应用如下:repo_id: <%= ActiveRecord::FixtureSet.identify(:issue_triage_sandbox) %>
https://stackoverflow.com/questions/23985675
复制相似问题