Intermittent object create error

16 views
Skip to first unread message

Torsten Rüger

unread,
Nov 3, 2014, 2:56:08 PM11/3/14
to rs...@googlegroups.com
As per subject, i am getting Errors now and then. Often on a whole run (all 212 tests) all is good. Sometimes not. Always when i run just one of some tests, as happens with guard. It's always 
ActiveRecord::StatementInvalid:
       SQLite3::ConstraintException: PRIMARY KEY must be unique

but on 3 different objects (that all use Basket)

Now i am quite new new to rspec, and though i do like it, i can't say i begin to understand the innards.
I have datacleaner installed, but the same happens without. I guess both use transactions and as seen above with sqlite (problem?)
I use FactoryGirl (which i is also new for me) to create objects with associated objects, and those are the problem.*

The project is online https://github.com/rubyclerks/office_clerk and i am not sure what information to include here: ruby 2.0 on mac. rails 4.0.11 , rspec 3.1.0 , factory_girl _rails 4.5.0.

Any help appreciated. Even if its just a direction or some good docs. I have been googling and banging my head but in vain

Torsten

factory :basket do
    sequence(:id)
    factory :basket_with_item do
      items {build_list :item , 1 }
    end
    factory :basket_2_items do
      items  {[FactoryGirl.create(:item2) , FactoryGirl.create(:item22)]}
    end



Antonio Antillon

unread,
Nov 3, 2014, 3:57:08 PM11/3/14
to rs...@googlegroups.com
Not sure you should set :id values in your factories... I think if you skip that field, it should work.

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/325f1136-3968-46f6-96e9-c7605e79077b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Torsten Rüger

unread,
Nov 4, 2014, 2:12:05 PM11/4/14
to rs...@googlegroups.com
Hi Antonio,
thanks for that. Quite obvious really, but sometimes it takes a second pair of eyes. 
I even knew that much but that must have stayed in there from early days.
So, all specs green :-)

Thanks

Torsten
Reply all
Reply to author
Forward
0 new messages