stadtratmonitor/spec/models/paper_spec.rb

55 lines
2 KiB
Ruby
Raw Permalink Normal View History

2020-03-09 11:27:52 +01:00
# frozen_string_literal: true
2016-02-17 08:36:16 +01:00
require 'rails_helper'
RSpec.describe Paper do
2020-03-09 11:27:52 +01:00
context 'Validations' do
2016-02-17 08:36:16 +01:00
it { should validate_presence_of(:name) }
2020-03-09 11:27:52 +01:00
it { should validate_length_of(:name).is_at_most(1000) }
2016-03-02 22:22:25 +01:00
it { should validate_presence_of(:url) }
it { should validate_length_of(:url).is_at_most(1000) }
2020-03-09 11:27:52 +01:00
context 'URL uniqueness' do
subject { FactoryBot.build(:paper) }
2016-03-02 22:22:25 +01:00
it { should validate_uniqueness_of(:url) }
end
2020-03-09 11:27:52 +01:00
it 'validate url format sane' do
expected_error = 'ist keine gültige URL'
paper = FactoryBot.build(:paper, url: 'wtf')
expect(paper).not_to be_valid, 'Expected paper to not be valid with invalid URL'
2016-03-02 22:22:25 +01:00
expect(paper.errors[:url]).not_to be_empty
expect(paper.errors[:url]).to include(expected_error), "Expected #{paper.errors[:url]} to include \"#{expected_error}\""
end
it { should validate_presence_of(:reference) }
it { should validate_length_of(:reference).is_at_most(100) }
it { should validate_presence_of(:body) }
it { should validate_length_of(:body).is_at_most(100) }
it { should validate_presence_of(:content) }
it { should validate_length_of(:content).is_at_most(100_000) }
it { should validate_presence_of(:originator) }
it { should validate_length_of(:originator).is_at_most(300) }
it { should validate_presence_of(:paper_type) }
it { should validate_length_of(:paper_type).is_at_most(50) }
2020-03-09 11:27:52 +01:00
context 'published_at' do
2016-03-02 22:22:25 +01:00
it { should validate_presence_of(:published_at) }
2020-03-09 11:27:52 +01:00
it 'validate date is parseable' do
expected_error = 'ist kein gültiges Datum'
paper = FactoryBot.build(:paper, published_at: 'fubar')
2016-03-02 22:22:25 +01:00
expect(paper).not_to be_valid
expect(paper.errors[:published_at]).not_to be_empty
expect(paper.errors[:published_at]).to include(expected_error), "Expected #{paper.errors[:published_at]} to include \"#{expected_error}\""
end
end
it { should validate_length_of(:resolution).is_at_most(30_000) }
2016-02-17 08:36:16 +01:00
end
end