Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Created May 13, 2012 06:36
Show Gist options
  • Save ch1ago/2686532 to your computer and use it in GitHub Desktop.
Save ch1ago/2686532 to your computer and use it in GitHub Desktop.
Fabricator(:state) do
name { Faker::Address.city }
end
Fabricator(:city) do
state #{ Fabricate(:state) }
name { Faker::Address.city }
end
1.9.3-p125 :005 > Fabricate(:city)
(0.5ms) BEGIN
SQL (1.1ms) INSERT INTO "states" ("bands_count", "created_at", "name", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["bands_count", 0], ["created_at", Sun, 13 May 2012 06:36:02 UTC +00:00], ["name", "North Elliot"], ["updated_at", Sun, 13 May 2012 06:36:02 UTC +00:00]]
SQL (0.9ms) INSERT INTO "cities" ("bands_count", "created_at", "name", "state_id", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["bands_count", 0], ["created_at", Sun, 13 May 2012 06:36:02 UTC +00:00], ["name", "Rowlandview"], ["state_id", nil], ["updated_at", Sun, 13 May 2012 06:36:02 UTC +00:00]]
(28.0ms) COMMIT
=> #<City id: 9, state_id: nil, name: "Rowlandview", bands_count: 0, created_at: "2012-05-13 06:36:02", updated_at: "2012-05-13 06:36:02">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment