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
|
|
|
|
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)
|
|
|
|
|
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"
|
|
|
|
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)
|
2015-09-27 10:25:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|