Add arguments to documentable concern to make it configurable for any recipient model.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
shared_examples "document validations" do |documentable_factory|
|
||||
|
||||
let(:document) { build(:document, documentable_factory.to_sym) }
|
||||
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 }
|
||||
|
||||
it "should be valid" do
|
||||
expect(document).to be_valid
|
||||
@@ -18,17 +20,20 @@ shared_examples "document validations" do |documentable_factory|
|
||||
expect(document).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid for attachment images" do
|
||||
document.attachment = File.new("spec/fixtures/files/logo_header.png")
|
||||
it "should be valid for all accepted content types" do
|
||||
accepted_content_types.each do |content_type|
|
||||
extension = content_type.split("/").last
|
||||
document.attachment = File.new("spec/fixtures/files/empty.#{extension}")
|
||||
|
||||
expect(document).to_not be_valid
|
||||
expect(document).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "should not be valid for attachment 3MB" do
|
||||
document.stub(:attachment_file_size).and_return(3.1.megabytes)
|
||||
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.should_not be_valid
|
||||
expect(document.errors[:attachment]).to include "must be in between 0 Bytes and 3 MB"
|
||||
expect(document).to_not be_valid
|
||||
expect(document.errors[:attachment]).to include "must be in between 0 Bytes and #{bytesToMeg(max_file_size)} MB"
|
||||
end
|
||||
|
||||
it "should not be valid without a user_id" do
|
||||
@@ -50,3 +55,7 @@ shared_examples "document validations" do |documentable_factory|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def bytesToMeg(bytes)
|
||||
bytes / (1024.0 * 1024.0)
|
||||
end
|
||||
Reference in New Issue
Block a user