Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Rails Testing: Migrations/Models/Fixtures
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jason Edwards  
View profile  
 More options Aug 14 2007, 6:32 pm
From: "Jason Edwards" <jtan...@gmail.com>
Date: Tue, 14 Aug 2007 16:32:38 -0600
Local: Tues, Aug 14 2007 6:32 pm
Subject: Rails Testing: Migrations/Models/Fixtures
Apparently I have missed something somewhere along the line, and have
made a real mess of things here.

The question/problem I'm trying to work through is, in Rails, how do
you deal with a mixture of "code tables" and test fixtures.  I'm not
sure what "code tables" are really called, but I'm referring to tables
containing data that's more like configuration.  For example I've got
three tables named 'authorities', 'roles' and 'authorities_roles'
representing a many-to-many (habtm) relationship between authorities
and roles.  The authorities table is essentially static, the records
will change very rarely (only when there's an update to the system).
The roles table has a set of default roles, and allows users to create
their own roles.  Make sense?

Somewhere I thought I read that my "code table" data should be moved
out of the fixtures and into a migration.  Easy enough.  But now my
tests fail miserably.  For one going from unit to functional tests,
all the records are deleted.

So how do you get the migrations and fixtures to play well together?

Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ceaser Larry  
View profile  
 More options Aug 15 2007, 1:11 am
From: Ceaser Larry <ceaser.la...@gmail.com>
Date: Tue, 14 Aug 2007 23:11:44 -0600
Local: Wed, Aug 15 2007 1:11 am
Subject: Re: [urug] Rails Testing: Migrations/Models/Fixtures
You need the data in both places. In the fixtures and in the migration  
script.

Ceaser

On Aug 14, 2007, at 4:32 PM, "Jason Edwards" <jtan...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Edwards  
View profile  
 More options Aug 15 2007, 7:53 am
From: "Jason Edwards" <jtan...@gmail.com>
Date: Wed, 15 Aug 2007 05:53:59 -0600
Local: Wed, Aug 15 2007 7:53 am
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
Well that won't work.  You can't follow the DRY principle if you do that...

Jason

On 8/14/07, Ceaser Larry <ceaser.la...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jamis Buck  
View profile  
 More options Aug 15 2007, 9:31 am
From: "Jamis Buck" <ja...@37signals.com>
Date: Wed, 15 Aug 2007 07:31:39 -0600
Local: Wed, Aug 15 2007 9:31 am
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
Not sure what you mean by that, Jason. The migration puts the data
into your "live" database (production, or development). The fixtures
put the data into your test database. If the data will always be the
same in both places, have your migration read the fixtures.

- Jamis

On 8/15/07, Jason Edwards <jtan...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Edwards  
View profile  
 More options Aug 15 2007, 10:32 am
From: "Jason Edwards" <jtan...@gmail.com>
Date: Wed, 15 Aug 2007 08:32:18 -0600
Local: Wed, Aug 15 2007 10:32 am
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
Derr, have the migrations read the fixtures, now I'm pickin' up what
you're layin' down...  I'll give that a whirl.

Thanks,

Jason

On 8/15/07, Jamis Buck <ja...@37signals.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brett Rasmussen  
View profile  
 More options Aug 16 2007, 5:38 pm
From: "Brett Rasmussen" <brett.rasmus...@twoedge.com>
Date: Thu, 16 Aug 2007 15:38:30 -0600
Local: Thurs, Aug 16 2007 5:38 pm
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures

Out of curiosity, what would I do if I wanted to load the fixtures into the
development database but don't want it part of a migration?

Brett


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tieg Zaharia  
View profile  
 More options Aug 16 2007, 5:42 pm
From: "Tieg Zaharia" <tieg.zaha...@gmail.com>
Date: Thu, 16 Aug 2007 17:42:52 -0400
Local: Thurs, Aug 16 2007 5:42 pm
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures

"rake db:fixtures:load FIXTURES=trains,plains,automobiles"

(and add RAILS_ENV=???) if you want to load it into a specific environment,

tieg

On 8/16/07, Brett Rasmussen <brett.rasmus...@twoedge.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Mabey  
View profile  
 More options Aug 16 2007, 5:43 pm
From: Ben Mabey <b...@benmabey.com>
Date: Thu, 16 Aug 2007 15:43:01 -0600
Local: Thurs, Aug 16 2007 5:43 pm
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
rake db:fixtures:load                  # Load fixtures into the current
environment's database.  Load specific fixtures using FIXTURES=x,y

For a complete listing of rake tasks that ships with rails do "rake
-T".  So if you want to load the fixtures into dev you would do:
RAILS_ENV=development rake db:fixtures:load

-Ben


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Edwards  
View profile  
 More options Aug 16 2007, 6:53 pm
From: "Jason Edwards" <jtan...@gmail.com>
Date: Thu, 16 Aug 2007 16:53:40 -0600
Local: Thurs, Aug 16 2007 6:53 pm
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
So I finally got it all working, just the way I wanted, but I didn't
follow the advice I got.  Please feel free to tell me how lame this
is.

* I'm still loading my base data sets as inserts in my migrations.
* My fixture files now contain *only* test fixtures, none of the base data.
* I set the 'self.pre_loaded_fixtures = true' and
'self.use_transactional_fixtures = true' in my test_helper.rb
* I took out all the fixture declarations in my test, and now have
them load fixtures from the database.
* I wrote a rake task which loads the fixtures, but doesn't delete the
existing data.  So I can insert data into a table in my migration, and
then insert additional rows in table using the fixtures.

Now the only problem I'm having is when I run the tests with Rake, it
calls 'db:test:prepare' which recreates the structure, but leaves the
tables empty.

Anyone know how to change that?  I was just going to write another Rake task...

Jason

P.S. - If you care, you can find the rake task on my blog:
http://www.jtanium.com/blog/?p=41

On 8/15/07, Jason Edwards <jtan...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lee Jensen  
View profile  
 More options Aug 16 2007, 9:15 pm
From: "Lee Jensen" <l...@outerim.com>
Date: Thu, 16 Aug 2007 19:15:33 -0600
Local: Thurs, Aug 16 2007 9:15 pm
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
Can't say I can tell you how to change that, but I would advise
against having a test database that can't be torn down and rebuilt at
a whim from your fixtures without breaking any tests. It'll make your
life easier in the long run. Not tearing down your test database each
time can leave you with extremely difficult to track down errors,
false negatives and false positives and generally make your tests
harder to use and less reliable.

Lee

On 8/16/07, Jason Edwards <jtan...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Edwards  
View profile  
 More options Aug 16 2007, 9:32 pm
From: "Jason Edwards" <jtan...@gmail.com>
Date: Thu, 16 Aug 2007 19:32:43 -0600
Local: Thurs, Aug 16 2007 9:32 pm
Subject: Re: [urug] Re: Rails Testing: Migrations/Models/Fixtures
It's not that it can't be torn down, I can tear it down, and rebuild
it easily, I do it dozens of times a day.  The problem is the default
Rake task ('test') doesn't use my migrations, and my
load_additional_fixtures task, to rebuild the test database.

In the short term I wrote a simple one-liner shell script to do
exactly what I'm talking about, but now I realize that a new Rake task
is definitely the way to go.

Thanks,

Jason

P.S. - In case you didn't get the memo: Ruby (metaclasses in this
case) rules!  Long live Ruby!

On 8/16/07, Lee Jensen <l...@outerim.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »