Sha256: 469dcbb7112b26e7f028b562f25e6b76b08f4c6a46c815a23f1263ff32c4641d

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require_relative 'spec_helper'

require 'ixtlan/datamapper/modified_by'

class D
  include DataMapper::Resource

  property :id, Serial
  property :name, String
  
  modified_by D
end

DataMapper.finalize
DataMapper.auto_migrate!

describe Ixtlan::DataMapper::ModifiedBy do

  subject do 
    unless d = D.get( 1 )
      d = D.new :name => 'huffalump', :id => 1, :modified_by_id => 1
      d.save!
    end
    d
  end

  it 'is valid per default' do
    subject.current_user.must_be_nil
    subject.persistence_state?.must_equal true
    subject.dirty?.must_equal false
    subject.valid?.must_equal true
  end

  it 'is not valid when dirty' do
    subject.name = 'asd'
    subject.current_user.must_be_nil
    subject.dirty?.must_equal true
    subject.valid?.must_equal false
  end

  it 'is valid when dirty and current_user set' do
    subject.name = 'asd'
    subject.current_user = subject
    subject.dirty?.must_equal true
    subject.valid?.must_equal true
  end

  it 'is valid after setting current user' do
    subject.current_user = subject
    subject.dirty?.must_equal false
    subject.valid?.must_equal true
  end

end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
ixtlan-datamapper-0.1.0 spec/modified_by_spec.rb
ixtlan-datamapper-0.1.0 spec/collection_spec.rb~