mercredi 18 janvier 2017

RSpec Stack level too deep (SystemStackError)

I have three models offer_ticket, event and offer and have three their respective factories below are the models and factories are given i got error stack level too deep suggest me a solution how to remove this error

offer_ticket.rb

class OfferTicket < ActiveRecord::Base
    belongs_to :event
end

event.rb

class Event < ActiveRecord::Base
   has_many :offer_tickets , dependent: :restrict_with_error
end

offer.rb

class Offer < ActiveRecord::Base
   has_many :offer_tickets , dependent: :restrict_with_error
end

Their respective factories as given below

offer_tickets.rb

FactoryGirl.define do
   factory :offer_ticket do
      venue_row_id        1
      sale_id             1
      status              "available"
      seat_number         1
      association(:event)
   end
end

events.rb

FactoryGirl.define do
   factory :event do |f|

      f.name { Faker::Name.name  }
      f.starts_at { Faker::Date.backward(Random.rand(20)).to_date }
      f.description { Faker::Lorem.paragraph }
      after(:build) do |event|
         create(:offer, event: event)
      end
   end
 end

offers.rb

FactoryGirl.define do
  factory :offer do
    price                   1
    proxy                   1
    multiple                1
    cancelothers            1
    after(:build) do |offer|
       create(:offer_ticket, offer: offer)
    end
  end

end

When run below command in terminal got an error stack toop deep level

rspec spec/models/offer_ticket_spec.rb
/home/aqib/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:222: stack level too deep (SystemStackError)

Aucun commentaire:

Enregistrer un commentaire