[英]Test paperclip image styles with Rspec
I have a Banner, with an attached file, using paperclip. 我有一个带有附件的横幅,使用回形针。 Paperclip will create "derivatives" for an uploaded image, using the "styles" parameter:
Paperclip将使用“styles”参数为上传的图像创建“衍生物”:
class Banner < ActiveRecord::Base
has_attached_file :image,
:styles => {:medium => "300x300>",
:thumb => "100x100>"}
end
I want to test this attached_file generation, preferably without testing the whole roundtrip to a disk and so on. 我想测试这个attach_file生成,最好不要测试整个往返到磁盘等等。 I could create a Banner, attach a file and then look on the filesystem if a certain file with certain dimensions is created, but that goes against my idea of testing a focused part, without testing the entire stack.
我可以创建一个Banner,附加一个文件然后查看文件系统,如果创建了某个具有特定尺寸的文件,但这违背了我测试焦点部分的想法,而不测试整个堆栈。
How can I test if the attached file :image
has certain styles in Paperclip? 如何测试附加文件
:image
在Paperclip中是否具有某些样式?
All the has_attached_file
method does is add the passed definitions to the model. 所有
has_attached_file
方法都将传递的定义添加到模型中。 The generation is done by paperclip and shouldn't need to be tested. 这一代是通过回形针完成的,不需要进行测试。
Source: https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip.rb#L174 资料来源: https : //github.com/thoughtbot/paperclip/blob/master/lib/paperclip.rb#L174
However, you could test that the definitions were created properly using the attachment_definitions
method. 但是,您可以使用
attachment_definitions
方法测试是否正确创建了定义。 Something like this: 像这样的东西:
it "has correct image style geometry" do
Banner.attachment_definitions[:data][:styles][:medium][:geometry].should == "300x300>"
Banner.attachment_definitions[:data][:styles][:thumb][:geometry].should == "100x100>"
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.