I have the following:
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :permissions
has_one :city
end
class User < ActiveRecord::Base
has_many :permissions, dependent: :destroy
has_and_belongs_to_many :groups
end
FactoryGirl.define do
factory :user do
username { FFaker::Name.first_name }
email { FFaker::Internet.email }
first_name { FFaker::Name.first_name }
last_name { FFaker::Name.last_name }
current_login_ip "127.0.0.1"
login_count { rand(100) + 1 }
deleted_at nil
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
suspended_at nil
password "password"
password_confirmation "password"
vertical {1}
marketplace_role {1}
end
factory :admin do
admin true
end
factory :group do
users { |a| [a.association(:user)] }
name { FFaker::Company.name }
city { FactoryGirl.create(:city) }
end
end
FactoryGirl.define do
factory :permission do
user
group
asset { fail "Please specify :asset for the permission" }
updated_at { FactoryGirl.generate(:time) }
created_at { FactoryGirl.generate(:time) }
end
end
factory :city do
name { FFaker::Name.name }
end
factory :zone do
city
name { FFaker::Name.name }
end
factory :location do
zone
name { FFaker::Name.name }
end
Failure/Error: @group = FactoryGirl.create(:group) ActiveModel::MissingAttributeError: can't write unknown attribute group_id
This is what I get. I am unable to define and use the groups factory. I looked into this post, But the solution doesnt work.