Why does my Paperclip validates_attachment_presence test fail?

Go To StackoverFlow.com

0

In my Rails 3.2.2 project, I have the following:

class Photo < ActiveRecord::Base
  belongs_to :album
  default_scope order: :title

  extend FriendlyId
  friendly_id :title, :use => :slugged
  validates :title, :presence => true
  validates :title, :uniqueness => {:scope => :album_id}
  validates :file, :attachment_presence => true

  has_attached_file :file, :path => (Rails.root + "photos/:id/:style/:filename").to_s,
                           :url => "/photos/:style/:id",
                           :styles => { :small => "450x450>"}
end

class PhotoTest < ActiveSupport::TestCase
  should belong_to(:album)

  should validate_presence_of(:title)
  should have_attached_file(:file)
  should validate_attachment_presence(:file)
end

The 'should validate_attachment_presence(:file)' test always flunks, but I can't figure out why. I have other unit tests with required attachments that test out fine.

Any ideas?

2012-04-04 16:55
by croceldon
Have you run paperclips internal tests against your setup? To ensure that it's not something coming from paperclip it self - Ekampp 2012-04-04 21:24
Not sure what you mean. I'm trying to use the Paperclip matchers, as described at http://rdoc.info/github/thoughtbot/paperclip/Paperclip/Shoulda/Matchers#validateattachmentpresence-instance_metho - croceldon 2012-04-05 13:16
Firstly, you should open the paperclip gem in your terminal: cd to/where/paperclip/is/located and then run bundle install to install dependencies. You then run rake or rake test (can't remember which) to test paperclip against your system, to see if there is something wrong with paperclip setup on your system - Ekampp 2012-04-08 13:16
I have the exact same problem with Rails 3.2.3, Paperclip 3.0.2 and on Ruby 1.9.3-p125. The should validate_attachment_presence(:file) always fails. As suggested by @Ekampp I ran the Paperclip tests, but they finished without any errors - rkallensee 2012-04-15 15:00
Hmm.. The I have no idea as to the problem. I have had paperclip running fine on a 3.2.1 app, maybe there was something that changed from 3.2.1 to 3.2.2 - Ekampp 2012-04-16 00:32
This is a paperclip bug and can be referenced below: Visit https://github.com/thoughtbot/paperclip/issues/1194Yahya 2013-06-03 08:08


2

For me the problem disappeared after I upgraded to Paperclip 3.0.3 - seems like the bug is now fixed.

2012-05-05 17:03
by rkallensee
This did the trick for me as well - edralph 2012-06-11 18:11
Ads