From 8daf2d0f7f46de062f1f17278eef14302c5036c4 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Tue, 9 Jul 2013 23:35:09 +0200 Subject: [PATCH] Serialize Snapshot with Snapshot::Serializer --- app/models/asciicast.rb | 2 +- spec/models/asciicast_spec.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/asciicast.rb b/app/models/asciicast.rb index f3afca0..2a5ff62 100644 --- a/app/models/asciicast.rb +++ b/app/models/asciicast.rb @@ -6,7 +6,7 @@ class Asciicast < ActiveRecord::Base mount_uploader :stdout, BasicUploader mount_uploader :stdout_timing, BasicUploader - serialize :snapshot, Hash + serialize :snapshot, Snapshot::Serializer.new validates :stdout, :stdout_timing, :presence => true validates :terminal_columns, :terminal_lines, :duration, :presence => true diff --git a/spec/models/asciicast_spec.rb b/spec/models/asciicast_spec.rb index 34da17b..9c0c270 100644 --- a/spec/models/asciicast_spec.rb +++ b/spec/models/asciicast_spec.rb @@ -121,23 +121,23 @@ describe Asciicast do describe '#snapshot' do let(:asciicast) { Asciicast.new } - it 'is an empty hash initially' do - expect(asciicast.snapshot).to eq({}) + it 'is empty Snapshot instance initially' do + expect(asciicast.snapshot).to eq(Snapshot.new) end - it 'is a hash before persisting' do - asciicast.snapshot = { :foo => 1 } + it 'is a Snapshot instance before persisting' do + asciicast.snapshot = Snapshot.new({ :foo => 1 }) - expect(asciicast.snapshot).to eq({ :foo => 1}) + expect(asciicast.snapshot).to eq(Snapshot.new({ :foo => 1 })) end - it 'is a hash after persisting and loading' do + it 'is a Snapshot instance after persisting and loading' do asciicast = build(:asciicast) - asciicast.snapshot = { :foo => 1 } + asciicast.snapshot = Snapshot.new({ :foo => 1 }) asciicast.save! - expect(asciicast.snapshot).to eq({ :foo => 1 }) - expect(Asciicast.find(asciicast.id).snapshot).to eq({ :foo => 1 }) + expect(asciicast.snapshot).to eq(Snapshot.new({ :foo => 1 })) + expect(Asciicast.find(asciicast.id).snapshot).to eq(Snapshot.new({ :foo => 1 })) end end end