ruby - Factory Girl - creating a factory with active record validations -


so have factory create item. can contain 1 or more line_items.

describe item   let(:user) { create :user }   let(:currency) { create :currency }   subject(:item) { create :item, currency: currency, create_user: user, update_user: user } 

it fails when creating item active record validation:

activerecord::recordinvalid: validation failed: have not entered data , cannot save blank form., have not entered data , cannot save blank form. 

is because line_item not being created when item created?

in factory, whenever create line_item, create item:

factorygirl.define   factory :line_item     item     create_user factory: :user     update_user factory: :user   end end 

make sure models validated model validations in factory. please can paste models. try code below. not tested have doctor based on model.

factorygirl.define     factory :user         sequence(:username) { |n| "foo#{n}"}         password "password"         email {"#{username}@example.com"}     end      factory :item         name "item1"         user     end      factory :line_item         name "line_item1"         item     end end 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -