adds model validations for legislation proposals

This commit is contained in:
rgarcia
2017-12-13 12:52:25 +01:00
parent d49a1dc208
commit abaf6ab785
3 changed files with 39 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ class Legislation::Proposal < ActiveRecord::Base
validates :title, presence: true
validates :summary, presence: true
validates :author, presence: true
validates :process, presence: true
validates :title, length: { in: 4..Legislation::Proposal.title_max_length }
validates :description, length: { maximum: Legislation::Proposal.description_max_length }

View File

@@ -816,6 +816,14 @@ LOREM_IPSUM
user
end
factory :legislation_proposal, class: 'Legislation::Proposal' do
title "Example proposal for a legislation"
summary "This law should include..."
terms_of_service '1'
process factory: :legislation_process
author factory: :user
end
factory :site_customization_page, class: 'SiteCustomization::Page' do
slug "example-page"
title "Example page"

View File

@@ -0,0 +1,30 @@
require 'rails_helper'
describe Legislation::Proposal do
let(:proposal) { build(:legislation_proposal) }
it "should be valid" do
expect(proposal).to be_valid
end
it "should not be valid without a process" do
proposal.process = nil
expect(proposal).to_not be_valid
end
it "should not be valid without an author" do
proposal.author = nil
expect(proposal).to_not be_valid
end
it "should not be valid without a title" do
proposal.title = nil
expect(proposal).to_not be_valid
end
it "should not be valid without a summary" do
proposal.summary = nil
expect(proposal).to_not be_valid
end
end