2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe DraftSequence do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2017-09-15 04:44:04 -04:00
|
|
|
|
2020-05-12 01:56:24 -04:00
|
|
|
describe '.next' do
|
|
|
|
it 'should produce next sequence for a key' do
|
|
|
|
expect(DraftSequence.next!(user, 'test')).to eq 1
|
|
|
|
expect(DraftSequence.next!(user, 'test')).to eq 2
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not produce next sequence for non-human user' do
|
|
|
|
user.id = -99999
|
|
|
|
2.times { expect(DraftSequence.next!(user, 'test')).to eq(0) }
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2017-09-15 04:44:04 -04:00
|
|
|
describe '.current' do
|
|
|
|
it 'should return 0 by default' do
|
|
|
|
expect(DraftSequence.current(user, 'test')).to eq 0
|
|
|
|
end
|
|
|
|
|
2020-05-12 01:56:24 -04:00
|
|
|
it 'should return nil for non-human user' do
|
|
|
|
user.id = -99999
|
2020-05-14 22:39:39 -04:00
|
|
|
expect(DraftSequence.current(user, 'test')).to eq(0)
|
2020-05-12 01:56:24 -04:00
|
|
|
end
|
|
|
|
|
2017-09-15 04:44:04 -04:00
|
|
|
it 'should return the right sequence' do
|
|
|
|
expect(DraftSequence.next!(user, 'test')).to eq(1)
|
|
|
|
expect(DraftSequence.current(user, 'test')).to eq(1)
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|