2012-01-14 20:26:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Api::AsciicastsController do
|
|
|
|
|
2012-04-09 20:46:38 +00:00
|
|
|
describe '#create' do
|
2013-08-04 20:53:25 +00:00
|
|
|
let(:creator) { double('creator') }
|
|
|
|
let(:attributes) { { 'foo' => 'bar' } }
|
2012-04-09 20:46:38 +00:00
|
|
|
|
|
|
|
before do
|
2013-08-04 20:53:25 +00:00
|
|
|
allow(AsciicastCreator).to receive(:new).with(no_args()) { creator }
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
context 'when the creator returns an asciicast' do
|
|
|
|
let(:asciicast) { stub_model(Asciicast, :id => 666) }
|
2012-04-09 20:46:38 +00:00
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
before do
|
2013-10-11 18:44:49 +00:00
|
|
|
allow(creator).to receive(:create).
|
|
|
|
with(attributes, kind_of(ActionDispatch::Http::Headers)) { asciicast }
|
2013-08-04 20:53:25 +00:00
|
|
|
post :create, :asciicast => attributes
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
it 'returns the status 201' do
|
|
|
|
expect(response.status).to eq(201)
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
it 'returns the URL of created asciicast as the content body' do
|
|
|
|
expect(response.body).to eq(asciicast_url(asciicast))
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
context 'when the creator raises ActiveRecord::RecordInvalid' do
|
2013-08-08 13:26:12 +00:00
|
|
|
let(:asciicast) { stub_model(Asciicast, :errors => errors) }
|
2013-08-04 20:53:25 +00:00
|
|
|
let(:errors) { double('errors', :full_messages => full_messages) }
|
|
|
|
let(:full_messages) { ['This is invalid'] }
|
|
|
|
|
2012-04-09 20:46:38 +00:00
|
|
|
before do
|
2013-10-11 18:44:49 +00:00
|
|
|
allow(creator).to receive(:create).
|
|
|
|
with(attributes, kind_of(ActionDispatch::Http::Headers)).
|
2013-08-04 20:53:25 +00:00
|
|
|
and_raise(ActiveRecord::RecordInvalid.new(asciicast))
|
|
|
|
post :create, :asciicast => attributes
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
it 'returns the status 422' do
|
|
|
|
expect(response.status).to eq(422)
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
|
2013-10-11 18:44:49 +00:00
|
|
|
it 'returns nothing as the content body' do
|
2013-08-04 20:53:25 +00:00
|
|
|
expect(response.body).to be_blank
|
2012-04-09 20:46:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-08-04 20:53:25 +00:00
|
|
|
|
2012-01-14 20:26:49 +00:00
|
|
|
end
|