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 =>
                                           :message => '- You can
upload only Flash movies'

  has_attached_file :filepath,
                    :url => APP_CONFIG['url']+"/videos/inline/:id",
                    :path => ":rails_root/

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

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

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/
      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 =>
                                :filepath_content_type => 'video/x-
                                :url_slug => video.url_slug}

    assert_redirected_to video_path(assigns(:video))

I get this message:

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

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?


Any idea how to debug?

rtacconi wrote:

Any idea how to debug?

Have a look at this example help me understand paperclip.


Just i noted from your code you are not using

"belongs_to :attachable" in your model video.

I will have a look thank you.