FIX: only send originalText when we need to

This commit is contained in:
Régis Hanol
2018-11-14 17:47:59 +01:00
parent 1e15c16f77
commit c78dcde973
5 changed files with 65 additions and 57 deletions

View File

@ -8,9 +8,15 @@ describe DraftController do
it 'saves a draft on update' do
user = sign_in(Fabricate(:user))
post "/draft.json", params: { draft_key: 'xyz', data: 'my data', sequence: 0 }
post "/draft.json", params: {
draft_key: 'xyz',
data: { my: "data" }.to_json,
sequence: 0
}
expect(response.status).to eq(200)
expect(Draft.get(user, 'xyz', 0)).to eq('my data')
expect(Draft.get(user, 'xyz', 0)).to eq(%q({"my":"data"}))
end
it 'checks for an conflict on update' do
@ -21,9 +27,10 @@ describe DraftController do
username: user.username,
draft_key: "topic",
sequence: 0,
data: "{}",
post_id: post.id,
original_text: post.raw
data: {
postId: post.id,
originalText: post.raw
}.to_json
}
expect(JSON.parse(response.body)['conflict_user']).to eq(nil)
@ -32,13 +39,16 @@ describe DraftController do
username: user.username,
draft_key: "topic",
sequence: 0,
data: "{}",
post_id: post.id,
original_text: "something else"
data: {
postId: post.id,
originalText: "something else"
}.to_json
}
expect(JSON.parse(response.body)['conflict_user']['id']).to eq(post.last_editor.id)
expect(JSON.parse(response.body)['conflict_user']).to include('avatar_template')
json = JSON.parse(response.body)
expect(json['conflict_user']['id']).to eq(post.last_editor.id)
expect(json['conflict_user']).to include('avatar_template')
end
it 'destroys drafts when required' do