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:invalidates_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:ineach’
    /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:incall’
    /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:ineach’
    /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:invalid_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:insend’
    /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:inbefore_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:incallback’
    /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:insave_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:insave’
    /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:intransaction’
    /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:insave’
    /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:inmethod_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:insend’
    /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:increate_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:increate_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:insave_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:insave’
    /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:intransaction’
    /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:insave’
    ./test/unit/vote_test.rb:16:in test_vote_creation_and_deletion' ./test/unit/vote_test.rb:13:intimes’
    ./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.
[email protected]

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
[email protected]

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.
[email protected]

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs