Add a simple model representing a terminal snapshot

This commit is contained in:
Marcin Kulik 2013-07-09 23:40:21 +02:00
parent 8daf2d0f7f
commit e947524533
2 changed files with 44 additions and 0 deletions

21
app/models/snapshot.rb Normal file
View File

@ -0,0 +1,21 @@
class Snapshot
attr_reader :lines
def initialize(lines = [])
@lines = lines
end
def ==(other)
other.lines == lines
end
class Serializer
def dump(snapshot)
YAML.dump(snapshot.lines)
end
def load(value)
value.present? ? Snapshot.new(YAML.load(value)) : Snapshot.new
end
end
end

View File

@ -0,0 +1,23 @@
require 'spec_helper'
describe Snapshot do
describe '#==' do
let(:snapshot) { Snapshot.new([:foo]) }
subject { snapshot == other }
context "when the other has the same lines" do
let(:other) { Snapshot.new([:foo]) }
it { should be(true) }
end
context "when the other has a different lines" do
let(:other) { Snapshot.new([:foo, :bar]) }
it { should be(false) }
end
end
end