Sha256: cb722829b496d0363270a3dafe1fbc0b62ab6021cf99e53fc6b4a2fa8ad12af6

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

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

describe ActsAsArchive::Base::Table do

  before(:all) do
    establish_test_db
    Article.create_archive_table
  end

  describe 'create_archive_table' do

    before(:all) do
      @article_columns = connection.columns("articles").collect(&:name)
      @archive_columns = connection.columns("archived_articles").collect(&:name)
    end

    it "should create an archive table" do
      connection.table_exists?("archived_articles").should == true
    end

    it "should create an archive table with the same structure as the original table" do
      @article_columns.each do |col|
        @archive_columns.include?(col).should == true
      end
    end

    it "should add a deleted_at column to the archive table" do
      (@archive_columns - @article_columns).should == [ 'deleted_at' ]
    end
  end

  describe 'create_archive_indexes' do

    before(:all) do
      Article.create_archive_indexes
    end

    it "should create archive indexes" do
      indexes.to_set.should == [ "id", "deleted_at" ].to_set
    end

    it "should destroy archive indexes" do
      Article.class_eval { acts_as_archive }
      Article.create_archive_indexes
      indexes.should == []
    end
  end

  describe 'migrate_from_acts_as_paranoid' do

    before(:all) do
      connection.add_column(:articles, :deleted_at, :datetime)
      Article.reset_column_information
    end

    before(:each) do
      connection.execute("DELETE FROM #{Article::Archive.table_name}")
    end

    it "should move deleted records to the archive" do
      create_records(Article, :deleted_at => Time.now.utc)
      Article.migrate_from_acts_as_paranoid
      Article.count.should == 0
      Article::Archive.count.should == 5
    end

    it "should not move non-deleted records to the archive" do
      create_records
      Article.migrate_from_acts_as_paranoid
      Article.count.should == 5
      Article::Archive.count.should == 0
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
brianjlandau-acts_as_archive-0.2.8 spec/acts_as_archive/base/table_spec.rb
brianjlandau-acts_as_archive-0.2.7 spec/acts_as_archive/base/table_spec.rb
brianjlandau-acts_as_archive-0.2.6 spec/acts_as_archive/base/table_spec.rb
micahwedemeyer-acts_as_archive-0.3.0 spec/acts_as_archive/base/table_spec.rb
acts_as_archive-0.2.5 spec/acts_as_archive/base/table_spec.rb
acts_as_archive-0.2.4 spec/acts_as_archive/base/table_spec.rb
acts_as_archive-0.2.3 spec/acts_as_archive/base/table_spec.rb
acts_as_archive-0.2.2 spec/acts_as_archive/base/table_spec.rb