file_column and fixtures

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

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 Wieland wrote:

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

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 Wieland wrote: