Sha256: 5ed9d8a4adcd775ff164e721311aa51ba23ac4e5a60c0012cda65a9cf8e07917
Contents?: true
Size: 1.91 KB
Versions: 2
Compression:
Stored size: 1.91 KB
Contents
require_relative '../../../spec_helper' describe DataMapper::Resource::PersistenceState::Deleted do before :all do class ::Author include DataMapper::Resource property :id, HugeInteger, :key => true, :default => 1 property :name, String property :active, Boolean, :default => true property :coding, Boolean, :default => true belongs_to :parent, self, :required => false has n, :children, self, :inverse => :parent end DataMapper.finalize @model = Author end before do @resource = @model.create(:name => 'Dan Kubb') @state = DataMapper::Resource::PersistenceState::Deleted.new(@resource) end after do @model.destroy! end describe '#commit' do subject { @state.commit } supported_by :all do it 'returns an Immutable state' do is_expected.to eql(DataMapper::Resource::PersistenceState::Immutable.new(@resource)) end it 'deletes the resource' do subject expect(@model.get(*@resource.key)).to be_nil end it 'removes the resource from the identity map' do identity_map = @resource.repository.identity_map(@model) expect { method(:subject) }.to change { identity_map.dup }.from(@resource.key => @resource).to({}) end end end describe '#delete' do subject { @state.delete } supported_by :all do it 'is a no-op' do is_expected.to equal(@state) end end end describe '#get' do it_behaves_like 'Resource::PersistenceState::Persisted#get' end describe '#set' do subject { @state.set(@key, @value) } supported_by :all do before do @key = @model.properties[:name] @value = @key.get!(@resource) end it 'raises an exception' do expect { method(:subject) }.to raise_error(DataMapper::ImmutableDeletedError, 'Deleted resource cannot be modified') end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sbf-dm-core-1.3.0 | spec/semipublic/resource/state/deleted_spec.rb |
sbf-dm-core-1.3.0.beta | spec/semipublic/resource/state/deleted_spec.rb |