Declare shared attributes in rails fixtures
Declare shared attributes in rails fixtures using a base fixture.
user_fixture.yaml:
# base fixture, attributes are loaded into other fixtures
base_user: &BASE_USER
name: testy testicle
mail: some_mail@example.com
gender: male
user1:
<<: *BASE_USER
avatar: some_avatar #add avatar
admin: false #add admin
user2:
<<: *BASE_USER
admin:true #add admin
gender: female #overwrite gender
Helps defining base attributes (e.g. for validations) while concentrentrating on test-specific attributes in other fixtures.
Written by Mathias Rong
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tdd
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#