2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe DraftController do
|
|
|
|
it 'requires you to be logged in' do
|
2018-06-07 00:24:20 -04:00
|
|
|
post "/draft"
|
2018-01-11 22:15:10 -05:00
|
|
|
expect(response.status).to eq(403)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves a draft on update' do
|
2018-06-07 00:24:20 -04:00
|
|
|
user = sign_in(Fabricate(:user))
|
|
|
|
post "/draft.json", params: { draft_key: 'xyz', data: 'my data', sequence: 0 }
|
|
|
|
expect(response.status).to eq(200)
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Draft.get(user, 'xyz', 0)).to eq('my data')
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-02-25 11:42:20 -05:00
|
|
|
it 'destroys drafts when required' do
|
2018-06-07 00:24:20 -04:00
|
|
|
user = sign_in(Fabricate(:user))
|
2013-02-05 14:16:51 -05:00
|
|
|
Draft.set(user, 'xxx', 0, 'hi')
|
2018-06-07 00:24:20 -04:00
|
|
|
delete "/draft.json", params: { draft_key: 'xxx', sequence: 0 }
|
|
|
|
expect(response.status).to eq(200)
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Draft.get(user, 'xxx', 0)).to eq(nil)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|