2010-11-25 5 views
0

나는 mongoid, machinist 2pickle을 사용하고 있습니다. 그러나 나는 그 질문이 더 일반적이라고 생각한다.레일, 오이 : 개체와 그 연관을

class Account 
    include Mongoid::Document 
    include Mongoid::Timestamps 

    referenced_in :user 
end 

및 사용자 :

나는 계정 모델이

class User 
    include Mongoid::Document 
    include Mongoid::Timestamps 

    references_one :account 
end 

을 나는 다음과 같은 시나리오는 (내가 reference_one 협회 설정)이 :이 생각

Scenario: Client views his account 
    Given a user with id: "4ceede9b5e6f991aef000007" 
    And the following accounts exist: 
     | user_id      | 
     | 4ceede9b5e6f991aef000007  | 
     ..... 

을 그렇게 좋은 아이디어는 그런 식으로 사용하지 마십시오. 연관성을 가진 객체를 만드는 가장 좋은 방법은 무엇입니까? 피클이라면 좋을거야. 예를 들어 도움이 될 수 있습니다.

답변

2

이 같은 청사진을 설정할 수 있습니다

User.blueprint do 
    name 
    # ... 
end 

Account.blueprint do 
    user 
    # ... 
end 

그리고 오이 내부 : 피클은 위의 단계를 처리하지 않는 경우

Given the following accounts exist 
    | user | 
    | Fred | 
    | Ethel | 

, 당신은 다음과 같이 자신의 단계 정의를 만들 수 있습니다 :

Given /^the following accounts:$/ do |class_name, table| 
    table.hashes.each do |attributes| 
    u = User.make! :name => attributes[:user] 
    Account.make! :user => u 
    end 
end 
관련 문제