2018-04-19 19:30:31 +08:00
|
|
|
require 'rails_helper'
|
2018-06-05 15:29:17 +08:00
|
|
|
require_dependency 'validators/upload_validator'
|
2018-04-19 19:30:31 +08:00
|
|
|
|
|
|
|
describe Validators::UploadValidator do
|
|
|
|
subject(:validator) { described_class.new }
|
|
|
|
|
|
|
|
describe 'validate' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:filename) { "discourse.csv" }
|
|
|
|
let(:csv_file) { file_from_fixtures(filename, "csv") }
|
|
|
|
|
|
|
|
it "should create an invalid upload when the filename is blank" do
|
|
|
|
SiteSetting.authorized_extensions = "*"
|
|
|
|
created_upload = UploadCreator.new(csv_file, nil).create_for(user.id)
|
|
|
|
validator.validate(created_upload)
|
|
|
|
expect(created_upload).to_not be_valid
|
2018-04-20 03:09:12 +08:00
|
|
|
expect(created_upload.errors.full_messages.first).to include(I18n.t("activerecord.errors.messages.blank"))
|
2018-04-19 19:30:31 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows 'gz' as extension when uploading export file" do
|
|
|
|
SiteSetting.authorized_extensions = ""
|
|
|
|
|
|
|
|
created_upload = UploadCreator.new(csv_file, "#{filename}.gz", for_export: true).create_for(user.id)
|
|
|
|
expect(created_upload).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|