number_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Number do
  4. let(:stubbed_subclass) { double('Foo') }
  5. before { stub_const('Ticket::Number::Foo', stubbed_subclass) }
  6. describe '.generate' do
  7. before { Setting.set('ticket_number', 'Ticket::Number::Foo') }
  8. it 'defers to subclass specified in "ticket_number" setting' do
  9. expect(Ticket::Number::Foo).to receive(:generate)
  10. expect(described_class.generate).to be_nil
  11. end
  12. end
  13. describe '.check' do
  14. before { Setting.set('ticket_number', 'Ticket::Number::Foo') }
  15. it 'defers to subclass specified in "ticket_number" setting' do
  16. expect(Ticket::Number::Foo).to receive(:check).with('foo')
  17. expect(described_class.check('foo')).to be_nil
  18. end
  19. end
  20. describe '.adapter' do
  21. it 'defaults to Ticket::Number::Increment' do
  22. expect(described_class.adapter).to be(Ticket::Number::Increment)
  23. end
  24. it 'depends on "ticket_number" setting' do
  25. expect { Setting.set('ticket_number', 'Ticket::Number::Foo') }
  26. .to change(described_class, :adapter).to(Ticket::Number::Foo)
  27. end
  28. end
  29. end