Using the Scenic gem I've built an activerecord model backed by a materialized view
class MatviewSales < ActiveRecord::Base
self.table_name = 'matview_sales'
self.primary_key = :id
belongs_to :user
belongs_to :account
belongs_to :account_manager, class_name: User, foreign_key: 'manager_id'
def self.refresh
Scenic.database.refresh_materialized_view(table_name, concurrently: true)
end
end
I'm now trying to test this model in RSpec but no matter what I do I can't get Postgres to populate the view with records:
> FactoryGirl.create(:sale_item)
> MatviewSales.refresh
> MatviewSales.all
=> #<ActiveRecord::Relation []>
How do I populate the materialized view with records for testing?