Topic: How to test deletion of a file?

Hello all, this is really two questions in one.  I have been looking around for quite some time to work this out... but am stumped.  I am sure I need to use mocks(stubs) but just can't work out how.

I have three models that are all has_many / belongs_to in a chain down from Book -> Sections -> Documents.  The documennts model allows the upload of files.  I have the upload working fine.  On destroy of any of the models they delete the "children" through "dependent => :destroy" calls on the has_many relationship.

This then calls a series of call backs that delete the files and directory structure as appropriate from all three models.

Also on the creation of the document model, it checks the file size of the uploaded file, verses the copy that it has inside the database and writes uver the size and confirms a correct upload.

This all works perfectly.

My problem comes into trying to work out how to test it all.

First problem:  How to have a fixture with an entire 40k text file in it.  Do i just put it in the YAML as the last entry?  Will I run into problems here?

Second problem:  When I test the delete, I have a file called "test.html" in the fixtures directory, and I reference this through the fixture.filename, and sure enough, the test runs and the file gets deleted "yay", but now it is gone.... and all the remaining unit and functional tests fail....

The only thing I can think of is copying the file over in EVERY test I do that relates to the file... but this doesn't sound very Railish or DRY to me.

What is a better idea?

Happy to post code if appropriate, but not sure how to make it look like the nice blue and white background coding everyone else can do smile

Thanks!

Mikel

Re: How to test deletion of a file?

Well, after hunting around, I found the answer in the end.  It was to use setup and teardown in the test methods.

These put the files where needed so that the tests can run properly.

Very handy.  A good write up for anyone else who needs to know is at the bottom of:

http://manuals.rubyonrails.com/read/chapter/23

Regards

Mikel