Sha256: a1f9cf2f79f6fc38e7ce761a16572a1e7751ba6bbe088487d58b0944f48c4012

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require_relative '../test/helper'

describe DBRotator do
  after do
    `mysql -B -e 'SHOW SCHEMAS;'`.split.each do |schema|
      if /^#{TEST_SCHEMA_PREFIX}/.match(schema)
        `mysql -e "DROP SCHEMA #{schema}"`
      end
    end
  end

  def dbname_with(time)
    "__minitest_#{ time.strftime(DBRotator::TIME_FORMAT) }"
  end

  describe "integration test" do
    it "rotates databases correctly" do
      dbr = DBRotator.new(dummy_config)

      t1 = Time.new(2013, 1, 1)
      t2 = Time.new(2013, 1, 2)
      t3 = Time.new(2013, 1, 3)

      Time.stub(:now, t1) do
        dbr.rotate
        `mysql -B -e 'SHOW SCHEMAS;'`.must_include(dbname_with(t1))
        `mysql -B -e 'SHOW TABLES FROM #{dbname_with(t1)};'`.must_include("test")
      end

      Time.stub(:now, t2) do
        dbr.rotate
        `mysql -B -e 'SHOW SCHEMAS;'`.must_include(dbname_with(t2))
        `mysql -B -e 'SHOW SCHEMAS;'`.must_include(dbname_with(t1))
      end

      Time.stub(:now, t3) do
        dbr.rotate
        `mysql -B -e 'SHOW SCHEMAS;'`.must_include(dbname_with(t3))
        `mysql -B -e 'SHOW SCHEMAS;'`.must_include(dbname_with(t2))

        `mysql -B -e 'SHOW SCHEMAS;'`.wont_include(dbname_with(t1))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
db-rotator-0.0.3 test/test_db_rotator.rb
db-rotator-0.0.2 test/test_db_rotator.rb