2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-04-18 03:08:19 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Ticket::Number do
|
|
|
|
let(:stubbed_subclass) { double('Foo') }
|
|
|
|
|
2020-06-22 09:57:45 +00:00
|
|
|
before { stub_const('Ticket::Number::Foo', stubbed_subclass) }
|
2019-04-18 03:08:19 +00:00
|
|
|
|
|
|
|
describe '.generate' do
|
|
|
|
before { Setting.set('ticket_number', 'Ticket::Number::Foo') }
|
|
|
|
|
|
|
|
it 'defers to subclass specified in "ticket_number" setting' do
|
|
|
|
expect(Ticket::Number::Foo).to receive(:generate)
|
|
|
|
expect(described_class.generate).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.check' do
|
|
|
|
before { Setting.set('ticket_number', 'Ticket::Number::Foo') }
|
|
|
|
|
|
|
|
it 'defers to subclass specified in "ticket_number" setting' do
|
|
|
|
expect(Ticket::Number::Foo).to receive(:check).with('foo')
|
|
|
|
expect(described_class.check('foo')).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.adapter' do
|
|
|
|
it 'defaults to Ticket::Number::Increment' do
|
|
|
|
expect(described_class.adapter).to be(Ticket::Number::Increment)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'depends on "ticket_number" setting' do
|
|
|
|
expect { Setting.set('ticket_number', 'Ticket::Number::Foo') }
|
|
|
|
.to change(described_class, :adapter).to(Ticket::Number::Foo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|