discourse/spec/models/draft_sequence_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe DraftSequence do
fab!(:user)
fab!(:upload)
2017-09-15 04:44:04 -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 = -99_999
2.times { expect(DraftSequence.next!(user, "test")).to eq(0) }
end
it "deletes old drafts and associated upload references" do
Draft.set(
user,
Draft::NEW_TOPIC,
0,
{
reply: "[#{upload.original_filename}|attachment](#{upload.short_url})",
action: "createTopic",
title: "New topic with an upload",
categoryId: 1,
tags: [],
archetypeId: "regular",
metaData: nil,
composerTime: 10_000,
typingTime: 10_000,
}.to_json,
)
expect { DraftSequence.next!(user, Draft::NEW_TOPIC) }.to change { Draft.count }.by(
-1,
).and change { UploadReference.count }.by(-1).and change {
user.reload.user_stat.draft_count
}.by(-1)
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
it "should return nil for non-human user" do
user.id = -99_999
expect(DraftSequence.current(user, "test")).to eq(0)
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