require 'rails_helper' describe Upload do let(:upload) { build(:upload) } let(:thumbnail) { build(:optimized_image, upload: upload) } let(:user_id) { 1 } let(:url) { "http://domain.com" } let(:image_filename) { "logo.png" } let(:image) { file_from_fixtures(image_filename) } let(:image_filesize) { File.size(image) } let(:image_sha1) { Upload.generate_digest(image) } let(:image_svg_filename) { "image.svg" } let(:image_svg) { file_from_fixtures(image_svg_filename) } let(:image_svg_filesize) { File.size(image_svg) } let(:huge_image_filename) { "huge.jpg" } let(:huge_image) { file_from_fixtures(huge_image_filename) } let(:huge_image_filesize) { File.size(huge_image) } let(:attachment_path) { __FILE__ } let(:attachment) { File.new(attachment_path) } let(:attachment_filename) { File.basename(attachment_path) } let(:attachment_filesize) { File.size(attachment_path) } context ".create_thumbnail!" do it "does not create a thumbnail when disabled" do SiteSetting.create_thumbnails = false OptimizedImage.expects(:create_for).never upload.create_thumbnail!(100, 100) end it "creates a thumbnail" do upload = Fabricate(:upload) thumbnail = Fabricate(:optimized_image, upload: upload) SiteSetting.expects(:create_thumbnails?).returns(true) OptimizedImage.expects(:create_for).returns(thumbnail) upload.create_thumbnail!(100, 100) upload.reload expect(upload.optimized_images.count).to eq(1) end end it "supports