melekes/valle

carrierwave support

darkleaf opened this issue · 9 comments

class Person < ActiveRecord::Base  
  mount_uploader :photo, PersonUploader  #iphoto of type string in db
end
...
@attrs = attributes_for :person #FactoryGirl
puts @attrs[:photo] #=> #<Rack::Test::UploadedFile:0x00000005a73c30>
puts @attrs[:photo].length #=> 9759

I have validtion error because 9759 > string length(255).

@darkleaf Rack::Test::UploadedFile only in the TEST environment?
Which values ​​in other environments? Successful validation in them?

@saratovsource this fails both on production and testing. I think we have to add skip_autovalidation_on option to handle such cases.

Eg:

class Course < AR::Base
  skip_autovalidation_on :image
end

@akalyaev, I have not found such a method.

@darkleaf It will be, soon 😄

@akalyaev, I think that this method should have another name.
May be skip_valle_validation :image?

@darkleaf Why do you think so? skip_autovalidation_on clearly indicates what it does. I consider the addition of valle prefix not necessarily here.

/cc @saratovsource @qblake What do you think?

@darkleaf Now you can use attributes option to skip adding validation to photo field:

Valle.configure do |config|
  config.attributes = {
    'Person' => %w(id <other_attributes_except_photo>)
  }
end

May be easier to test class of field?
It skip validation if class isn't String.

@darkleaf see README for details