Created
December 6, 2012 16:19
-
-
Save jeffdeville/4225721 to your computer and use it in GitHub Desktop.
FactoryGirl associations failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| attr_accessible :name | |
| has_one :address | |
| end | |
| class Address < ActiveRecord::Base | |
| attr_accessible :addr1, :addr2 | |
| belongs_to :user | |
| validates_presence_of :user | |
| end | |
| FactoryGirl.define do | |
| factory :user do | |
| name "MyString" | |
| association :address | |
| end | |
| factory :address do | |
| addr1 "MyString" | |
| addr2 "MyString" | |
| end | |
| end | |
| FactoryGirl.create :user | |
| FactoryGirl.define do | |
| factory :user do | |
| name "MyString" | |
| after(:build) do |user| | |
| user.address = FactoryGirl.build :address | |
| end | |
| end | |
| end | |
| FactoryGirl.create :user, :address => FactoryGirl.build(:address, :addr1 => "elm st") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment