benim Spec testleri ile bir sorunu çözmeye çalışıyorum ve aşağıdaki hata Hataları olsun: ile derneklerleRSpec ve fabrika kızı SystemStackError: çok derin yığın seviyesi
Buna1) SessionsController POST 'create' with valid email and password should sign in the user
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
# /Users/Aurelien/.rvm/gems/[email protected]/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:103
Finished in 37.77 seconds
9 examples, 1 failure
Failed examples:
rspec ./spec/controllers/sessions_controller_spec.rb:35 # SessionsController POST 'create' with valid email and password should sign in the user
önce vardı sorunlar benim fabrikalar.
Factory.define :role do |role|
role.name "Registered"
role.association :user, :factory => :user
end
Factory.define :admin do |role|
role.name "Admin"
role.association :user, :factory => :user
end
Factory.define :user do |user|
user.first_name "Foo"
user.last_name "Bar"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
user.status "At foobar"
user.description "Lorem Ipsum sit dolor amet."
user.username "foobar"
user.association :role, :factory => :role
user.association :admin, :factory => :role
end
Factory.define :user_with_admin_role, :parent => :user do |user|
user.after_create { |u| Factory(:role, :user => u) }
end
Factory.define :reg_user do |user|
user.first_name "bar"
user.last_name "foo"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
user.status "At foobar"
user.description "Lorem Ipsum sit dolor amet."
user.username "barfoo"
user.association :role, :factory => :role
end
ve benim oturumu testleri bugüne kadar şunlardır:
describe "POST 'create'" do
describe "invalid signin" do
before(:each) do
@attr = { :email => "[email protected]", :password => "invalid" }
end
it "should re-render the 'new' page with a flash error" do
post :create, :session => @attr
flash.now[:error] =~ /invalid/i
response.should render_template('new')
end
end
describe "with valid email and password" do
before(:each) do
@user = Factory(:user)
@attr = { :email => @user.email, :password => @user.password}
end
it "should sign in the user" do
post :create, :session => @attr
controller.current_user.should == @user
end
end
end
Gerçekten sorunu yaratıyor emin değilim. Modelimde, ilk kullanıcı için "Kayıtlı" ve "Yönetici" rolü olarak her kullanıcıya varsayılan bir rol atadım.
user.rb
def assign_default_role
if User.count == 0
self.roles << Role.find_by_name("Admin")
self.roles << Role.find_by_name("Registered")
end
self.roles << Role.find_by_name("Registered") unless User.count == 0
end
Herhangi bir tavsiye en hoş olurdu. Teşekkür
[FactoryGirl ilişkilendirme modeli sorununun olası yinelenmesi: "SystemStackError: yığın düzeyi çok derinde"] (http://stackoverflow.com/questions/7479031/factorygirl-association-model-trouble-systemstackerror-stack-level-too- derin) –