diff --git a/spec/components/avatar_upload_service_spec.rb b/spec/components/avatar_upload_service_spec.rb index d33a2fab4..a003d2630 100644 --- a/spec/components/avatar_upload_service_spec.rb +++ b/spec/components/avatar_upload_service_spec.rb @@ -3,7 +3,7 @@ require "avatar_upload_service" describe AvatarUploadService do - let(:logo) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") } + let(:logo) { file_from_fixtures("logo.png") } let(:file) do ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', tempfile: logo }) diff --git a/spec/components/file_store/local_store_spec.rb b/spec/components/file_store/local_store_spec.rb index 63a6b8ac4..c8cbb53bb 100644 --- a/spec/components/file_store/local_store_spec.rb +++ b/spec/components/file_store/local_store_spec.rb @@ -6,7 +6,7 @@ describe FileStore::LocalStore do let(:store) { FileStore::LocalStore.new } let(:upload) { build(:upload) } - let(:uploaded_file) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") } + let(:uploaded_file) { file_from_fixtures("logo.png") } let(:optimized_image) { build(:optimized_image) } let(:avatar) { build(:upload) } diff --git a/spec/components/file_store/s3_store_spec.rb b/spec/components/file_store/s3_store_spec.rb index eff8b6e0b..b12a2d583 100644 --- a/spec/components/file_store/s3_store_spec.rb +++ b/spec/components/file_store/s3_store_spec.rb @@ -7,13 +7,13 @@ describe FileStore::S3Store do let(:store) { FileStore::S3Store.new } let(:upload) { build(:upload) } - let(:uploaded_file) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") } + let(:uploaded_file) { file_from_fixtures("logo.png") } let(:optimized_image) { build(:optimized_image) } - let(:optimized_image_file) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") } + let(:optimized_image_file) { file_from_fixtures("logo.png") } let(:avatar) { build(:upload) } - let(:avatar_file) { File.new("#{Rails.root}/spec/fixtures/images/logo-dev.png") } + let(:avatar_file) { file_from_fixtures("logo-dev.png") } before(:each) do SiteSetting.stubs(:s3_upload_bucket).returns("S3_Upload_Bucket") diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb index 030c7049f..08b731d6d 100644 --- a/spec/controllers/categories_controller_spec.rb +++ b/spec/controllers/categories_controller_spec.rb @@ -103,7 +103,7 @@ describe CategoriesController do describe "logged in" do let!(:user) { log_in(:admin) } - let(:logo) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") } + let(:logo) { file_from_fixtures("logo.png") } let(:upload) do ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', tempfile: logo }) end diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 074bda9a9..a1deb7b98 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -15,14 +15,14 @@ describe UploadsController do let(:logo) do ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', - tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo.png") + tempfile: file_from_fixtures("logo.png") }) end let(:logo_dev) do ActionDispatch::Http::UploadedFile.new({ filename: 'logo-dev.png', - tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo-dev.png") + tempfile: file_from_fixtures("logo-dev.png") }) end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 42ccc49be..66a4152ac 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1113,7 +1113,7 @@ describe UsersController do let!(:user) { log_in } - let(:logo) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") } + let(:logo) { file_from_fixtures("logo.png") } let(:user_image) do ActionDispatch::Http::UploadedFile.new({ filename: 'logo.png', tempfile: logo }) diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 545d6501c..d55b0df42 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -15,10 +15,9 @@ describe Upload do let(:user_id) { 1 } let(:url) { "http://domain.com" } - let(:image_path) { "#{Rails.root}/spec/fixtures/images/logo.png" } - let(:image) { File.new(image_path) } - let(:image_filename) { File.basename(image_path) } - let(:image_filesize) { File.size(image_path) } + let(:image) { file_from_fixtures("logo.png") } + let(:image_filename) { "logo.png" } + let(:image_filesize) { File.size(image) } let(:image_sha1) { Digest::SHA1.file(image).hexdigest } let(:attachment_path) { __FILE__ } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 682b37768..6ed30789f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -110,6 +110,12 @@ Spork.prefork do Time.stubs(:now).returns(Time.parse(now.to_s)) end + def file_from_fixtures(filename) + FileUtils.mkdir_p("#{Rails.root}/tmp/spec") unless Dir.exists?("#{Rails.root}/tmp/spec") + FileUtils.cp("#{Rails.root}/spec/fixtures/images/#{filename}", "#{Rails.root}/tmp/spec/#{filename}") + File.new("#{Rails.root}/tmp/spec/#{filename}") + end + end Spork.each_run do