test/dummy/spec/factories/events.rb in polygallery-0.2.1 vs test/dummy/spec/factories/events.rb in polygallery-0.2.3

- old
+ new

@@ -1,7 +1,47 @@ include ActionDispatch::TestProcess FactoryGirl.define do factory :event do title { FFaker::BaconIpsum.words(3).join(' ').titleize } + + trait :with_photo do + before :create do |e| + e.gallery_attributes = { + :title => 'gallery', + :photos_attributes => [attributes_for(:photo)] } + end + end + + trait :with_custom_photo do + before :create do |e| + custom_photo_attributes = attributes_for :photo, + :gallery_title => 'custom_gallery', :galleryable => e + e.custom_gallery_attributes = { + :title => 'custom_gallery', + :custom_photos_attributes => [custom_photo_attributes] } + end + end + + trait :with_photos do + before :create do |e| + g_attrs = { :title => 'gallery', :photos_attributes => [] } + 3.times { g_attrs[:photos_attributes] << attributes_for(:photo) } + e.gallery_attributes = g_attrs + end + end + + trait :with_custom_photos do + before :create do |e| + cg_attrs = { :title => 'custom_gallery', + :custom_photos_attributes => [] } + 3.times { + cp_attrs = attributes_for :photo, + :gallery_title => 'custom_gallery', + :galleryable => e + cg_attrs[:custom_photos_attributes] << cp_attrs } + e.custom_gallery_attributes = cg_attrs + end + end + end end