2015-09-27 10:25:40 +02:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class PaperTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
context "Validations" do
|
2015-09-27 13:51:13 +02:00
|
|
|
should validate_presence_of(:name)
|
|
|
|
should validate_length_of(:name).is_at_most(1000)
|
|
|
|
|
|
|
|
should validate_presence_of(:url)
|
|
|
|
should validate_length_of(:url).is_at_most(1000)
|
|
|
|
context "URL uniqueness" do
|
2018-03-18 21:21:59 +01:00
|
|
|
subject { FactoryBot.build(:paper) }
|
2015-09-27 13:51:13 +02:00
|
|
|
should validate_uniqueness_of(:url)
|
|
|
|
end
|
|
|
|
should "validate url format sane" do
|
|
|
|
expected_error = "ist keine gültige URL"
|
2018-03-18 21:21:59 +01:00
|
|
|
paper = FactoryBot.build(:paper, url: "wtf")
|
2015-09-27 13:51:13 +02:00
|
|
|
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)
|
|
|
|
|
2015-09-27 10:25:40 +02:00
|
|
|
should validate_presence_of(:body)
|
2015-09-27 13:51:13 +02:00
|
|
|
should validate_length_of(:body).is_at_most(100)
|
|
|
|
|
2015-09-27 10:25:40 +02:00
|
|
|
should validate_presence_of(:content)
|
2015-09-27 13:51:13 +02:00
|
|
|
should validate_length_of(:content).is_at_most(100_000)
|
|
|
|
|
2015-09-27 10:25:40 +02:00
|
|
|
should validate_presence_of(:originator)
|
2015-09-27 13:51:13 +02:00
|
|
|
should validate_length_of(:originator).is_at_most(300)
|
|
|
|
|
2015-09-27 10:25:40 +02:00
|
|
|
should validate_presence_of(:paper_type)
|
2015-09-27 13:51:13 +02:00
|
|
|
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"
|
2018-03-18 21:21:59 +01:00
|
|
|
paper = FactoryBot.build(:paper, published_at: "fubar")
|
2015-09-27 13:51:13 +02:00
|
|
|
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)
|
2015-09-27 10:25:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|