Skip to content
This repository has been archived by the owner on Sep 30, 2018. It is now read-only.

Commit

Permalink
Update persistence spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Feb 11, 2014
1 parent 2027858 commit 593335c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions spec/model/persistence_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'spec_helper'

describe Vienna::Model do
let(:model) { SimpleModel.new }

let(:model_class) { SimpleModel }
let(:model) { model_class.new }
let(:loaded_model) { model_class.load(:first_name => "Adam", id: 872) }
describe "#did_destroy" do
it "triggers a :destroy event on the record" do
called = false
Expand All @@ -13,16 +14,30 @@

it "triggers a :destroy event on the class" do
called = false
SimpleModel.on(:destroy) { called = true }
model_class.on(:destroy) { called = true }
model.did_destroy
called.should eq(true)
end

it "removes the record from the class identity_map" do
model = SimpleModel.load(:first_name => "Adam", id: 872)
loaded_model.did_destroy
model_class.identity_map[loaded_model.id].should eq(nil)
end

model.did_destroy
SimpleModel.identity_map[model.id].should eq(nil)
it "removes the record from the class record_array" do
loaded_model.did_destroy
model_class.all.should_not include(loaded_model)
end
end

describe '#destroyed?' do
it 'is false for "living" models' do
model.destroyed?.should be_falsey
end

it "is true for destroyed models" do
loaded_model.did_destroy
loaded_model.destroyed?.should be_truthy
end
end

Expand Down

0 comments on commit 593335c

Please sign in to comment.