Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for schema order of non-public-schema views #403

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/scenic/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ class SearchInAHaystack < ActiveRecord::Base

Search.connection.drop_view :"scenic.searches"
end

it "sorts dependency order when views exist in a non-public schema" do
Search.connection.execute("CREATE SCHEMA IF NOT EXISTS scenic; SET search_path TO public, scenic")
Search.connection.execute("CREATE VIEW scenic.apples AS SELECT 1;")
Search.connection.execute("CREATE VIEW scenic.bananas AS SELECT 2;")
Search.connection.execute("CREATE OR REPLACE VIEW scenic.apples AS SELECT * FROM scenic.bananas;")
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
views = stream.string.lines.grep(/create_view/).map do |view_line|
view_line.match('create_view "(?<name>.*)"')[:name]
end
expect(views).to eq(%w[scenic.bananas scenic.apples])

Search.connection.execute("DROP SCHEMA IF EXISTS scenic CASCADE; SET search_path TO public")
end
end

it "handles active record table name prefixes and suffixes" do
Expand Down