2013-08-04 20:53:25 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AsciicastCreator do
|
2013-09-25 17:29:57 +00:00
|
|
|
|
|
|
|
let(:creator) { described_class.new }
|
2013-08-04 20:53:25 +00:00
|
|
|
|
|
|
|
describe '#create' do
|
2013-09-25 17:29:57 +00:00
|
|
|
let(:asciicast) { stub_model(Asciicast, id: 666) }
|
|
|
|
let(:input_attrs) { { a: 'A' } }
|
2013-10-11 18:44:49 +00:00
|
|
|
let(:headers) { { 'User-Agent' => 'asciinema/0.9.7' } }
|
2014-02-09 18:12:15 +00:00
|
|
|
let(:prepared_attrs) { double('prepared_attrs', attributes: { b: 'B' }) }
|
2013-09-25 17:29:57 +00:00
|
|
|
|
2013-10-11 18:44:49 +00:00
|
|
|
subject { creator.create(input_attrs, headers) }
|
2013-08-04 20:53:25 +00:00
|
|
|
|
|
|
|
before do
|
2014-02-09 18:12:15 +00:00
|
|
|
allow(AsciicastParams).to receive(:build).
|
2013-10-11 18:44:49 +00:00
|
|
|
with(input_attrs, headers) { prepared_attrs }
|
2013-08-04 20:53:25 +00:00
|
|
|
allow(Asciicast).to receive(:create!) { asciicast }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Asciicast.create! with proper attributes' do
|
|
|
|
subject
|
|
|
|
|
2013-09-25 17:29:57 +00:00
|
|
|
expect(Asciicast).to have_received(:create!).
|
|
|
|
with({ b: 'B' }, { without_protection: true })
|
2013-08-04 20:53:25 +00:00
|
|
|
end
|
|
|
|
|
2013-09-25 17:29:57 +00:00
|
|
|
it 'enqueues a post-processing job' do
|
2013-08-04 20:53:25 +00:00
|
|
|
subject
|
|
|
|
|
2013-09-25 17:29:57 +00:00
|
|
|
expect(AsciicastWorker).to have_queued_job(666)
|
2013-08-04 20:53:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the created asciicast' do
|
|
|
|
expect(subject).to be(asciicast)
|
|
|
|
end
|
|
|
|
end
|
2013-09-25 17:29:57 +00:00
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
end
|