Sha256: 10624bddb3ba5426e3e7173fac482811535f392df662aa6d517b52636af94835

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')

describe Memento::Action::Destroy, "when object gets destroyed" do
  before do
    setup_db
    setup_data
    @project = Project.create!(:name => "P1", :closed_at => 3.days.ago).reload
    Memento.start(@user)
    @project.destroy
  end

  after do
    Memento.stop
    shutdown_db
  end

  it "should create memento_state for ar-object with full attributes_for_memento" do
    Memento::State.count.should eql(1)
    Memento::State.first.action_type.should eql("destroy")
    Memento::State.first.record.should be_nil # it was destroyed, remember?
    Memento::State.first.reload.record_data.should == @project.attributes_for_memento
  end

  it "should destroy object" do
    Project.find_by_id(@project.id).should be_nil
    Project.count.should be_zero
  end

  it "should allow undoing the destruction" do
    Project.count.should be_zero
    Memento::Session.last.undo
    Project.count.should eql(1)
    Project.first.attributes_for_memento.reject{|k, v| k.to_sym == :id }.should == (
      @project.attributes_for_memento.reject{|k, v| k.to_sym == :id }
    )
  end

  it "should give back undone_object on undoing the destruction" do
    Memento::Session.last.undo.map{|e| e.object.class }.should eql([Project])
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
memento-0.4.1 spec/memento/action/destroy_spec.rb
memento-0.4.0 spec/memento/action/destroy_spec.rb