Skip to content

Commit

Permalink
Merge pull request ManageIQ#605 from NickLaMuro/add_timestamps_to_bin…
Browse files Browse the repository at this point in the history
…ary_blobs

Adds timestamps to binary blobs
  • Loading branch information
Fryguy authored Aug 27, 2021
2 parents 402bd2e + 8ff509b commit 3579480
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/migrate/20210824231354_add_timestamps_to_binary_blobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTimestampsToBinaryBlobs < ActiveRecord::Migration[6.0]
def change
add_timestamps :binary_blobs, :null => false, :default => -> { 'NOW()' }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require_migration

describe AddTimestampsToBinaryBlobs do
let(:binary_blob_stub) { new_migration_stub(:binary_blobs) }

migration_context :up do
it "adds timestamp columns and auto-populates the value" do
record = binary_blob_stub.create!
expect(record.respond_to?(:created_at)).to be false
expect(record.respond_to?(:updated_at)).to be false

before_migration_time = 5.seconds.ago.utc

migrate

record.reload
expect(record.created_at).to be > before_migration_time
expect(record.updated_at).to be > before_migration_time
end
end

migration_context :down do
it "removes timestamp columns" do
before_migration_time = 5.seconds.ago.utc

record = binary_blob_stub.create!

expect(record.created_at).to be > before_migration_time
expect(record.updated_at).to be > before_migration_time

migrate

record.reload
expect(record.respond_to?(:created_at)).to be false
expect(record.respond_to?(:updated_at)).to be false
end
end
end
4 changes: 4 additions & 0 deletions spec/support/migration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def migration_stub(klass)
stub
end

def new_migration_stub(table_name)
Class.new(ActiveRecord::Base) { self.table_name = table_name.to_s }
end

private

# Clears any cached column information on stubs, since the migrations
Expand Down

0 comments on commit 3579480

Please sign in to comment.