Create new polymorphic model Document.
This commit is contained in:
@@ -368,6 +368,18 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :document do
|
||||
association :user, factory: :user
|
||||
|
||||
trait :proposal_document do
|
||||
association :documentable, factory: :proposal
|
||||
end
|
||||
|
||||
trait :budget_investment_document do
|
||||
association :documentable, factory: :budget_investment
|
||||
end
|
||||
end
|
||||
|
||||
factory :comment do
|
||||
association :commentable, factory: :debate
|
||||
user
|
||||
|
||||
8
spec/models/document_spec.rb
Normal file
8
spec/models/document_spec.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Document do
|
||||
|
||||
it_behaves_like "document validations", "budget_investment_document"
|
||||
it_behaves_like "document validations", "proposal_document"
|
||||
|
||||
end
|
||||
27
spec/shared/models/document_validatable.rb
Normal file
27
spec/shared/models/document_validatable.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
shared_examples "document validations" do |documentable_factory|
|
||||
|
||||
let(:documentable) { build(:document, documentable_factory.to_sym) }
|
||||
|
||||
it "should be valid" do
|
||||
expect(documentable).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a user_id" do
|
||||
documentable.user_id = nil
|
||||
|
||||
expect(documentable).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a documentable_id" do
|
||||
documentable.documentable_id = nil
|
||||
|
||||
expect(documentable).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a documentable_type" do
|
||||
documentable.documentable_type = nil
|
||||
|
||||
expect(documentable).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user