fixes for screenshot worker

This commit is contained in:
Kyle Drake 2014-08-20 13:48:20 -07:00
parent 0aca6b3328
commit fbf78f04d6
8 changed files with 69 additions and 2 deletions

View file

@ -17,6 +17,9 @@ Bundler.require :test
#require 'minitest/pride'
require 'minitest/autorun'
require 'webmock'
include WebMock::API
require 'webmock/minitest'
require 'sidekiq/testing'
Sinatra::Application.configure do |app|

8
tests/files/index.html Normal file
View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Hello?</title>
</head>
<body>
<h1>Hi there!</h1>
</body>
</html>

View file

@ -9,6 +9,24 @@ end
describe 'site_files' do
describe 'upload' do
it 'succeeds with index.html file' do
site = Fabricate :site
PurgeCacheWorker.jobs.clear
ScreenshotWorker.jobs.clear
post '/site_files/upload', {
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html'),
'csrf_token' => 'abcd'
}, {'rack.session' => { 'id' => site.id, '_csrf_token' => 'abcd' }}
last_response.body.must_match /successfully uploaded/i
File.exists?(site.files_path('index.html')).must_equal true
args = ScreenshotWorker.jobs.first['args']
args.first.must_equal site.username
args.last.must_equal 'index.html'
end
it 'succeeds with valid file' do
site = Fabricate :site
PurgeCacheWorker.jobs.clear

View file

@ -0,0 +1,28 @@
require_relative '../environment.rb'
describe ScreenshotWorker do
it 'saves a screenshot for a root html file' do
worker = ScreenshotWorker.new
worker.perform 'kyledrake', 'index.html'
site = Fabricate :site
Site::SCREENSHOT_RESOLUTIONS.each do |r|
File.exists?(File.join(Site::SCREENSHOTS_ROOT, 'kyledrake', "index.html.#{r}.jpg")).must_equal true
site.screenshot_url('index.html', r).must_equal(
File.join(Site::SCREENSHOTS_URL_ROOT, site.username, "index.html.#{r}.jpg")
)
end
end
it 'saves a screenshot for a path html file' do
worker = ScreenshotWorker.new
worker.perform 'kyledrake', 'derpie/derp/index.html'
site = Fabricate :site
Site::SCREENSHOT_RESOLUTIONS.each do |r|
File.exists?(File.join(Site::SCREENSHOTS_ROOT, 'kyledrake', "derpie/derp/index.html.#{r}.jpg")).must_equal true
site.screenshot_url('derpie/derp/index.html', r).must_equal(
File.join(Site::SCREENSHOTS_URL_ROOT, site.username, "derpie/derp/index.html.#{r}.jpg")
)
end
end
end