Skip to content

Instantly share code, notes, and snippets.

@yock
Last active December 19, 2015 14:19
Show Gist options
  • Save yock/5968485 to your computer and use it in GitHub Desktop.
Save yock/5968485 to your computer and use it in GitHub Desktop.
FactoryGirl traits
FactoryGirl.define do
factory :user do
name 'Test User'
email 'fake@example.com'
trait :admin do
# Setting name here isn't required. Given to show override.
name 'Test Admin'
admin true
end
end
end
user = FactoryGirl.create(:user)
user.admin? # false
user.name # Test User
user = FactoryGirl.create(:user, :admin)
user.admin? #true
user.name # Test Admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment