2011-11-23 21:30:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Asciicast do
|
2012-03-04 17:14:58 +00:00
|
|
|
it "has valid factory" do
|
2012-03-06 18:09:15 +00:00
|
|
|
FactoryGirl.build(:asciicast).should be_valid
|
2012-03-04 17:14:58 +00:00
|
|
|
end
|
|
|
|
|
2012-03-04 19:28:30 +00:00
|
|
|
describe '.assign_user' do
|
|
|
|
let(:user) { Factory(:user) }
|
|
|
|
let(:token) { 'token' }
|
2012-03-08 14:00:10 +00:00
|
|
|
let!(:asciicast) do
|
|
|
|
Factory(:asciicast, :user => nil, :user_token => token)
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
let(:user) { Factory(:user) }
|
2012-03-08 14:00:10 +00:00
|
|
|
let(:asciicast) do
|
|
|
|
Factory(:asciicast, :user => nil, :user_token => user_token)
|
|
|
|
end
|
2012-03-04 17:14:58 +00:00
|
|
|
|
|
|
|
context 'when user exists with given token' do
|
|
|
|
let(:user_token) { Factory(:user_token, :user => user).token }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
describe '#meta=' do
|
|
|
|
let(:asciicast) { stub_model(Asciicast) }
|
|
|
|
|
|
|
|
let(:username) { 'username' }
|
|
|
|
let(:user_token) { 'token' }
|
|
|
|
let(:duration) { 123.456 }
|
|
|
|
let(:recorded_at) { Time.now.to_s }
|
|
|
|
let(:title) { 'title' }
|
|
|
|
let(:command) { '/bin/command' }
|
|
|
|
let(:shell) { '/bin/shell' }
|
|
|
|
let(:uname) { 'OS' }
|
|
|
|
let(:terminal_lines) { 29 }
|
|
|
|
let(:terminal_columns) { 97 }
|
|
|
|
let(:terminal_type) { 'xterm-lolz' }
|
|
|
|
|
|
|
|
it 'assigns attributes properly' do
|
|
|
|
data = {
|
|
|
|
:username => username,
|
|
|
|
:user_token => user_token,
|
|
|
|
:duration => duration,
|
|
|
|
:recorded_at => recorded_at,
|
|
|
|
:title => title,
|
|
|
|
:command => command,
|
|
|
|
:shell => shell,
|
|
|
|
:uname => uname,
|
|
|
|
:term => {
|
|
|
|
:lines => terminal_lines,
|
|
|
|
:columns => terminal_columns,
|
|
|
|
:type => terminal_type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
json = data.to_json
|
|
|
|
tempfile = stub('tempfile', :read => json)
|
|
|
|
json_file = stub('file', :tempfile => tempfile)
|
|
|
|
asciicast.meta = json_file
|
|
|
|
|
|
|
|
asciicast.username.should == username
|
|
|
|
asciicast.user_token.should == user_token
|
|
|
|
asciicast.duration.should == duration
|
|
|
|
asciicast.recorded_at.should == recorded_at
|
|
|
|
asciicast.title.should == title
|
|
|
|
asciicast.command.should == command
|
|
|
|
asciicast.shell.should == shell
|
|
|
|
asciicast.uname.should == uname
|
|
|
|
asciicast.terminal_lines.should == terminal_lines
|
|
|
|
asciicast.terminal_columns.should == terminal_columns
|
|
|
|
asciicast.terminal_type.should == terminal_type
|
|
|
|
end
|
|
|
|
end
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|