number_spec.rb 1.1 KB

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