2014-06-06 6 views
0

중첩 된 요소가 있고 다른 클래스와 HMABT 관계가있는 클래스를 조작하려고합니다. 여기 내 클래스는레일 mongoid와 fabricator 보석 has_many_and_belongs_to 관계

class Quote 

    has_and_belongs_to_many :providers 
    belongs_to :user 

class Provider 

    has_and_belongs_to_many :quotes 
    belongs_to :user 
    embeds_many :workdones 


class Workdone 
    embedded_in :provider 
    embeds_many :prices 

class Price 
    embedded_in :workdone 

이 내 날조 있습니다 내가 제작합니다과 견적을 제조 할 때

Fabricator(:price) do 
    workdone 
    variation_id {Fabricate(:variation)._id} 
    price {12} 
    discount {5} 
end 

usern = Faker::Name.last_name 
uidn = Faker::Number.number(10) 
Fabricator(:user) do 
    uid 123456 
    username {usern } 
    email {Faker::Internet.email} 
    username_or_uid { [ usern , uidn] } 
    provider {'facebook'} 
    name {Faker::Name.name } 
    gender {'male'} 
    birthday { Time.at(rand * (18.years.ago.to_f - 50.years.ago.to_f) + 50.years.ago.to_f).to_date } 
end 

Fabricator(:workdone) do 
    provider 
    workdonecount {1} 
    quotegivencount {1} 
    rating {5} 
    active {true} 
    give_price {true} 
end 


Fabricator(:provider) do 
    user 
    business_address {"Bostanlı Mh., 6352. Sokak No:15, 35480 İzmir, Türkiye"} 
    business_description {"Biz de sadece epilasyon işleriyle uğraşıyoruz ve bu işlerin 
    quote(count: 1) 

Fabricator(:quote) do 
    user 
    providers(count: 3) { Fabricate(:price).workdone.provider } 
    share_on_facebook_timeline {false} 
    customer_address {"Bostanlı Mh., 6352. Sokak No:15, 35480 İzmir, Türkiye"} 
    description {"dasdsadasdsad sadadsssssdsadsasdas"} 
    location {[27.094637499999976,38.4621336 ] } 
    variation_id { Fabricate(:variation)._id} 
end 

는 (: 견적)

그것은이 오류 메시지를 제공

Quote#give_quote works 
    Failure/Error: Unable to find matching line from backtrace 
    SystemStackError: 
     stack level too deep 

때 나는이 오류를 알려주는 공급자 제작자로부터 인용문 (개수 : 1)을 삭제합니다. 이것은 레일즈 콘솔에서 작동합니다 - 공급자가 생성됩니다. 나는 완전히 공급자를 제거

Failure/Error: quote = Fabricate(:quote) 
    TypeError: 
     no implicit conversion of nil into String 
    # ./spec/fabricators/quote_fabricator.rb:4:in `block (2 levels) in <top (required)>' 
    # ./spec/models/quote_spec.rb:51:in `block (3 levels) in <top (required)>' 

(수 : 3) {제작합니다 (: 가격) .workdone.provider} 인용 제작자 테스트에서 협회는 통과하지만, 물론 업체가

사람이 있습니까 만들어지지 않는다 어떻게 제공자를 만들 수 있을지 생각해?

답변

0

생성 된 사용자로부터이 견적에 대해 3 명의 공급자를 끌어낼 수 있습니까? Fabricator 정의를 사용하면 그렇게 할 수 있습니다.

Fabricator(:quote) do user providers { |attrs| attrs[:user].providers.sample(3) } share_on_facebook_timeline false customer_address "Bostanlı Mh., 6352. Sokak No:15, 35480 İzmir, Türkiye" description "dasdsadasdsad sadadsssssdsadsasdas" location [27.094637499999976,38.4621336] variation_id { Fabricate(:variation)._id } end

또한 만 동적 값을 생성하는 경우, 블록 구문을 사용할 필요가있다. 정적 값을 모두 사용하는 경우 (위에서와 같이) 직접 값을 전달하면 약간의 오버 헤드가 발생합니다.

+0

저는 실제로이 문제를 해결했습니다. 문제는 gmaps4rails gem이 사용하지 않은 빈 공간 점 값입니다. 나의 코드를 당신의 도움으로 업데이트하고 제작 보석에 큰 공헌을 해주셔서 감사드립니다. –