# Testing Paperclip - post :create fails

**URL:** <https://www.ruby-forum.com/t/testing-paperclip-post-create-fails/183543>\
**Category:** Rails\
**Created:** [February 16, 2010, 10:54am UTC](https://www.ruby-forum.com/t/testing-paperclip-post-create-fails/183543 "2010-02-16T10:54:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rtacconi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@rtacconi](https://www.ruby-forum.com/u/rtacconi)\
**Post date:** [February 16, 2010, 10:54am UTC](https://www.ruby-forum.com/t/testing-paperclip-post-create-fails/183543/1 "2010-02-16T10:54:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rtacconi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@rtacconi](https://www.ruby-forum.com/u/rtacconi)\
**Post date:** [February 16, 2010, 2:37pm UTC](https://www.ruby-forum.com/t/testing-paperclip-post-create-fails/183543/2 "2010-02-16T14:37:24Z")

</div>

Any idea how to debug?

---

<div class="post-metadata">

**Author:** ![rtacconi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@rtacconi](https://www.ruby-forum.com/u/rtacconi)\
**Post date:** [February 18, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/testing-paperclip-post-create-fails/183543/3 "2010-02-18T16:51:43Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![rtacconi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@rtacconi](https://www.ruby-forum.com/u/rtacconi)\
**Post date:** [February 18, 2010, 6:02pm UTC](https://www.ruby-forum.com/t/testing-paperclip-post-create-fails/183543/4 "2010-02-18T18:02:41Z")

</div>

I will have a look thank you.
