mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 17:44:30 +08:00
e7f251c105
FIX: history revision can now properly be hidden FIX: PostRevision serializer is now entirely dynamic to properly handle hidden revisions FIX: default history modal to "side by side" view on mobile FIX: properly hiden which revision has been hidden UX: inline category/user/wiki/post_type changes with the revision details FEATURE: new '/posts/:post_id/revisions/latest' endpoint to retrieve latest revision UX: do not show the hide/show revision button on mobile (no room for them) UX: remove CSS transitions on the buttons in the history modal FIX: PostRevisor now handles all the changes that might create new revisions FIX: PostRevision.ensure_consistency! was wrong due to off by 1 mistake... refactored topic's callbacks for better readability extracted 'PostRevisionGuardian'
85 lines
2.9 KiB
Ruby
85 lines
2.9 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Draft do
|
|
before do
|
|
@user = Fabricate(:user)
|
|
end
|
|
it "can get a draft by user" do
|
|
Draft.set(@user, "test", 0, "data")
|
|
Draft.get(@user, "test", 0).should == "data"
|
|
end
|
|
|
|
it "uses the user id and key correctly" do
|
|
Draft.set(@user, "test", 0,"data")
|
|
Draft.get(Fabricate.build(:coding_horror), "test", 0).should == nil
|
|
end
|
|
|
|
it "should overwrite draft data correctly" do
|
|
Draft.set(@user, "test", 0, "data")
|
|
Draft.set(@user, "test", 0, "new data")
|
|
Draft.get(@user, "test", 0).should == "new data"
|
|
end
|
|
|
|
it "should clear drafts on request" do
|
|
Draft.set(@user, "test", 0, "data")
|
|
Draft.clear(@user, "test", 0)
|
|
Draft.get(@user, "test", 0).should == nil
|
|
end
|
|
|
|
it "should disregard old draft if sequence decreases" do
|
|
Draft.set(@user, "test", 0, "data")
|
|
Draft.set(@user, "test", 1, "hello")
|
|
Draft.set(@user, "test", 0, "foo")
|
|
Draft.get(@user, "test", 0).should == nil
|
|
Draft.get(@user, "test", 1).should == "hello"
|
|
end
|
|
|
|
|
|
context 'key expiry' do
|
|
it 'nukes new topic draft after a topic is created' do
|
|
u = Fabricate(:user)
|
|
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
|
_t = Fabricate(:topic, user: u)
|
|
s = DraftSequence.current(u, Draft::NEW_TOPIC)
|
|
Draft.get(u, Draft::NEW_TOPIC, s).should == nil
|
|
end
|
|
|
|
it 'nukes new pm draft after a pm is created' do
|
|
u = Fabricate(:user)
|
|
Draft.set(u, Draft::NEW_PRIVATE_MESSAGE, 0, 'my draft')
|
|
t = Fabricate(:topic, user: u, archetype: Archetype.private_message, category_id: nil)
|
|
s = DraftSequence.current(t.user, Draft::NEW_PRIVATE_MESSAGE)
|
|
Draft.get(u, Draft::NEW_PRIVATE_MESSAGE, s).should == nil
|
|
end
|
|
|
|
it 'does not nuke new topic draft after a pm is created' do
|
|
u = Fabricate(:user)
|
|
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
|
t = Fabricate(:topic, user: u, archetype: Archetype.private_message, category_id: nil)
|
|
s = DraftSequence.current(t.user, Draft::NEW_TOPIC)
|
|
Draft.get(u, Draft::NEW_TOPIC, s).should == 'my draft'
|
|
end
|
|
|
|
it 'nukes the post draft when a post is created' do
|
|
user = Fabricate(:user)
|
|
topic = Fabricate(:topic)
|
|
p = PostCreator.new(user, raw: Fabricate.build(:post).raw, topic_id: topic.id).create
|
|
Draft.set(p.user, p.topic.draft_key, 0,'hello')
|
|
|
|
PostCreator.new(user, raw: Fabricate.build(:post).raw).create
|
|
Draft.get(p.user, p.topic.draft_key, DraftSequence.current(p.user, p.topic.draft_key)).should == nil
|
|
end
|
|
|
|
it 'nukes the post draft when a post is revised' do
|
|
p = Fabricate(:post)
|
|
Draft.set(p.user, p.topic.draft_key, 0,'hello')
|
|
p.revise(p.user, { raw: 'another test' })
|
|
s = DraftSequence.current(p.user, p.topic.draft_key)
|
|
Draft.get(p.user, p.topic.draft_key, s).should == nil
|
|
end
|
|
|
|
it 'increases the sequence number when a post is revised' do
|
|
end
|
|
end
|
|
end
|