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?

croceldon
  • 4,511
  • 11
  • 57
  • 92
  • Have you run paperclips internal tests against your setup? To ensure that it's not something coming from paperclip it self? – Ekampp Apr 04 '12 at 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#validate_attachment_presence-instance_method – croceldon Apr 05 '12 at 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 Apr 08 '12 at 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 Apr 15 '12 at 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 Apr 16 '12 at 00:32
  • This is a paperclip bug and can be referenced below: Visit – Yahya Jun 03 '13 at 08:08

1 Answers1

2

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

rkallensee
  • 1,994
  • 15
  • 12