Foreign keys in YAML fixtures

Hi all,
I’m trying to set up my test fixtures, and I’ve recently added foreign
keys to my database. Each “channel” is owned by a user, so I need to
include a valid user id with each fixture. I’m not sure how to set this
up. My YAML is the following

eBay:
id: 1
name: eBay
created_at: <%= 5.days.ago.to_s :db %>
user_id: <%= User.find_by_login(“quentin”) %>
antiqueStore:
id: 2
name: antique Store
created_at: <%= 5.days.ago.to_s :db %>
user_id: <%= User.find_by_login(“quentin”) %>

Nothing is inserted into the user table, so the above obviously won’t
work.
How can I run my users.yaml file when I run my channels test?

Thanks,
Todd

Todd N. wrote:

Hi all,
I’m trying to set up my test fixtures, and I’ve recently added foreign
keys to my database. Each “channel” is owned by a user, so I need to
include a valid user id with each fixture. I’m not sure how to set this
up. My YAML is the following

eBay:
id: 1
name: eBay
created_at: <%= 5.days.ago.to_s :db %>
user_id: <%= User.find_by_login(“quentin”) %>
antiqueStore:
id: 2
name: antique Store
created_at: <%= 5.days.ago.to_s :db %>
user_id: <%= User.find_by_login(“quentin”) %>

You have a users.yaml file? If not, you need one!

Usually the user_id:… lines would read

user_id: 4 # some definite number

where you have a user in the users.yaml file with id 4 (or some other
definite number).

Nothing is inserted into the user table, so the above obviously won’t
work.
How can I run my users.yaml file when I run my channels test?

See

Thanks,
Todd

On Oct 9, 2007, at 3:55 PM, Stephan W. wrote:

id: 1

See
Bootstrapping your Database with Ordered Fixtures – Alistair Israel
database-with-ordered-fixtures/

Thanks,
Todd

Well, you said you’ve added the foreign keys to the database so you
may have issues with the order in which your fixtures are loaded. If
you just need to have the entries of a single fixture loaded to the
database in a particular order, you can replace the default YAML map
with an omap (ordered map) type quite easily:

— !omap

  • eBay:
    id: 1
    name: eBay
    created_at: <%= 5.days.ago.to_s :db %>
    user_id: 4
  • antiqueStore:
    id: 2
    name: antique Store
    created_at: <%= 5.days.ago.to_s :db %>
    user_id: 5

But you still (potentially) have the issue of loading the users table
before your channels.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Hi Stephan,
Thanks for the response, I apologize for the delay in my response, I
only
have time to work on RoR on the weekends. I do have a users file. I
have
included the text below. As far as ordering, will the ordering plugin
be
implicitly executed when I run my rake file, or will I have to manually
run
the target?

Thanks,
Todd

quentin:
id: 1
login: quentin
email: [email protected]
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
#crypted_password: “ce2/iFrNtQ8=\n” # quentin, use only if you’re
using
2-way encryption
created_at: <%= 5.days.ago.to_s :db %>
activated_at: <%= 5.days.ago.to_s :db %> # only if you’re activating
new
signups
enabled: <%= true %>

aaron:
id: 2
login: aaron
email: [email protected]
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
activation_code: aaronscode # only if you’re activating new signups
created_at: <%= 1.days.ago.to_s :db %>
enabled: <%= true %>

disabled:
id: 3
login: disabled
email: [email protected]
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
#crypted_password: “ce2/iFrNtQ8=\n” # quentin, use only if you’re
using
2-way encryption
created_at: <%= 5.days.ago.to_s :db %>
activated_at: <%= 5.days.ago.to_s :db %> # only if you’re activating
new
signups
enabled: <%= false %>