Files
nairobi/spec/shared/models/document_validations.rb
Bertocq ed16a78f42 Enables RSpec/ExampleWording and fixes all issues
Both avoiding 'should' and repiting 'it' on the tests description
improves reading them and also makes all descriptions consistent.

Read about cop at http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWording
2018-01-07 01:03:45 +01:00

62 lines
1.7 KiB
Ruby

shared_examples "document validations" do |documentable_factory|
include DocumentsHelper
include DocumentablesHelper
let!(:document) { build(:document, documentable_factory.to_sym) }
let!(:documentable) { document.documentable }
let!(:maxfilesize) { max_file_size(document.documentable.class) }
let!(:acceptedcontenttypes) { accepted_content_types(document.documentable.class) }
it "is valid" do
expect(document).to be_valid
end
it "is not valid without a title" do
document.title = nil
expect(document).to_not be_valid
end
it "is not valid without an attachment" do
document.attachment = nil
expect(document).to_not be_valid
end
it "is valid for all accepted content types" do
acceptedcontenttypes.each do |content_type|
extension = content_type.split("/").last
document.attachment = File.new("spec/fixtures/files/empty.#{extension}")
expect(document).to be_valid
end
end
it "is not valid for attachments larger than documentable max_file_size definition" do
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 #{maxfilesize} MB"
end
it "is not valid without a user_id" do
document.user_id = nil
expect(document).to_not be_valid
end
it "is not valid without a documentable_id" do
document.save
document.documentable_id = nil
expect(document).to_not be_valid
end
it "is not valid without a documentable_type" do
document.save
document.documentable_type = nil
expect(document).to_not be_valid
end
end