Sha256: d0a024d5176c56f1f30a16405fd489ea716279f306d656bd016811e6e080283a

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe ActsAsArchive::Base do
  
  before(:all) do
    establish_test_db
  end
  
  describe 'acts_as_archive' do    
    it "should add self.acts_as_archive? to the model" do
      Article.respond_to?(:acts_as_archive?).should == true
    end
    
    it "should add self.archive_indexes to the model" do
      Article.respond_to?(:archive_indexes).should == true
      Article.archive_indexes.should == [ 'id', 'deleted_at' ]
    end
    
    it "should add Archive class to the model" do
      defined?(Article::Archive).should == "constant"
    end
    
    describe 'for STI models' do
      before do
        Article.create_archive_table
        @headline = Headline.create(:title => "This is a headline")
        @oped = Opinion.create(:title => "This is an op-ed")
        @headline.destroy
        @oped.destroy
      end
      
      it 'should only return a deleted entry for the STI type used' do
        Headline::Archive.all.map(&:id).should include(@headline.id)
        Headline::Archive.all.map(&:id).should_not include(@oped.id)
        Opinion::Archive.all.map(&:id).should_not include(@headline.id)
        Opinion::Archive.all.map(&:id).should include(@oped.id)
      end
      
      it 'should be able to restore a deleted entry' do
        @deleted_item = Headline::Archive.first
        @deleted_item.restore
        lambda { Headline.find(@deleted_item.id) }.should_not raise_exception
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brianjlandau-acts_as_archive-0.2.8 spec/acts_as_archive/base_spec.rb