This commit is contained in:
Rico Sta. Cruz 2016-12-24 00:23:06 +08:00
parent b8ea695245
commit b7e4c06ce7
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
2 changed files with 35 additions and 35 deletions

View File

@ -4,33 +4,24 @@ category: Ruby libraries
layout: default-ad layout: default-ad
--- ---
### Paths ## Factories
test/factories.rb
spec/factories.rb
test/factories/*.rb
spec/factories/*.rb
### Factories
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
first_name "John" first_name 'John'
last_name "Doe" last_name 'Doe'
birthdate { 21.years.ago } birthdate { 21.years.ago }
admin false admin false
profile # assuming there's a factory :profile sequence(:username) { |n| "user#{n}" }
end end
end end
### Others # Also available:
factory :user, class: 'User'
factory :user, aliases: [:author]
factory :user { ... } ## Using
factory :sample_user, class: 'User' { ... }
factory :user, aliases: [:author, :client] { ... }
### Using
FactoryGirl.build(:user) FactoryGirl.build(:user)
@ -39,7 +30,7 @@ layout: default-ad
attributes_for(:user) # hash attributes_for(:user) # hash
build_stubbed(:user) # stubbed out attributes build_stubbed(:user) # stubbed out attributes
build(:user, name: "John") build(:user, name: 'John')
create_list(:user, 3) create_list(:user, 3)
build_list(:user, 3) build_list(:user, 3)
@ -47,10 +38,13 @@ layout: default-ad
## Associations ## Associations
factory :post do factory :post do
association :author, factory: :user
association :author, factory: [:user, :admin]
author # assumes there's a factory :author author # assumes there's a factory :author
end end
### More complicated ### After-create hooks
factory :post do factory :post do
after :create do |post| after :create do |post|
@ -69,7 +63,21 @@ layout: default-ad
create :user, :admin create :user, :admin
## Transients ## Nested factories
factory :user do
first_name 'John'
factory :sample_user do
first_name { FFaker::Name.first_name }
end
end
# create :sample_user
# Also: factory :sample_user, parent: :user
## Options (transients)
factory :user do factory :user do
transient do transient do
@ -83,22 +91,12 @@ layout: default-ad
create(user, upcased: true) create(user, upcased: true)
### Etc ## Paths
# Sequences test/factories.rb
sequence(:username) { |n| "user#{n}" } spec/factories.rb
test/factories/*.rb
# Associations spec/factories/*.rb
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
## See also ## See also

View File

@ -58,6 +58,7 @@ Last updated for Vainglory 1.22 with some 2.0 stuff.
| BP: [Breaking Point][BP] | 2600 | +55 wp | __Stacking dmg__ <br> *stacking weapon dmg*, +35% atk speed | | BP: [Breaking Point][BP] | 2600 | +55 wp | __Stacking dmg__ <br> *stacking weapon dmg*, +35% atk speed |
| SM: [Serpent Mask][SM] | 2800 | +85 wp | __Lifesteal__ <br> *stacking lifesteal*, +10% lifesteal | | SM: [Serpent Mask][SM] | 2800 | +85 wp | __Lifesteal__ <br> *stacking lifesteal*, +10% lifesteal |
| SB: [Sorrowblade][SB] | 3100 | +150 wp | __Raw power__ <br> - | | SB: [Sorrowblade][SB] | 3100 | +150 wp | __Raw power__ <br> - |
| PS: [Poison Shiv][PS] | ? | ? | __Mortal wounds__ <br> - |
{:.wide} {:.wide}
[BS]: http://www.vaingloryfire.com/vainglory/wiki/items/bonesaw [BS]: http://www.vaingloryfire.com/vainglory/wiki/items/bonesaw
@ -67,6 +68,7 @@ Last updated for Vainglory 1.22 with some 2.0 stuff.
[TB]: http://www.vaingloryfire.com/vainglory/wiki/items/tension-bow [TB]: http://www.vaingloryfire.com/vainglory/wiki/items/tension-bow
[TT]: http://www.vaingloryfire.com/vainglory/wiki/items/tornado-trigger [TT]: http://www.vaingloryfire.com/vainglory/wiki/items/tornado-trigger
[TM]: http://www.vaingloryfire.com/vainglory/wiki/items/tyrants-monocle [TM]: http://www.vaingloryfire.com/vainglory/wiki/items/tyrants-monocle
[PS]: http://www.vaingloryfire.com/vainglory/wiki/items/poison-shiv
## T3 Utils by HP ## T3 Utils by HP