# File\_column and fixtures

**URL:** <https://www.ruby-forum.com/t/file-column-and-fixtures/112636>\
**Category:** Rails\
**Created:** [August 21, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/file-column-and-fixtures/112636 "2007-08-21T17:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [August 21, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/file-column-and-fixtures/112636/1 "2007-08-21T17:21:57Z")

</div>

Hi \*,  
I have a problem in creating fixtures for models with file\_column  
columns.

superman:  
id: 1  
image: superman.png

This generates:

1. Error:  
test\_vote\_creation\_and\_deletion(VoteTest):  
Errno::ENOENT: No such file or directory - /Users/ngw/zooppa/  
config/…/public/assets/image/image/1/superman.png  
/Users/ngw/zooppa/config/…/vendor/plugins/file\_column/lib/  
validations.rb:65:in `size' /Users/ngw/zooppa/config/../vendor/plugins/file_column/lib/ validations.rb:65:in`validates\_filesize\_of’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/validations.rb:302:in `validates_each' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/validations.rb:299:in`each’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/validations.rb:299:in `validates_each' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/validations.rb:822:in`call’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/validations.rb:822:in `run_validations' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/validations.rb:816:in`each’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/validations.rb:816:in `run_validations' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/validations.rb:780:in`valid\_without\_callbacks?’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/callbacks.rb:299:in `valid?' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/associations/association_proxy.rb:123:in`send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/associations/association\_proxy.rb:123:in `method_missing' /Users/ngw/zooppa/config/../app/models/ad.rb:32:in`before\_save’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/callbacks.rb:348:in `send' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/callbacks.rb:348:in`callback’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/callbacks.rb:241:in `create_or_update' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/base.rb:1545:in`save\_without\_validation’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/validations.rb:752:in `save_without_transactions' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/transactions.rb:129:in`save’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/connection\_adapters/abstract/database\_statements.rb:  
59:in `transaction' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/transactions.rb:95:in`transaction’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/transactions.rb:121:in `transaction' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/transactions.rb:129:in`save’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/associations/association\_proxy.rb:123:in `send' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/associations/association_proxy.rb:123:in`method\_missing’  
/Users/ngw/zooppa/config/…/app/models/vote.rb:32:in `after_create' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/callbacks.rb:348:in`send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/callbacks.rb:348:in `callback' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/callbacks.rb:255:in`create\_without\_timestamps’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/timestamp.rb:39:in `create' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/base.rb:1789:in`create\_or\_update\_without\_callbacks’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/callbacks.rb:242:in `create_or_update' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/base.rb:1545:in`save\_without\_validation’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/validations.rb:752:in `save_without_transactions' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/transactions.rb:129:in`save’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/connection\_adapters/abstract/database\_statements.rb:  
59:in `transaction' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/transactions.rb:95:in`transaction’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/  
active\_record/transactions.rb:121:in `transaction' /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/transactions.rb:129:in`save’  
./test/unit/vote\_test.rb:16:in `test_vote_creation_and_deletion' ./test/unit/vote_test.rb:13:in`times’  
./test/unit/vote\_test.rb:13:in `test\_vote\_creation\_and\_deletion’

What I don’t understand is why fixtures work for certain models and  
doesn’t work for others … I wrote unit tests for the Image model,  
but Rails complains about tests of another model that just loads  
those fixtures …

Someone has an idea ?

ngw

–  
Nicholas W.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [August 21, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/file-column-and-fixtures/112636/2 "2007-08-21T17:29:01Z")

</div>

From the looks of the error message, it looks like a validation is  
failing. Does  
/Users/ngw/zooppa/config/…/public/assets/image/image/1/superman.png  
exist?

Nicholas W. wrote:

> test\_vote\_creation\_and\_deletion(VoteTest):  
> /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/validations.rb:299:in  
> `valid_without_callbacks?' `callback’  
> /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/transactions.rb:95:in  
> /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/callbacks.rb:348:in  
> `create\_or\_update’  
> /opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/transactions.rb:121:in  
> but Rails complains about tests of another model that just loads those
> 
> >

–  
Sincerely,

William P.

[http://www.billpratt.net](http://www.billpratt.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [August 21, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/file-column-and-fixtures/112636/3 "2007-08-21T18:06:09Z")

</div>

Il giorno 21/ago/07, alle ore 17:27, William P. ha scritto:

> From the looks of the error message, it looks like a validation is  
> failing. Does /Users/ngw/zooppa/config/…/public/assets/image/image/  
> 1/superman.png exist?

No, at all.  
But all the other fixtures work, I thought I could fake it.  
I also have no idea on how to upload a file inside fixtures, so …  
You use file\_column ? How do you write fixtures ?

TIA,  
ngw

–  
Nicholas W.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [August 21, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/file-column-and-fixtures/112636/4 "2007-08-21T21:39:45Z")

</div>

Fixtures use your model to load the data, so in order to use a fixture,  
the data supplied must pass any validation you have in your model. One  
possibility would be to leave that column empty in your fixture and  
dynamically populate it in a test / helper. I don’t actually use that  
plugin, so I can’t really help there, but it seems you may need to dig  
into how it works a bit and glue something together. Does that plugin  
come with a test helper that you can use? Fixtures are processed as erb  
files so if there is a helper you can use to load data into that field,  
you could use it like:

image\_column: \<%= helper\_method -%\>

Hope this helps to at least steer you in the proper direction.

Nicholas W. wrote:

> You use file\_column ? How do you write fixtures ?
> 
> >

–  
Sincerely,

William P.
