Support all (old) variations of asciicast upload API

This commit is contained in:
Marcin Kulik 2015-02-26 13:14:32 +00:00
parent 3809191a7c
commit 87d60054cf
10 changed files with 294 additions and 16 deletions

View File

@ -2,33 +2,271 @@ require 'rails_helper'
describe "Asciicast creation" do
before do
post '/api/asciicasts', asciicast: {
meta: fixture_file(meta_filename, 'application/json'),
stdout: fixture_file('stdout', 'application/octet-stream'),
stdout_timing: fixture_file('stdout.time', 'application/octet-stream')
}
let(:created_asciicast) { Asciicast.last }
def basic_auth_header(user, password)
{ 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password) }
end
let(:meta_filename) { 'meta.json' }
it 'returns the URL to the uploaded asciicast' do
expect(response.body).to eq(asciicast_url(Asciicast.last))
def user_agent_header(user_agent)
{ 'User-Agent' => user_agent }
end
context "when json includes uname (legacy)" do
let(:meta_filename) { 'meta-with-uname.json' }
def headers(user, password, user_agent)
h = {}
h.merge!(basic_auth_header(user, password)) if user
h.merge!(user_agent_header(user_agent)) if user_agent
h
end
context '<= v0.9.7 client' do
subject { make_request }
def make_request
post '/api/asciicasts',
{
asciicast: {
meta: fixture_file('0.9.7/meta.json', 'application/json'),
stdout: fixture_file('0.9.7/stdout', 'application/octet-stream'),
stdout_timing: fixture_file('0.9.7/stdout.time', 'application/octet-stream')
}
}, headers(nil, nil, 'python-requests blah/blah')
end
before { subject }
it 'creates asciicast with given command' do
expect(created_asciicast.command).to eq('/bin/bash')
end
it 'creates asciicast with given duration' do
expect(created_asciicast.duration).to eq(11.146430015564)
end
it 'creates asciicast with given shell' do
expect(created_asciicast.shell).to eq('/bin/zsh')
end
it 'creates asciicast with given terminal type' do
expect(created_asciicast.terminal_type).to eq('screen-256color')
end
it 'creates asciicast with given terminal width' do
expect(created_asciicast.terminal_columns).to eq(96)
end
it 'creates asciicast with given terminal height' do
expect(created_asciicast.terminal_lines).to eq(26)
end
it 'creates asciicast with given title' do
expect(created_asciicast.title).to eq('bashing :)')
end
it 'creates asciicast with given uname' do
expect(created_asciicast.uname).to eq('Linux 3.9.9-302.fc19.x86_64 #1 SMP Sat Jul 6 13:41:07 UTC 2013 x86_64')
end
it 'creates asciicast with no user agent set' do
expect(created_asciicast.user_agent).to be(nil)
end
context 'when a user with given token does not exist' do
let(:created_user) { User.last }
it 'creates new user with given username and token' do
expect(created_user.temporary_username).to eq('kill')
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
end
it 'creates asciicast assigned to newly created user' do
expect(created_asciicast.user).to eq(created_user)
end
end
context 'when a user with given token exists' do
let(:user) { User.create_with_token('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill') }
subject do
user
make_request
end
it 'creates asciicast assigned to a user with given token' do
expect(created_asciicast.user).to eq(user)
end
end
it 'returns the URL to the uploaded asciicast' do
expect(response.body).to eq(asciicast_url(Asciicast.last))
expect(response.body).to eq(asciicast_url(created_asciicast))
end
end
context "when json doesn't include user_token (anonymous?)" do
let(:meta_filename) { 'meta-no-token.json' }
context 'v0.9.8 client' do
subject { make_request }
def make_request
post '/api/asciicasts',
{
asciicast: {
meta: fixture_file('0.9.8/meta.json', 'application/json'),
stdout: fixture_file('0.9.8/stdout', 'application/octet-stream'),
stdout_timing: fixture_file('0.9.8/stdout.time', 'application/octet-stream')
}
}, headers(nil, nil, 'asciinema/0.9.8 CPython/2.7.4 Jola/Misio-Foo')
end
before { subject }
it 'creates asciicast with given command' do
expect(created_asciicast.command).to eq('/bin/bash')
end
it 'creates asciicast with given duration' do
expect(created_asciicast.duration).to eq(11.146430015564)
end
it 'creates asciicast with given shell' do
expect(created_asciicast.shell).to eq('/bin/zsh')
end
it 'creates asciicast with given terminal type' do
expect(created_asciicast.terminal_type).to eq('screen-256color')
end
it 'creates asciicast with given terminal width' do
expect(created_asciicast.terminal_columns).to eq(96)
end
it 'creates asciicast with given terminal height' do
expect(created_asciicast.terminal_lines).to eq(26)
end
it 'creates asciicast with given title' do
expect(created_asciicast.title).to eq('bashing :)')
end
it 'creates asciicast with given uname' do
expect(created_asciicast.uname).to be(nil)
end
it 'creates asciicast with given user agent' do
expect(created_asciicast.user_agent).to eq('asciinema/0.9.8 CPython/2.7.4 Jola/Misio-Foo')
end
context 'when a user with given token does not exist' do
let(:created_user) { User.last }
it 'creates new user with given username and token' do
expect(created_user.temporary_username).to eq('kill')
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
end
it 'creates asciicast assigned to newly created user' do
expect(created_asciicast.user).to eq(created_user)
end
end
context 'when a user with given token exists' do
let(:user) { User.create_with_token('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill') }
subject do
user
make_request
end
it 'creates asciicast assigned to a user with given token' do
expect(created_asciicast.user).to eq(user)
end
end
it 'returns the URL to the uploaded asciicast' do
expect(response.body).to eq(asciicast_url(Asciicast.last))
expect(response.body).to eq(asciicast_url(created_asciicast))
end
end
context 'v0.9.9 client' do
subject { make_request }
def make_request
post '/api/asciicasts',
{
asciicast: {
meta: fixture_file('0.9.9/meta.json', 'application/json'),
stdout: fixture_file('0.9.9/stdout', 'application/octet-stream'),
stdout_timing: fixture_file('0.9.9/stdout.time', 'application/octet-stream')
}
}, headers('kill', 'f33e6188-f53c-11e2-abf4-84a6c827e88b', 'asciinema/0.9.9 gc/go1.3 jola-amd64')
end
before { subject }
it 'creates asciicast with given command' do
expect(created_asciicast.command).to eq('/bin/bash')
end
it 'creates asciicast with given duration' do
expect(created_asciicast.duration).to eq(11.146430015564)
end
it 'creates asciicast with given shell' do
expect(created_asciicast.shell).to eq('/bin/zsh')
end
it 'creates asciicast with given terminal type' do
expect(created_asciicast.terminal_type).to eq('screen-256color')
end
it 'creates asciicast with given terminal width' do
expect(created_asciicast.terminal_columns).to eq(96)
end
it 'creates asciicast with given terminal height' do
expect(created_asciicast.terminal_lines).to eq(26)
end
it 'creates asciicast with given title' do
expect(created_asciicast.title).to eq('bashing :)')
end
it 'creates asciicast with given uname' do
expect(created_asciicast.uname).to be(nil)
end
it 'creates asciicast with given user agent' do
expect(created_asciicast.user_agent).to eq('asciinema/0.9.9 gc/go1.3 jola-amd64')
end
context 'when a user with given token does not exist' do
let(:created_user) { User.last }
it 'creates new user with given username and token' do
expect(created_user.temporary_username).to eq('kill')
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
end
it 'creates asciicast assigned to newly created user' do
expect(created_asciicast.user).to eq(created_user)
end
end
context 'when a user with given token exists' do
let(:user) { User.create_with_token('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill') }
subject do
user
make_request
end
it 'creates asciicast assigned to a user with given token' do
expect(created_asciicast.user).to eq(user)
end
end
it 'returns the URL to the uploaded asciicast' do
expect(response.body).to eq(asciicast_url(created_asciicast))
end
end

15
spec/fixtures/0.9.7/meta.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"command": "/bin/bash",
"duration": 11.146430015564,
"recorded_at": "Thu, 25 Jul 2013 20:08:57 +0000",
"shell": "/bin/zsh",
"term": {
"columns": 96,
"lines": 26,
"type": "screen-256color"
},
"title": "bashing :)",
"uname": "Linux 3.9.9-302.fc19.x86_64 #1 SMP Sat Jul 6 13:41:07 UTC 2013 x86_64",
"user_token": "f33e6188-f53c-11e2-abf4-84a6c827e88b",
"username": "kill"
}

BIN
spec/fixtures/0.9.7/stdout vendored Normal file

Binary file not shown.

BIN
spec/fixtures/0.9.7/stdout.time vendored Normal file

Binary file not shown.

14
spec/fixtures/0.9.8/meta.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"command": "/bin/bash",
"duration": 11.146430015564,
"recorded_at": "Thu, 25 Jul 2013 20:08:57 +0000",
"shell": "/bin/zsh",
"term": {
"columns": 96,
"lines": 26,
"type": "screen-256color"
},
"title": "bashing :)",
"user_token": "f33e6188-f53c-11e2-abf4-84a6c827e88b",
"username": "kill"
}

BIN
spec/fixtures/0.9.8/stdout vendored Normal file

Binary file not shown.

BIN
spec/fixtures/0.9.8/stdout.time vendored Normal file

Binary file not shown.

11
spec/fixtures/0.9.9/meta.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"command": "/bin/bash",
"duration": 11.146430015564,
"shell": "/bin/zsh",
"term": {
"columns": 96,
"lines": 26,
"type": "screen-256color"
},
"title": "bashing :)"
}

BIN
spec/fixtures/0.9.9/stdout vendored Normal file

Binary file not shown.

BIN
spec/fixtures/0.9.9/stdout.time vendored Normal file

Binary file not shown.