ruby on rails - FactoryGirl Model Spec with Associations -
New to testing and trying to add FactoryGirl to a model test. My challenge is that I have an account between the user and the account, but in the account model through an owner through the IID area.
The following test work
Describe the customer "name and account with the valid" user = user. Create (email: "me@example.com", password: "PW", password_confirmation: "pw") account = account. Creating (name: "company one", owner_id: User.id) Customer = account.clients.new (name: "TestClient") is expected (customer). Be_valid end date
I'm trying to modify so that FactoryGirl can be used:
Describe the client "is a valid factory" Expect (build (client)). For Be_valid end end,
customer model is related to an account which is a user through association owner_id instead of User_id.
class user & lt; ActiveRecord :: Base is_On: Owner_Count, Class_Name: 'Account', Foreign_key: 'Owner_ID' near_mind: User_Connects, Dependent :: has been deleted_I: Through Accounts, :: UserCounts and Class Account & lt; ActiveRecord :: Base is_to: Owner, class_name: 'User' has _my: user_account, dependent :: has has_many: user, through :: user_accounts has_many: delete client, dependent :: and class client & lt; ActiveRecord :: Base is_to: account default_scope {where (account_id: account.current_id)} and
for the factory, I have:
FactoryGirl Define Factory: Email the user "john@example.com" password "pw" password_confirmation "pw" end-end factorygear. Define Factory: Account Association: owner_id, Factory: Username "Account One" and FactoryGirl.Define Factory : Client Association: Account Name "Test Client" End End
I Do I get to do and assign the name of the owner of the account?
factorygear
I need to change: owners_id: The owner of the association in the account factory.
Comments
Post a Comment