Testing Paperclip - post :create fails

I have a video model using Paperclip to store the file. The model:

class Video < ActiveRecord::Base
  belongs_to :category
  before_save :permalink

  validates_presence_of :title
  validates_presence_of :category
  validates_attachment_presence :filepath, :message => '- please,
select a file to updload'
  validates_attachment_size :filepath, :less_than => 100.megabytes
  validates_attachment_content_type :filepath, :content_type =>
['video/x-flv'],
                                           :message => '- You can
upload only Flash movies'

  has_attached_file :filepath,
                    :url => APP_CONFIG['url']+"/videos/inline/:id",
                    :path => ":rails_root/
uploads/:attachment/:id/:style/:basename.:extension"

  named_scope :videos_in_category,
    lambda { |category_id|
      {:conditions => ["category_id = ?", category_id]}
      }

  private
    def permalink
      slug = Slug.new
      self.url_slug = slug.url_friendly self.title
    end
end

When I run this test:

  test "should create video" do
    assert_difference('Video.count') do
      video = videos :videos_002
      video.filepath = File.new("#{RAILS_ROOT}/test/fixtures/
add_file.flv")
      video.filepath_content_type = 'video/x-flv'
      category = categories(:intranet_administration)
      post :create, :video => { :title => video.title,
                                :description => video.description,
                                :category_id => category.id,
                                :filepath => video.filepath,
                                :filepath_file_size =>
File.size("#{RAILS_ROOT}/test/fixtures/add_file.flv"),
                                :filepath_content_type => 'video/x-
flv',
                                :url_slug => video.url_slug}
    end

    assert_redirected_to video_path(assigns(:video))
  end

I get this message:

"Video.count" didn't change by 1.
<2> expected but was
<1>.

I tried to understand why it is not created but I do not get any
feedback. Do you have an idea how to solve this?

Thanks.

Any idea how to debug?

rtacconi wrote:

Any idea how to debug?

Have a look at this example help me understand paperclip.

http://www.cordinc.com/blog/2009/04/multiple-attachments-with-vali.html

Just i noted from your code you are not using

"belongs_to :attachable" in your model video.

I will have a look thank you.