Skip to content

Instantly share code, notes, and snippets.

@melekes
Created November 13, 2013 15:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melekes/7450542 to your computer and use it in GitHub Desktop.
Save melekes/7450542 to your computer and use it in GitHub Desktop.
Writing tests using FactoryGirl and validating presence of nested attributes (http://homeonrails.com/2012/10/validating-nested-associations-in-rails/) P.S. code not tested
require 'factory_girl'
FactoryGirl.define do
factory :company do
name "Twitter Corp."
before(:create) do |company, evaluator|
offices_attributes = []
3.times do # 3 offices per company
offices_attributes << attributes_for(:office)
end
company.offices_attributes = offices_attributes
end
end
end
require 'factory_girl'
FactoryGirl.define do
factory :office do
name "North America"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment