dimanche 28 juin 2015

How to call nested factory_girl attribute

I am using rspec and factory girl and am having a weird problem getting a sub class from a factory. I am creating a designer, which is a sub cat of a user, however the test is still receiving a user, not a designer.

FactoryGirl.define do
  factory :user do
    factory :designer do
      role: "designer"
    end
  end
end

describe StoreRating do
  it "should have a rating" do
    user = FactoryGirl.create(:designer)
    store = FactoryGirl.create(:store)

    StoreRating.create(designer: user, store: store, rating: 5) 
  end
end

expected Designer, got User

Aucun commentaire:

Enregistrer un commentaire