0
在我的Rails 3.2.2項目,我有以下幾點:爲什麼我的Paperclip validates_attachment_presence測試失敗?
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
的 '應該validate_attachment_presence(:文件)' 測試總是flunks,但我想不出爲什麼。我有其他的單元測試,需要測試的附件。
任何想法?
您是否針對您的設置運行了回形針內部測試?確保它不是來自回形針的東西嗎? – Ekampp 2012-04-04 21:24:12
不確定你的意思。我試圖使用Paperclip匹配器,如http://rdoc.info/github/thoughtbot/paperclip/Paperclip/Shoulda/Matchers#validate_attachment_presence-instance_method – croceldon 2012-04-05 13:16:20
中所述,首先,您應該在終端中打開回形針gem:' cd到/ where/paperclip/is/located',然後運行'bundle install'安裝依賴關係。然後運行'rake'或'rake test'(不記得是哪一個)來針對您的系統測試回形針,以查看系統上的回形針設置是否有問題。 – Ekampp 2012-04-08 13:16:59