Make snapshot generation aware of custom snapshot time on asciicast

private-asciicasts
Marcin Kulik 10 years ago
parent 1e9423bc89
commit 8d496bd418

@ -1,6 +1,7 @@
class AsciicastSnapshotUpdater
def update(asciicast, at_seconds = asciicast.duration / 2)
def update(asciicast, at_seconds = nil)
at_seconds ||= asciicast.snapshot_at || asciicast.duration / 2
snapshot = generate_snapshot(asciicast, at_seconds)
asciicast.update_attribute(:snapshot, snapshot)
end

@ -0,0 +1,5 @@
class AddSnapshotAtToAsciicasts < ActiveRecord::Migration
def change
add_column :asciicasts, :snapshot_at, :float
end
end

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141005152615) do
ActiveRecord::Schema.define(version: 20141127112626) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -52,6 +52,7 @@ ActiveRecord::Schema.define(version: 20141005152615) do
t.string "stdout_frames"
t.string "user_agent"
t.string "theme_name"
t.float "snapshot_at"
end
add_index "asciicasts", ["created_at"], name: "index_asciicasts_on_created_at", using: :btree

@ -5,11 +5,13 @@ describe AsciicastSnapshotUpdater do
let(:updater) { described_class.new }
describe '#update' do
let(:asciicast) { double('asciicast', :duration => 5.0, :stdout => stdout,
:update_attribute => nil) }
let(:asciicast) { double('asciicast', duration: 5.0, stdout: stdout,
update_attribute: nil,
snapshot_at: snapshot_at) }
let(:stdout) { double('stdout') }
let(:terminal) { double('terminal') }
let(:film) { double('film', :snapshot_at => 'foo') }
let(:snapshot_at) { nil }
subject { updater.update(asciicast) }
@ -20,15 +22,25 @@ describe AsciicastSnapshotUpdater do
subject
end
it "generates the snapshot at half of asciicast's duration" do
expect(film).to have_received(:snapshot_at).with(2.5)
end
it "updates asciicast's snapshot to the terminal's snapshot" do
expect(asciicast).to have_received(:update_attribute).
with(:snapshot, 'foo')
end
context "when no snapshot time set on asciicast nor custom time given" do
it "generates the snapshot at half of asciicast's duration" do
expect(film).to have_received(:snapshot_at).with(2.5)
end
end
context "when snapshot time set on asciicast" do
let(:snapshot_at) { 2.0 }
it "generates the snapshot at half of asciicast's duration" do
expect(film).to have_received(:snapshot_at).with(2.0)
end
end
context "when snapshot time given" do
subject { updater.update(asciicast, 4.3) }

Loading…
Cancel
Save