我有一个Post
模型,如下所示:
class Post < ApplicationRecord
has_attached_file :image,
styles: { large: "500X500",
medium: "300x300>",
thumb: "100x100#" }
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
答案 0 :(得分:0)
我不确定您真正想为什么编写测试,但是您可以使用Paperclip::Shoulda::Matchers编写简单的测试:
describe Post do
# For: `has_attached_file :image`
it { should have_attached_file(:image) }
# For: `validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/`
it { should validate_attachment_content_type(:image).
allowing('image/png', 'image/gif').
rejecting('text/plain', 'nonimage/something') }
end