require 'spec_helper'
describe AsciicastPagePresenter do
describe '.build' do
subject { described_class.build(asciicast, user, playback_options) }
let(:asciicast) { stub_model(Asciicast, decorate: decorated_asciicast) }
let(:user) { double('user') }
let(:playback_options) { { speed: 3.0 } }
let(:decorated_asciicast) { double('decorated_asciicast', theme_name: 'foo') }
it "builds presenter with given asciicast decorated" do
expect(subject.asciicast).to be(decorated_asciicast)
end
it "builds presenter with given user" do
expect(subject.current_user).to be(user)
end
it "builds presenter with given playback options" do
expect(subject.playback_options.speed).to eq(3.0)
expect(subject.playback_options.theme).to eq('foo')
end
end
let(:presenter) { described_class.new(asciicast, current_user, nil) }
let(:asciicast) { stub_model(Asciicast, user: author) }
let(:current_user) { User.new }
let(:author) { User.new }
let(:view_context) {
controller = ApplicationController.new
controller.request = ActionController::TestRequest.new
controller.view_context
}
describe '#title' do
subject { presenter.title }
before do
allow(asciicast).to receive(:title) { 'the-title' }
end
it { should eq('the-title') }
end
describe '#asciicast_title' do
subject { presenter.asciicast_title }
before do
allow(asciicast).to receive(:title) { 'the-title' }
end
it { should eq('the-title') }
end
describe '#author_img_link' do
subject { presenter.author_img_link }
before do
allow(asciicast).to receive(:author_img_link) { '' }
end
it { should eq('') }
end
describe '#author_link' do
subject { presenter.author_link }
before do
allow(asciicast).to receive(:author_link) { '' }
end
it { should eq('') }
end
describe '#asciicast_created_at' do
subject { presenter.asciicast_created_at }
let(:now) { Time.now }
before do
allow(asciicast).to receive(:created_at) { now }
end
it { should eq(now) }
end
describe '#asciicast_env_details' do
subject { presenter.asciicast_env_details }
before do
allow(asciicast).to receive(:os) { 'Linux' }
allow(asciicast).to receive(:shell) { 'bash' }
allow(asciicast).to receive(:terminal_type) { 'xterm' }
end
it { should eq('Linux / bash / xterm') }
end
describe '#views_count' do
subject { presenter.views_count }
before do
allow(asciicast).to receive(:views_count) { 5 }
end
it { should eq(5) }
end
describe '#embed_script' do
subject { presenter.embed_script(view_context) }
let(:src_regexp) { /src="[^"]+\b123\b[^"]*\.js"/ }
let(:id_regexp) { /id="asciicast-123"/ }
let(:script_regexp) {
/^