[rspec-users] how to avoid tests removing data that my migrations put in?
pergesu at gmail.com
Wed Nov 5 14:18:41 EST 2008
"Greg Hauptmann" <greg.hauptmann.ruby at gmail.com> writes:
> so is the concept to build up all seed data creation in one
> place/method, & then for the rake spec case run this in via the "test"
> environment.rb file?
That sounds good. I typically put it in spec_helper.rb so all
test-related stuff is in one place, but I think it makes a lot of sense
to treat this as part of the environment.
> But then if you were to use rake:migrate to drop back a couple of
> version you might be in a spot of bother? (ie newest seed data not
> then tied to migration)?
Let me know if I'm understanding your problem correctly...if you put the
seed data in test.rb, then it'll try to load it regardless of whether it
matches the db schema. Is that right? If that's the case, I suppose
you could do a check to see if you even need to load seed data.
Basically, if there are already users in the test db, no need to do
anything. This would let you have a fully-migrated db with seed data
that you then migrated down. But honestly I'm not sure why you would
want to drop the schema back down a couple of versions in the first
> On 11/5/08, Pat Maddox <pergesu at gmail.com> wrote:
>> "Mark Wilden" <mark at mwilden.com> writes:
>>> On Tue, Nov 4, 2008 at 4:26 PM, Pat Maddox <pergesu at gmail.com> wrote:
>>> aslak's right though in that case too. In your spec_helper, just loop
>>> over the tables and delete everything, then insert the seed data you
>>> want, and it should be good to go.
>>> But then Ashley's comment applies: you've got the same facts in two
>>> places. Best thing is to
>>> avoid the dependency, if at all possible.
>> Sure, but you can encapsulate all that stuff too. When I've done stuff
>> like this in the past (and on second thought I have done it just as
>> aslak suggested, I just didn't think of it :) we've created some seed
>> data builders. Then it becomes a simple matter of SeedData.build_data
>> to kick off the whole deal.
>> rspec-users mailing list
>> rspec-users at rubyforge.org
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users