2017-10-06 1 views
0

나는이 하나의 사양 및 하나 개의 공장 나는이 오류가 점점 오전 : 나는 verbage를 사용하려고하면 작동 '구축'RSpec에와 FactoryGirl : SystemStackError : 스택 레벨 너무 깊이 레일

SystemStackError: stack level too deep 
    from gems/activerecord-4.2.1/lib/active_record/relation/delegation.rb:9:in `relation_delegate_class'  

을; 하지만 데이터를 테스트하기 위해 저장해야하며 '작성'은 let!(:user) { create(:user) }에서 작동하지 않으므로 오류가 발생합니다. Rspec은 정상적으로 작동하는 것 같습니다.

나는 루비 2.2.2를 실행 중이다. - 당신은 단지 세상을 위해 자신을 설정하는

FactoryGirl.define do 
    factory :user, aliases: [:participant] do 
    sequence(:email) { |n| "user#{n}@example.com" } 
    first_name { Faker::Name.first_name } 
    last_name { Faker::Name.last_name } 
    password 'testpass' 
    password_confirmation { password } 
    role 
    end 
end 

이 공장에 ID를 하드 코딩하지 마십시오 : RSpec에, 공장 소녀를 사용하여 설정 협회에

require 'spec_helper' 
describe API::V1::CurrentUserController do 
    let!(:user) { create(:user) } 
    setup_api_authorization 

    describe "GET 'show'" do 
    before (:each) do 
    setup_api_headers 
    get 'show', subdomain: 'api', id: 'me' 
    end 
end 


FactoryGirl.define do 
    factory :user, aliases: [:participant] do 
    sequence(:email) { |n| "user#{n}@example.com" } 
    first_name { Faker::Name.first_name } 
    last_name { Faker::Name.last_name } 
    password 'testpass' 
    password_confirmation { |user| user.password } 
    role_id {4} 
end 
end 
+1

은'User' 모델을 제시해주십시오. 'after_create','after_commit' 등과 같은 콜백을 가지고 있습니까? –

+0

spec 사용자 모델 또는 app – eWadeMan

+0

모델의'app/models'. –

답변

0

당신은 공장의 이름을 호출 할 수 있습니다 상처의.

당신은 대신 사용자에게 역할을 추가 콜백을 사용할 수 있습니다 Rolify를 사용하는 경우 :

FactoryGirl.define do 
    factory :user, aliases: [:participant] do 
    sequence(:email) { |n| "user#{n}@example.com" } 
    first_name { Faker::Name.first_name } 
    last_name { Faker::Name.last_name } 
    password 'testpass' 
    password_confirmation { password } 
    after(:create) { |user| user.add_role(:peasant) } 
    end 
end 
+0

그래요. 스택 레벨이 너무 깊은 이유를 이해하기 위해 노력하고 있습니다. 그래서 내 모델에서 읽고 왜이 오류 던지고 무엇입니까? – eWadeMan

+0

내가 위에 쓴 것을 설명해 주시겠습니까? – eWadeMan

0

This error generally happens when you accidentally recursively changing an attribute. If you have a username attribute in User model, and a virtual attribute named username, that is directly changing the username, you end up calling the virtual, the virtual calls the virtual again and so on.. Therefore, take a look on whether something like that happens somewhere in your code.

Stack level too deep error in Ruby on Rails

관련 문제