Add missing image model spec. Add shared specs to check image validations at any imageable model
This commit is contained in:
@@ -296,7 +296,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
||||
from: send(documentable_path, arguments))
|
||||
|
||||
expect(page).to have_content "You can upload up to a maximum of #{max_file_size(documentable)} documents."
|
||||
expect(page).to have_content "You can upload #{documentable_humanized_accepted_content_types(documentable)} files."
|
||||
expect(page).to have_content "You can upload #{documentable_humanized_accepted_content_types(documentable.class)} files."
|
||||
expect(page).to have_content "You can upload files up to #{max_file_size(documentable)} MB."
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ shared_examples "document validations" do |documentable_factory|
|
||||
let!(:document) { build(:document, documentable_factory.to_sym) }
|
||||
let!(:documentable) { document.documentable }
|
||||
let!(:maxfilesize) { max_file_size(document.documentable) }
|
||||
let!(:acceptedcontenttypes) { accepted_content_types(document.documentable) }
|
||||
let!(:acceptedcontenttypes) { accepted_content_types(document.documentable.class) }
|
||||
|
||||
it "should be valid" do
|
||||
expect(document).to be_valid
|
||||
|
||||
70
spec/shared/models/image_validations.rb
Normal file
70
spec/shared/models/image_validations.rb
Normal file
@@ -0,0 +1,70 @@
|
||||
shared_examples "image validations" do |imageable_factory|
|
||||
include ImagesHelper
|
||||
include ImageablesHelper
|
||||
|
||||
let!(:image) { build(:image, imageable_factory.to_sym) }
|
||||
let!(:imageable) { image.imageable }
|
||||
let!(:acceptedcontenttypes) { imageable_accepted_content_types }
|
||||
|
||||
it "should be valid" do
|
||||
expect(image).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a title" do
|
||||
image.title = nil
|
||||
|
||||
expect(image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without an attachment" do
|
||||
image.attachment = nil
|
||||
|
||||
expect(image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should be valid for all accepted content types" do
|
||||
acceptedcontenttypes.each do |content_type|
|
||||
extension = content_type.split("/").last
|
||||
image.attachment = File.new("spec/fixtures/files/clippy.#{extension}")
|
||||
|
||||
expect(image).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "should not be valid for png and gif image content types" do
|
||||
["gif", "png"].each do |content_type|
|
||||
extension = content_type.split("/").last
|
||||
image.attachment = File.new("spec/fixtures/files/clippy.#{extension}")
|
||||
|
||||
expect(image).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "should not be valid for attachments larger than imageable max_file_size definition" do
|
||||
image.stub(:attachment_file_size).and_return(Image::MAX_IMAGE_SIZE + 1.byte)
|
||||
|
||||
expect(image).to_not be_valid
|
||||
expect(image.errors[:attachment]).to include "must be in between 0 Bytes and 1 MB"
|
||||
end
|
||||
|
||||
it "should not be valid without a user_id" do
|
||||
image.user_id = nil
|
||||
|
||||
expect(image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a imageable_id" do
|
||||
image.save
|
||||
image.imageable_id = nil
|
||||
|
||||
expect(image).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a imageable_type" do
|
||||
image.save
|
||||
image.imageable_type = nil
|
||||
|
||||
expect(image).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user