diff --git a/lib/scenic/schema_dumper.rb b/lib/scenic/schema_dumper.rb index 68aab1b2..74ce2049 100644 --- a/lib/scenic/schema_dumper.rb +++ b/lib/scenic/schema_dumper.rb @@ -15,7 +15,7 @@ def views(stream) dumpable_views_in_database.each do |view| stream.puts(view.to_schema) - indexes(view.name, stream) + indexes(view.unscoped_name, stream) end end diff --git a/lib/scenic/view.rb b/lib/scenic/view.rb index 45df91bf..c2f59c59 100644 --- a/lib/scenic/view.rb +++ b/lib/scenic/view.rb @@ -40,12 +40,16 @@ def ==(other) materialized == other.materialized end + # @api private + def unscoped_name + name.split(".").last + end + # @api private def to_schema materialized_option = materialized ? "materialized: true, " : "" - <<-DEFINITION - create_view #{name.inspect}, #{materialized_option}sql_definition: <<-\SQL + create_view #{unscoped_name.inspect}, #{materialized_option}sql_definition: <<-\SQL #{definition.indent(2)} SQL DEFINITION diff --git a/spec/scenic/schema_dumper_spec.rb b/spec/scenic/schema_dumper_spec.rb index 87e683b7..a92f69de 100644 --- a/spec/scenic/schema_dumper_spec.rb +++ b/spec/scenic/schema_dumper_spec.rb @@ -40,7 +40,7 @@ class SearchInAHaystack < ActiveRecord::Base end context "with views in non public schemas" do - it "dumps a create_view including namespace for a view in the database" do + it "dumps a create_view excluding namespace for a view in the database" do view_definition = "SELECT 'needle'::text AS haystack" Search.connection.execute "CREATE SCHEMA scenic; SET search_path TO scenic, public" Search.connection.create_view :"scenic.searches", sql_definition: view_definition @@ -49,7 +49,7 @@ class SearchInAHaystack < ActiveRecord::Base ActiveRecord::SchemaDumper.dump(Search.connection, stream) output = stream.string - expect(output).to include 'create_view "scenic.searches",' + expect(output).to include 'create_view "searches",' Search.connection.drop_view :'scenic.searches' end @@ -89,7 +89,7 @@ class SearchInAHaystack < ActiveRecord::Base end end - context "with views using unexpected characters, name including namespace" do + context "with views using unexpected characters, name excluding namespace" do it "dumps a create_view for a view in the database" do view_definition = "SELECT 'needle'::text AS haystack" Search.connection.execute( @@ -102,7 +102,7 @@ class SearchInAHaystack < ActiveRecord::Base ActiveRecord::SchemaDumper.dump(Search.connection, stream) output = stream.string - expect(output).to include 'create_view "scenic.\"search in a haystack\"",' + expect(output).to include 'create_view "\"search in a haystack\"",' expect(output).to include view_definition Search.connection.drop_view :'scenic."search in a haystack"'