Add documentables helper
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
shared_examples "document validations" do |documentable_factory|
|
||||
include DocumentsHelper
|
||||
include DocumentablesHelper
|
||||
|
||||
let(:document) { build(:document, documentable_factory.to_sym) }
|
||||
let(:max_file_size) { document.documentable.class.max_file_size }
|
||||
let(:accepted_content_types) { document.documentable.class.accepted_content_types }
|
||||
let!(:document) { build(:document, documentable_factory.to_sym) }
|
||||
let!(:maxfilesize) { max_file_size(document.documentable) }
|
||||
let!(:acceptedcontenttypes) { accepted_content_types(document.documentable) }
|
||||
|
||||
it "should be valid" do
|
||||
expect(document).to be_valid
|
||||
@@ -21,7 +23,7 @@ shared_examples "document validations" do |documentable_factory|
|
||||
end
|
||||
|
||||
it "should be valid for all accepted content types" do
|
||||
accepted_content_types.each do |content_type|
|
||||
acceptedcontenttypes.each do |content_type|
|
||||
extension = content_type.split("/").last
|
||||
document.attachment = File.new("spec/fixtures/files/empty.#{extension}")
|
||||
|
||||
@@ -30,10 +32,10 @@ shared_examples "document validations" do |documentable_factory|
|
||||
end
|
||||
|
||||
it "should not be valid for attachments larger than documentable max_file_size definition" do
|
||||
document.stub(:attachment_file_size).and_return(max_file_size.bytes + 1.byte)
|
||||
document.stub(:attachment_file_size).and_return(maxfilesize.megabytes + 1.byte)
|
||||
|
||||
expect(document).to_not be_valid
|
||||
expect(document.errors[:attachment]).to include "must be in between 0 Bytes and #{bytesToMeg(max_file_size)} MB"
|
||||
expect(document.errors[:attachment]).to include "must be in between 0 Bytes and #{maxfilesize} MB"
|
||||
end
|
||||
|
||||
it "should not be valid without a user_id" do
|
||||
@@ -54,8 +56,4 @@ shared_examples "document validations" do |documentable_factory|
|
||||
expect(document).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def bytesToMeg(bytes)
|
||||
bytes / (1024.0 * 1024.0)
|
||||
end
|
||||
Reference in New Issue
Block a user