2011-11-23 21:30:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Asciicast do
|
2013-08-04 20:43:36 +00:00
|
|
|
|
|
|
|
let(:asciicast) { Asciicast.new }
|
|
|
|
|
2012-03-04 19:28:30 +00:00
|
|
|
describe '.assign_user' do
|
2012-12-01 17:45:06 +00:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
2012-03-04 19:28:30 +00:00
|
|
|
let(:token) { 'token' }
|
2012-03-08 14:00:10 +00:00
|
|
|
let!(:asciicast) do
|
2012-12-01 17:45:06 +00:00
|
|
|
FactoryGirl.create(:asciicast, :user => nil, :user_token => token)
|
2012-03-08 14:00:10 +00:00
|
|
|
end
|
2012-03-04 19:28:30 +00:00
|
|
|
|
|
|
|
subject { Asciicast.assign_user(token, user) }
|
|
|
|
|
|
|
|
it 'returns number of updated records' do
|
|
|
|
subject.should == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns user to matching asciicasts' do
|
|
|
|
subject
|
|
|
|
asciicast.reload.user.should == user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-04 21:19:23 +00:00
|
|
|
# TODO: create a service for this
|
2012-03-04 17:14:58 +00:00
|
|
|
describe '#save' do
|
2012-03-06 18:09:15 +00:00
|
|
|
let(:asciicast) { FactoryGirl.build(:asciicast, :user => user) }
|
2012-03-04 17:14:58 +00:00
|
|
|
|
|
|
|
context 'when no user given' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it 'calls #assign_user' do
|
|
|
|
asciicast.should_receive(:assign_user)
|
|
|
|
asciicast.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user given' do
|
2012-03-06 18:09:15 +00:00
|
|
|
let(:user) { FactoryGirl.build(:user) }
|
2012-03-04 17:14:58 +00:00
|
|
|
|
|
|
|
it "doesn't call #assign_user" do
|
|
|
|
asciicast.should_not_receive(:assign_user)
|
|
|
|
asciicast.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#assign_user' do
|
2012-12-01 17:45:06 +00:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
2012-03-08 14:00:10 +00:00
|
|
|
let(:asciicast) do
|
2012-12-01 17:45:06 +00:00
|
|
|
FactoryGirl.create(:asciicast, :user => nil, :user_token => user_token)
|
2012-03-08 14:00:10 +00:00
|
|
|
end
|
2012-03-04 17:14:58 +00:00
|
|
|
|
|
|
|
context 'when user exists with given token' do
|
2012-12-01 17:45:06 +00:00
|
|
|
let(:user_token) { FactoryGirl.create(:user_token, :user => user).token }
|
2012-03-04 17:14:58 +00:00
|
|
|
|
|
|
|
it 'assigns user and resets user_token' do
|
|
|
|
asciicast.assign_user
|
|
|
|
asciicast.user.should == user
|
|
|
|
asciicast.user_token.should be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no user with given token' do
|
|
|
|
let(:user_token) { 'some-foo-bar' }
|
|
|
|
|
|
|
|
it 'assigns user' do
|
|
|
|
asciicast.assign_user
|
|
|
|
asciicast.user.should be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-09 18:04:58 +00:00
|
|
|
|
2013-08-04 21:06:56 +00:00
|
|
|
describe '#update_snapshot' do
|
|
|
|
let(:asciicast) { create(:asciicast) }
|
|
|
|
let(:snapshot) { [[[{ :foo => 'bar' }]]] }
|
|
|
|
|
|
|
|
it 'persists the snapshot' do
|
|
|
|
asciicast.update_snapshot(snapshot)
|
|
|
|
|
|
|
|
expect(Asciicast.find(asciicast.id).snapshot).to eq([[[{ 'foo' => 'bar' }]]])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-04 20:43:36 +00:00
|
|
|
describe '#stdout' do
|
2013-08-13 17:27:02 +00:00
|
|
|
let(:asciicast) { stub_model(Asciicast) }
|
2013-08-15 18:58:41 +00:00
|
|
|
let(:data_file) { double('data_file', :decompressed_path => '/foo') }
|
|
|
|
let(:timing_file) { double('timing_file', :decompressed_path => '/bar') }
|
2013-08-04 20:43:36 +00:00
|
|
|
let(:stdout) { double('stdout') }
|
2013-07-08 22:55:31 +00:00
|
|
|
|
2013-08-04 20:43:36 +00:00
|
|
|
before do
|
2013-08-13 17:27:02 +00:00
|
|
|
allow(asciicast).to receive(:stdout_data) { data_file }
|
|
|
|
allow(asciicast).to receive(:stdout_timing) { timing_file }
|
2013-08-04 20:43:36 +00:00
|
|
|
allow(Stdout).to receive(:new) { stdout }
|
2013-07-08 22:55:31 +00:00
|
|
|
end
|
|
|
|
|
2013-08-04 20:43:36 +00:00
|
|
|
it 'creates a new Stdout instance' do
|
|
|
|
asciicast.stdout
|
2013-08-13 17:27:02 +00:00
|
|
|
|
2013-08-15 18:58:41 +00:00
|
|
|
expect(Stdout).to have_received(:new).with('/foo', '/bar')
|
2013-08-04 20:43:36 +00:00
|
|
|
end
|
2013-07-08 22:55:31 +00:00
|
|
|
|
2013-08-04 20:43:36 +00:00
|
|
|
it 'returns created Stdout instance' do
|
|
|
|
expect(asciicast.stdout).to be(stdout)
|
2013-07-08 22:55:31 +00:00
|
|
|
end
|
|
|
|
end
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|