Sha256: edf6f125fc362c3ed9b74e6afd7ac4ef2c3d9fe464a9c09f69c003bd70919e91

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

require 'dm-core'
require 'dm-timestamps'
require 'dm-migrations'
require 'dm-sqlite-adapter'
require 'ixtlan/optimistic/data_mapper'

DataMapper.setup(:default, 'sqlite::memory:')

class A
  include DataMapper::Resource
  include Ixtlan::Optimistic::DataMapper

  property :id, Serial
  property :name, String
  
  timestamps :at
end

DataMapper.finalize
DataMapper.auto_migrate!

describe Ixtlan::Optimistic::DataMapper do

  subject { A.create :name => 'huffalump' }

  it 'should load' do
    A.optimistic_get!(subject.updated_at.to_s, subject.id).must_equal subject
  end

  it 'should fail with nil' do
    A.optimistic_get((subject.updated_at - 1000).to_s, subject.id).must_be_nil
  end

  it 'should fail with exception' do
    lambda { A.optimistic_get!((subject.updated_at - 1000).to_s, subject.id) }.must_raise Ixtlan::Optimistic::ObjectStaleException
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ixtlan-optimistic-0.1.0 spec/datamapper_spec.rb