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 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) snapshot = generate_snapshot(asciicast, at_seconds)
asciicast.update_attribute(:snapshot, snapshot) asciicast.update_attribute(:snapshot, snapshot)
end 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. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -52,6 +52,7 @@ ActiveRecord::Schema.define(version: 20141005152615) do
t.string "stdout_frames" t.string "stdout_frames"
t.string "user_agent" t.string "user_agent"
t.string "theme_name" t.string "theme_name"
t.float "snapshot_at"
end end
add_index "asciicasts", ["created_at"], name: "index_asciicasts_on_created_at", using: :btree 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 } let(:updater) { described_class.new }
describe '#update' do describe '#update' do
let(:asciicast) { double('asciicast', :duration => 5.0, :stdout => stdout, let(:asciicast) { double('asciicast', duration: 5.0, stdout: stdout,
:update_attribute => nil) } update_attribute: nil,
snapshot_at: snapshot_at) }
let(:stdout) { double('stdout') } let(:stdout) { double('stdout') }
let(:terminal) { double('terminal') } let(:terminal) { double('terminal') }
let(:film) { double('film', :snapshot_at => 'foo') } let(:film) { double('film', :snapshot_at => 'foo') }
let(:snapshot_at) { nil }
subject { updater.update(asciicast) } subject { updater.update(asciicast) }
@ -20,13 +22,23 @@ describe AsciicastSnapshotUpdater do
subject subject
end 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 it "generates the snapshot at half of asciicast's duration" do
expect(film).to have_received(:snapshot_at).with(2.5) expect(film).to have_received(:snapshot_at).with(2.5)
end end
end
it "updates asciicast's snapshot to the terminal's snapshot" do context "when snapshot time set on asciicast" do
expect(asciicast).to have_received(:update_attribute). let(:snapshot_at) { 2.0 }
with(:snapshot, 'foo')
it "generates the snapshot at half of asciicast's duration" do
expect(film).to have_received(:snapshot_at).with(2.0)
end
end end
context "when snapshot time given" do context "when snapshot time given" do

Loading…
Cancel
Save