asciinema.org/spec/models/asciicast_spec.rb

141 lines
3.7 KiB
Ruby
Raw Normal View History

2011-11-23 21:30:09 +00:00
require 'spec_helper'
require 'tempfile'
2011-11-23 21:30:09 +00:00
describe Asciicast do
describe '.for_category_ordered' do
subject { described_class.for_category_ordered(category, order) }
let!(:asciicast_1) { create(:asciicast, created_at: 2.hours.ago,
views_count: 10,
featured: false) }
let!(:asciicast_2) { create(:asciicast, created_at: 1.hour.ago,
views_count: 20,
featured: true) }
let!(:asciicast_3) { create(:asciicast, created_at: 4.hours.ago,
views_count: 30,
featured: false) }
let!(:asciicast_4) { create(:asciicast, created_at: 3.hours.ago,
views_count: 40,
featured: true) }
context "when category is :all" do
let(:category) { :all }
context "and order is :recency" do
let(:order) { :recency }
it { should eq([asciicast_2, asciicast_1, asciicast_4, asciicast_3]) }
end
context "and order is :popularity" do
let(:order) { :popularity }
it { should eq([asciicast_4, asciicast_3, asciicast_2, asciicast_1]) }
end
end
context "when category is :featured" do
let(:category) { :featured }
context "and order is :recency" do
let(:order) { :recency }
it { should eq([asciicast_2, asciicast_4]) }
end
context "and order is :popularity" do
let(:order) { :popularity }
it { should eq([asciicast_4, asciicast_2]) }
end
end
end
let(:asciicast) { described_class.new }
2012-04-09 18:04:58 +00:00
describe '#user' do
subject { asciicast.user }
before do
asciicast.username = 'hugo'
end
context "when user was set" do
let(:user) { User.new }
before do
asciicast.user = user
end
it { should be(user) }
end
context "when user wasn't set" do
it 'defaults to a user with nickname set to username' do
expect(asciicast.user.nickname).to eq('hugo')
end
end
end
describe '#stdout' do
let(:asciicast) { Asciicast.new }
2013-09-21 11:11:36 +00:00
let(:data_uploader) { double('data_uploader',
:decompressed_path => '/foo') }
let(:timing_uploader) { double('timing_uploader',
:decompressed_path => '/bar') }
let(:stdout) { double('stdout', :lazy => lazy_stdout) }
let(:lazy_stdout) { double('lazy_stdout') }
subject { asciicast.stdout }
2013-07-08 22:55:31 +00:00
before do
allow(BufferedStdout).to receive(:new) { stdout }
allow(StdoutDataUploader).to receive(:new) { data_uploader }
allow(StdoutTimingUploader).to receive(:new) { timing_uploader }
2013-07-08 22:55:31 +00:00
end
it 'creates a new BufferedStdout instance' do
subject
2013-08-13 17:27:02 +00:00
expect(BufferedStdout).to have_received(:new).with('/foo', '/bar')
end
2013-07-08 22:55:31 +00:00
it 'returns lazy instance of stdout' do
expect(subject).to be(lazy_stdout)
2013-07-08 22:55:31 +00:00
end
end
describe '#managable_by?' do
subject { asciicast.managable_by?(user) }
let(:asciicast) { Asciicast.new }
let(:owner) { nil }
before do
asciicast.user = owner
end
context "when user is nil" do
let(:user) { nil }
it { should be(false) }
end
context "when user is owner of the asciicast" do
let(:user) { User.new }
let(:owner) { user }
it { should be(true) }
end
context "when user isn't owner of the asciicast" do
let(:user) { User.new }
let(:owner) { User.new }
it { should be(false) }
end
end
2011-11-23 21:30:09 +00:00
end