views:

232

answers:

1

Hi, I'm testing the following:

Account

class Account < ActiveRecord::Base 
  has_many :ownerships
  has_many :brands, :through => :ownerships
end

Ownership join model

class Ownership < ActiveRecord::Base
  belongs_to :brand
  belongs_to :account
end

Test

it "should be able to apply for brand ownership" do
  account = Account.create(valid_account_attributes)
  account.ownerships.create(:brand => Brand.create(:name => 'Superuser'))
  account.ownerships.first.state == 'pending'
end

And I keep getting this error

You cannot call create unless the parent is saved

I really don't get it - what parent? Shouldn't all the models be created and saved when using 'create'-method? I've tried putting 'account.save' everywhere.

A: 

Are you sure that account is actually saved? Did you try using create! to see if any exceptions are raised?

zetetic