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