Topic: [Rails][Tests] File upload + acts_as_attachement

I just beginning creating tests and I would like to test a file upload and check that a reference to that file has well been added into the database.

I have a model called uploaded_files wich use the acts_as_attachement plugin.
Every uploaded_files belongs to a project.
So in my projects_controller I have a method called upload_file(:project_id, uploaded_file)

def test_should_create_source_template
    old_count = SourceTemplate.count
    ...#What should I add there ?
    assert_equal old_count+1, SourceTemplate.count
end

If somebody knows how to upload files using acts_as_attachement into test methods, thanks for your help

Re: [Rails][Tests] File upload + acts_as_attachement

ok, seems i m getting closer, i did this :

def test_should_create_source_template
    old_count = SourceTemplate.count
    post :create_source_template, :id => 1, :source_template => fixture_file_upload( 'files/previous_library.xtd' )
    assert_equal old_count+1, SourceTemplate.count
  end

but i get an error with this... :
NoMethodError: undefined method `stringify_keys!' for #<File:/tmp/previous_library.xtd.491.0>

But outside tests the file upload works fine.... so what did i do wrong ? If somebody got a clue, thanks for sharing wink

Last edited by adamas (2007-06-08 04:29:49)