Testing Paperclip Styles with Rspec

I have a banner with an attached file using paperclip. A clip will create derivatives for the loaded image using the styles parameter:

class Banner < ActiveRecord::Base has_attached_file :image, :styles => {:medium => "300x300>", :thumb => "100x100>"} end 

I want to test this attach_file creation, preferably without testing the whole roundtrip to disk and so on. I could create a banner, attach a file, and then look at the file system if a specific file with certain sizes is created, but this contradicts my idea of ​​testing the concentrated part, without testing the entire stack.

How to check if an attached file :image certain styles in a folder?

+4
source share
1 answer

The whole has_attached_file method is to add the passed definitions to the model. Generation is performed using a paper clip and does not need testing.

Source: https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip.rb#L174

However, you can verify that definitions are created correctly using the attachment_definitions method. Something like that:

 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 
+1
source

Source: https://habr.com/ru/post/1393029/


All Articles