diff --git a/lib/scenic/adapters/postgres.rb b/lib/scenic/adapters/postgres.rb index ba1fb4e1..9941832a 100644 --- a/lib/scenic/adapters/postgres.rb +++ b/lib/scenic/adapters/postgres.rb @@ -235,7 +235,9 @@ def refresh_materialized_view(name, concurrently: false, cascade: false) def populated?(name) raise_unless_materialized_views_supported - sql = "SELECT relispopulated FROM pg_class WHERE relname = '#{name}'" + schemaless_name = name.split(".").last + + sql = "SELECT relispopulated FROM pg_class WHERE relname = '#{schemaless_name}'" relations = execute(sql) if relations.count.positive? diff --git a/spec/scenic/adapters/postgres_spec.rb b/spec/scenic/adapters/postgres_spec.rb index d8358a16..66819aa7 100644 --- a/spec/scenic/adapters/postgres_spec.rb +++ b/spec/scenic/adapters/postgres_spec.rb @@ -229,6 +229,18 @@ module Adapters expect(adapter.populated?("greetings")).to be true end + it "strips out the schema from table_name" do + adapter = Postgres.new + + ActiveRecord::Base.connection.execute <<-SQL + CREATE MATERIALIZED VIEW greetings AS + SELECT text 'hi' AS greeting + WITH NO DATA + SQL + + expect(adapter.populated?("public.greetings")).to be false + end + it "raises an exception if the version of PostgreSQL is too old" do connection = double("Connection", supports_materialized_views?: false) connectable = double("Connectable", connection: connection)