picardo
picardo

Reputation: 24896

Question about FactoryGirl

I was reading through the documentation of Factory Girl and came across this code block.

#The behavior of the association method varies depending on the build strategy used for the parent object.

#Builds and saves a User and a Post
post = FactoryGirl.create(:post)
post.new_record?       # => false
post.author.new_record # => false

# Builds and saves a User, and then builds but does not save a Post
post = FactoryGirl.build(:post)
post.new_record?       # => true
post.author.new_record # => false

I'm new to Factory Girl, but shouldn't the first code example return true for new_record? I'm confused why it returns false if the post is built and saved.

Upvotes: 2

Views: 329

Answers (1)

Art Shayderov
Art Shayderov

Reputation: 5110

new_record?() public
Returns true if this object hasn’t been saved yet — that is, a record for the object doesn’t exist yet; otherwise, returns false.
This method is deprecated on the latest stable version of Rails.

Edit:
Oops, looks like the link was broken. Fixed. new_record?

Upvotes: 2

Related Questions