summaryrefslogtreecommitdiff
path: root/spec/support/helpers/database/database_helpers.rb
blob: b8d7ea3662f98d877af6ed07056d37e4db709e43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

module Database
  module DatabaseHelpers
    # In order to directly work with views using factories,
    # we can swapout the view for a table of identical structure.
    def swapout_view_for_table(view)
      ActiveRecord::Base.connection.execute(<<~SQL)
        CREATE TABLE #{view}_copy (LIKE #{view});
        DROP VIEW #{view};
        ALTER TABLE #{view}_copy RENAME TO #{view};
      SQL
    end
  end
end