Last active
March 6, 2017 08:11
-
-
Save blueplanet/5737194 to your computer and use it in GitHub Desktop.
FactoryGirl使い方メモ ref: http://qiita.com/blueplanet/items/b023e26e0ecd79231136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ActiveRecord::Base | |
has_many :groups | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :seq_group, class: Group do | |
sequence(:name) { |n| "group #{n}"} | |
sequence(:description) {|n| "description #{n}"} | |
sequence(:img_url) {|n| "http://test.com/#{n}.jpg"} | |
end | |
factory :group_event, class: Group , parent: :seq_group do | |
events { | |
[FactoryGirl.create(:seq_event)] | |
} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Group < ActiveRecord::Base | |
has_many :events | |
has_many :members | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :group_event, class: Group do | |
members { | |
FactoryGirl.create_list(:seq_user, 10) | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment