Sha256: a0b73e3eea8b7765a600c57156e37ce5bd1f08d127fd0398bb5ad6c534fc64d9

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 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.instance.start(@user)
    @project.destroy
  end
  
  after do
    Memento.instance.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

9 entries across 9 versions & 2 rubygems

Version Path
yolk-memento-0.2.0 spec/memento/action/destroy_spec.rb
memento-0.3.7 spec/memento/action/destroy_spec.rb
memento-0.3.6 spec/memento/action/destroy_spec.rb
memento-0.3.5 spec/memento/action/destroy_spec.rb
memento-0.3.4 spec/memento/action/destroy_spec.rb
memento-0.3.3 spec/memento/action/destroy_spec.rb
memento-0.3.2 spec/memento/action/destroy_spec.rb
memento-0.3.1 spec/memento/action/destroy_spec.rb
memento-0.3.0 spec/memento/action/destroy_spec.rb