mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 10:25:02 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
41 lines
1.2 KiB
Ruby
41 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe DraftSequence do
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
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
|
|
|
|
it 'updates draft count' do
|
|
Draft.create!(user: user, draft_key: 'test', data: {})
|
|
expect(user.reload.user_stat.draft_count).to eq(1)
|
|
expect(DraftSequence.next!(user, 'test')).to eq 1
|
|
expect(user.reload.user_stat.draft_count).to eq(0)
|
|
end
|
|
end
|
|
|
|
describe '.current' do
|
|
it 'should return 0 by default' do
|
|
expect(DraftSequence.current(user, 'test')).to eq 0
|
|
end
|
|
|
|
it 'should return nil for non-human user' do
|
|
user.id = -99999
|
|
expect(DraftSequence.current(user, 'test')).to eq(0)
|
|
end
|
|
|
|
it 'should return the right sequence' do
|
|
expect(DraftSequence.next!(user, 'test')).to eq(1)
|
|
expect(DraftSequence.current(user, 'test')).to eq(1)
|
|
end
|
|
end
|
|
end
|