I've already posted to StackOverflow
but I'm impatient and this is driving me nuts.
I can do this in the console:
>>> a = FactoryGirl.create(:client)
=> #<Client id: 4, name: "name5", email: "cli...@example.com", password_digest: "$2a$10$vFsW6VfmNMKWBifPY3vcHe6Q2.vCCLEq3RqPYRxdMo0m...", created_at: "2012-08-14 23:37:11", updated_at: "2012-08-14 23:37:11">
>>> a.assign_admin
=> #<ClientRole id: 2, client_id: 4, role: 1, created_at: "2012-08-14 23:37:28", updated_at: "2012-08-14 23:37:28">
>>> a.admin?
=> true
but when I try to create an admin from FactoryGirl, I get:
>>> a = FactoryGirl.create(:admin)
ActiveRecord::RecordNotSaved: You cannot call create unless the parent is saved
from /.../usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.1/lib/active_record/associations/collection_association.rb:425:in `create_record'
my factory looks like this:
FactoryGirl.define do
factory :client do
sequence(:name) {|n| "name#{n}"}
sequence(:email) {|n| "client#{n}@example.com" }
password "password"
factory :admin do
after_create {|admin|
admin.assign_admin
}
end
end
end
I don't think I've changed any of my models, but I did update gems recently. See the SO post for more details, but I thought I'd ask the experts to get a faster response. Any idea what's going on?
- ff