diff --git a/_includes/meta.html b/_includes/meta.html index 71d90a02f..0a18dd336 100644 --- a/_includes/meta.html +++ b/_includes/meta.html @@ -86,7 +86,7 @@ {%comment%}{%endcomment%} {% if site.analytics %}{% endif %} - + diff --git a/factory_girl.md b/factory_girl.md index d16e28e6d..e1cbbcd54 100644 --- a/factory_girl.md +++ b/factory_girl.md @@ -10,40 +10,19 @@ layout: default test/factories/*.rb spec/factories/*.rb -### Defining stuff - - FactoryGirl.define do - factory ... - end - ### Factories - # This will guess the User class - factory :user do - first_name "John" - last_name { %w[Doe Smith Doyle].shuffle } - admin false + FactoryGirl.define do + factory :user do + first_name "John" + last_name "Doe" + birthdate { 21.years.ago } + admin false - # Sequences - sequence(:username) { |n| "user#{n}" } - - # Associations - association :author - association :author, factory: user, last_name: "Ho" - author - - # Traits - trait :admin do - admin true + profile # assuming there's a factory :profile end - - after :create do |user, evaluator| ... end - after :build end - factory :user, aliases: [:author, :commenter] do ... end - factory :admin_user, parent: :user do .. end - ### Using FactoryGirl.build(:user) @@ -58,3 +37,53 @@ layout: default create_list(:user, 3) build_list(:user, 3) +### Associations + + factory :post do + after :create do |post| + create :theme, post: post # has_one + create_list :comment, 3, post: post # has_many + end + end + +### Ignores + + factory :user do + ignore do + likes 30 + end + + after :create do |user, options| + create_list :like, options.likes, user: user + end + end + + create(:user, likes: 10) + +### Traits + + factory :user do + trait :admin do + admin true + end + end + + create :user, :admin + +### Etc + + # Sequences + sequence(:username) { |n| "user#{n}" } + + # Associations + association :author + association :author, factory: user, last_name: "Ho" + author + + after :create do |user, evaluator| ... end + after :build + end + + factory :user, aliases: [:author, :commenter] do ... end + factory :admin_user, parent: :user do .. end + diff --git a/sinon.md b/sinon.md index 750bb4c4d..93d879824 100644 --- a/sinon.md +++ b/sinon.md @@ -80,5 +80,10 @@ layout: default ### Sandbox - beforeEach -> global.sinon = require('sinon').sandbox.create() - afterEach -> global.sinon.restore() + beforeEach(function() { + global.sinon = require('sinon').sandbox.create(); + }); + + afterEach(function() { + global.sinon.restore(); + });