2014-08-30 17:38:47 +00:00
|
|
|
require 'rails_helper'
|
2013-09-10 19:29:17 +00:00
|
|
|
require 'tempfile'
|
2011-11-23 21:30:09 +00:00
|
|
|
|
|
|
|
describe Asciicast do
|
2013-08-04 20:43:36 +00:00
|
|
|
|
2013-11-18 13:29:18 +00:00
|
|
|
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
|
|
|
|
|
2013-09-25 17:29:57 +00:00
|
|
|
let(:asciicast) { described_class.new }
|
2012-04-09 18:04:58 +00:00
|
|
|
|
2013-11-30 23:55:31 +00:00
|
|
|
describe '#user' do
|
|
|
|
subject { asciicast.user }
|
|
|
|
|
2014-02-12 16:45:57 +00:00
|
|
|
context "when it has user assigned" do
|
2013-11-30 23:55:31 +00:00
|
|
|
let(:user) { User.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
asciicast.user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should be(user) }
|
|
|
|
end
|
|
|
|
|
2014-02-12 16:45:57 +00:00
|
|
|
context "when it doesn't have user assigned" do
|
2014-10-05 15:47:42 +00:00
|
|
|
it 'is a null user' do
|
|
|
|
expect(asciicast.user.temporary_username).to eq('anonymous')
|
2013-11-30 23:55:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-04 20:43:36 +00:00
|
|
|
describe '#stdout' do
|
2015-02-28 17:39:31 +00:00
|
|
|
context 'for single-file, JSON asciicast' do
|
|
|
|
let(:asciicast) { create(:asciicast) }
|
2013-07-08 22:55:31 +00:00
|
|
|
|
2015-02-28 17:39:31 +00:00
|
|
|
subject { asciicast.stdout.to_a }
|
2013-08-13 17:27:02 +00:00
|
|
|
|
2015-02-28 17:39:31 +00:00
|
|
|
it 'is enumerable with [delay, data] pair as every item' do
|
|
|
|
expect(subject).to eq([
|
|
|
|
[1.234567, "foo bar"],
|
|
|
|
[5.678987, "baz qux"],
|
|
|
|
[3.456789, "żółć jaźń"],
|
|
|
|
])
|
|
|
|
end
|
2013-08-04 20:43:36 +00:00
|
|
|
end
|
2013-07-08 22:55:31 +00:00
|
|
|
|
2015-02-28 17:39:31 +00:00
|
|
|
context 'for multi-file, legacy asciicast' do
|
|
|
|
let(:asciicast) { create(:legacy_asciicast) }
|
|
|
|
|
|
|
|
subject { asciicast.stdout.to_a }
|
|
|
|
|
|
|
|
it 'is enumerable with [delay, data] pair as every item' do
|
|
|
|
expect(subject).to eq([
|
|
|
|
[1.234567, "foobar"],
|
|
|
|
[0.123456, "baz"],
|
|
|
|
[2.345678, "qux"],
|
|
|
|
])
|
|
|
|
end
|
2013-07-08 22:55:31 +00:00
|
|
|
end
|
|
|
|
end
|
2013-09-10 19:29:17 +00:00
|
|
|
|
2014-06-30 21:26:25 +00:00
|
|
|
describe '#theme' do
|
|
|
|
it 'returns proper theme when theme_name is not blank' do
|
|
|
|
asciicast = described_class.new(theme_name: 'tango')
|
|
|
|
|
|
|
|
expect(asciicast.theme.name).to eq('tango')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when theme_name is blank' do
|
|
|
|
asciicast = described_class.new(theme_name: '')
|
|
|
|
|
|
|
|
expect(asciicast.theme).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|