mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
Refactor and expand Paper validations
This commit is contained in:
parent
5dcbc7c73d
commit
631dca322c
6 changed files with 90 additions and 9 deletions
|
@ -3,14 +3,50 @@ require 'test_helper'
|
|||
class PaperTest < ActiveSupport::TestCase
|
||||
|
||||
context "Validations" do
|
||||
should validate_presence_of(:body)
|
||||
should validate_presence_of(:content)
|
||||
should validate_presence_of(:name)
|
||||
should validate_presence_of(:originator)
|
||||
should validate_presence_of(:paper_type)
|
||||
should validate_presence_of(:reference)
|
||||
should validate_length_of(:name).is_at_most(1000)
|
||||
|
||||
should validate_presence_of(:url)
|
||||
should validate_presence_of(:published_at)
|
||||
should validate_length_of(:url).is_at_most(1000)
|
||||
context "URL uniqueness" do
|
||||
subject { FactoryGirl.build(:paper) }
|
||||
should validate_uniqueness_of(:url)
|
||||
end
|
||||
should "validate url format sane" do
|
||||
expected_error = "ist keine gültige URL"
|
||||
paper = FactoryGirl.build(:paper, url: "wtf")
|
||||
assert_not paper.valid?, "Expected paper to not be valid with invalid URL"
|
||||
assert_not paper.errors[:url].empty?
|
||||
assert paper.errors[:url].include?(expected_error), "Expected #{paper.errors[:url]} to include \"#{expected_error}\""
|
||||
end
|
||||
|
||||
should validate_presence_of(:reference)
|
||||
should validate_length_of(:reference).is_at_most(100)
|
||||
|
||||
should validate_presence_of(:body)
|
||||
should validate_length_of(:body).is_at_most(100)
|
||||
|
||||
should validate_presence_of(:content)
|
||||
should validate_length_of(:content).is_at_most(100_000)
|
||||
|
||||
should validate_presence_of(:originator)
|
||||
should validate_length_of(:originator).is_at_most(300)
|
||||
|
||||
should validate_presence_of(:paper_type)
|
||||
should validate_length_of(:paper_type).is_at_most(50)
|
||||
|
||||
context "published_at" do
|
||||
should validate_presence_of(:published_at)
|
||||
should "validate date is parseable" do
|
||||
expected_error = "ist kein gültiges Datum"
|
||||
paper = FactoryGirl.build(:paper, published_at: "fubar")
|
||||
assert_not paper.valid?
|
||||
assert_not paper.errors[:published_at].empty?
|
||||
assert paper.errors[:published_at].include?(expected_error), "Expected #{paper.errors[:published_at]} to include \"#{expected_error}\""
|
||||
end
|
||||
end
|
||||
|
||||
should validate_length_of(:resolution).is_at_most(30_000)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue