# Faking Paperclip has\_attached\_file with Factory girl?

**URL:** <https://www.ruby-forum.com/t/faking-paperclip-has-attached-file-with-factory-girl/194226>\
**Category:** Rails\
**Created:** [September 1, 2010, 10:46am UTC](https://www.ruby-forum.com/t/faking-paperclip-has-attached-file-with-factory-girl/194226 "2010-09-01T10:46:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anders\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Anders\_P](https://www.ruby-forum.com/u/Anders_P)\
**Post date:** [September 1, 2010, 10:46am UTC](https://www.ruby-forum.com/t/faking-paperclip-has-attached-file-with-factory-girl/194226/1 "2010-09-01T10:46:20Z")

</div>

Hello!

I wonder if it’s possible to simulate Paperclip’s has\_attached\_file  
with Factory Girl and then test it with Rspec. I don’t get it to work.  
My factories.rb file looks like this:

Factory.define :user do |user|  
user.name “Anders”  
user.email “removed\_email\_address@domain.invalid”  
user.password “foobar”  
user.password\_confirmation “foobar”  
user.avatar\_file\_name “avatar”  
end

My Rspec test (users\_controller\_spec.rb) looks like this:

it “should have a profile image” do  
get :show, :id =\> @user  
should have\_attached\_file(:avatar)  
end

And I get the following error:

UsersController GET ‘show’ should have a profile image  
Failure/Error: @user = Factory(:user)  
undefined method `avatar\_file\_name=’ for #User:0x000001037cc550

I have followed these instructions,  
[GitHub - thoughtbot/paperclip: Easy file attachment management for ActiveRecord](http://github.com/thoughtbot/paperclip).

Any help would be greatly appreciated! I’m a newbie to Rails so it may  
be something simple.

Thanks!

// Anders

---

<div class="post-metadata">

**Author:** ![Anders\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Anders\_P](https://www.ruby-forum.com/u/Anders_P)\
**Post date:** [September 1, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/faking-paperclip-has-attached-file-with-factory-girl/194226/2 "2010-09-01T21:07:36Z")

</div>

I solved it by defining :avatar\_file\_name in attr\_accessor in my user  
model. Don’t know if it’s the best solution, comments?
