default_spec.rb 850 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Validations::TicketArticleValidator::Default do
  4. it 'is called when a ticket article is created' do
  5. expect_any_instance_of(described_class).to receive(:validate)
  6. create(:ticket_article)
  7. end
  8. describe '#validate' do
  9. it 'passes with body present' do
  10. instance = build(:ticket_article, body: 'sample body')
  11. described_class.new(instance).validate
  12. expect(instance.errors).to be_blank
  13. end
  14. it 'fails if body is blank' do
  15. instance = build(:ticket_article, body: '')
  16. described_class.new(instance).validate
  17. expect(instance.errors).to have_attributes(
  18. errors: include(have_attributes(message: match(%r{Need at least an 'article body' field.})))
  19. )
  20. end
  21. end
  22. end