discourse/spec/models/upload_spec.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
require 'spec_helper'
describe Upload do
it { should belong_to :user }
it { should belong_to :topic }
2013-04-07 23:52:46 +08:00
2013-02-06 03:16:51 +08:00
it { should validate_presence_of :original_filename }
it { should validate_presence_of :filesize }
2013-04-07 23:52:46 +08:00
context '.create_for' do
let(:user_id) { 1 }
let(:topic_id) { 42 }
let(:logo) do
ActionDispatch::Http::UploadedFile.new({
filename: 'logo.png',
content_type: 'image/png',
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo.png")
})
end
2013-06-05 06:34:53 +08:00
let(:upload) { Upload.create_for(user_id, logo, topic_id) }
2013-04-07 23:52:46 +08:00
2013-06-05 06:34:53 +08:00
let(:url) { "http://domain.com" }
2013-04-07 23:52:46 +08:00
shared_examples_for "upload" do
it "is valid" do
2013-06-05 06:34:53 +08:00
upload.user_id.should == user_id
upload.topic_id.should == topic_id
upload.original_filename.should == logo.original_filename
2013-06-05 06:34:53 +08:00
upload.filesize.should == File.size(logo.tempfile)
upload.width.should == 244
upload.height.should == 66
2013-06-05 06:34:53 +08:00
upload.url.should == url
end
end
2013-06-05 06:34:53 +08:00
context "imgur" do
before(:each) do
2013-06-05 06:34:53 +08:00
SiteSetting.stubs(:enable_imgur?).returns(true)
Imgur.stubs(:store_file).returns(url)
end
it_behaves_like "upload"
2013-04-07 23:52:46 +08:00
end
2013-06-05 06:34:53 +08:00
context "s3" do
before(:each) do
2013-06-05 06:34:53 +08:00
SiteSetting.stubs(:enable_s3_uploads?).returns(true)
S3.stubs(:store_file).returns(url)
end
it_behaves_like "upload"
2013-04-07 23:52:46 +08:00
end
2013-06-05 06:34:53 +08:00
context "locally" do
before(:each) { LocalStore.stubs(:store_file).returns(url) }
it_behaves_like "upload"
2013-04-07 23:52:46 +08:00
end
end
2013-02-06 03:16:51 +08:00
end