Forum: Ruby on Rails Testing 'create' from multipart/form-data submission

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C0afdc1c900a8f7b429f786507e19758?d=identicon&s=25 Marcus Mitchell (marcuslee)
on 2006-01-12 12:16
good morning forum! :)

i'm looking to test the creation of a record from the submission of a
form with content-type="multipart/form-data" (uploading an image into a
BLOB field), currently i'm using a small binary string to simulate this
but for thoroughness i want to provide the test with a path to an image
on my filesystem and have it populate the db correctly...any idea what
the syntax for posting a form this way is?? (current code below)

  def test_create
    num_images = Image.count

    post(:create,
    	{:image => {
             'item_id' => 203,
    	     'primary_image' => 0,
             'data_orig' => '01010101',
    	     'data_medium' => '01010101',
    	     'data_thumb' => '01010101',
    	     'content_type' => 'image/jpg',
    	     'comment' => 'this is a comment'}})

    assert_response( :redirect )
    assert_redirected_to :action => 'list'
    assert_equal num_images + 1, Image.count
  end

many thanks, Marcus
This topic is locked and can not be replied to.