Blog Home  Home Add to any service  
Beckshome.com: Thomas Beck's Blog - Functional Testing Attachment_Fu
Musings about technology and things tangentially related
 
 Saturday, July 21, 2007
I was performing functional tests on my models that employed Attachment_Fu this morning and thought it would be worthwhile to share the code since it was a bit of a hassle pulling it together. Kudos to Mike Subelsky for his introduction to functional testing Attachment_Fu. It got me going in the right direction. What proved difficult once again was the multi-model controller. Once I got over that hump, I was on my way. As you can see from all the detail in the HTTP POST below, that was not an entirely easy task.

class ProductsControllerTest < Test::Unit::TestCase
...
def test_create_with_user
    num_products = Product.count
    imgdata = fixture_file_upload('/files/image.png', 'image/png')
    audiodata = fixture_file_upload('/files/sound.mp3', 'audio/mpeg')
    post :create, {:product => {
            :name => "Widget",
            :description => "A small tool-like item",
            :weight => "3",
            :price => "19.99",
            :language_id => "1"
                   },
            :image => {:uploaded_data => imgdata},
            :audio => {:uploaded_data => audiodata} ,
            :html => { :multipart => true }
          },
          {:user_id => users(:valid_active_user).id}
    assert_response :redirect
    assert_redirected_to :action => 'show'
    assert_equal num_products + 1, Product.count
  end
  ...
  end

Monday, December 10, 2007 4:41:36 AM (Eastern Standard Time, UTC-05:00)
Hello Good website, I love, I hope you do better! !
Monday, December 10, 2007 4:41:55 AM (Eastern Standard Time, UTC-05:00)
Your website, I liked it, it has a collection!
Monday, March 03, 2008 9:11:30 AM (Eastern Standard Time, UTC-05:00)
Cool, the post.

Thanks for the information.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2008 Thomas Beck. Some rights reserved.

Creative Commons License