0
這裏是我的工廠:Rails/Rspec/Factory girl:記錄不關聯?
FactoryGirl.define do
factory :account do
company 'Example, Inc.'
end
factory :site do
association :account
end
factory :page do
association :site
end
end
和一個簡單的請求,規格:
require 'spec_helper'
describe "Pages" do
before do
@account = Factory(:account)
@site = Factory(:site)
end
it "lets me create a new page" do
visit account_site_pages_path(@account, @site)
page.should have_content('New Page')
end
end
但我得到這個故障:
Failure/Error: visit account_site_pages_path(@account, @site)
ActiveRecord::RecordNotFound:
Couldn't find Site with ID=51 [WHERE (`sites`.account_id = 127)]
# <internal:prelude>:10:in `synchronize'
# ./spec/requests/pages_spec.rb:19:in `block (2 levels) in <top (required)>'
這意味着,網站的工廠不與適當的關聯帳戶,對吧?我猜我錯過了很明顯的東西:D
是的,就是這樣。謝謝! – imderek 2012-03-12 12:22:11