How to create an association in a miniskirt factory?

199 Views Asked by At

I'm writing tests with minitest and trying to use miniskirt to handle factories in my rails app. I'm having trouble creating an assocation between my user model and my other models. Since miniskirt does not have Factory#association like factory girl how do you create the association? I'm trying this:

Factory.define :user do |f|
  f.email "[email protected]"
  f.password f.password_confirmation("rockaway")
end

Factory.define :song do |f|
  f.title "I Wanna Be Sedated"
  f.artist "Ramones"
  f.credits "Recorded on February 12-19, 1976 at Plaza Sound, Radio City Music Hall in New York City for Sire Records. All Songs by The Ramones."
  f.artwork "name-of-the-file.jpg"
  f.user { Factory :user }
end

But the following test keeps failing as Validation failed: User can't be blank:

require "test_helper"

describe Song do
  it "has a valid factory" do
    Factory.create :song
  end
end
0

There are 0 best solutions below