-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Rely on search_path (instead of "public") when deciding to fully-qualify view name #401
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,16 +58,38 @@ class SearchInAHaystack < ActiveRecord::Base | |
context "with views in non public schemas" do | ||
it "dumps a create_view including 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.execute "CREATE SCHEMA scenic; SET search_path TO public, scenic" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [89/80] |
||
Search.connection.create_view :"scenic.searches", sql_definition: view_definition | ||
Search.connection.create_view :"public.searches", sql_definition: view_definition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [87/80] |
||
stream = StringIO.new | ||
|
||
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" | ||
Search.connection.drop_view :"public.searches" | ||
end | ||
|
||
context 'when "public" is not the primary search path' do | ||
it "dumps a create_view including 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [91/80] |
||
Search.connection.create_view :"scenic.searches", sql_definition: view_definition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [89/80] |
||
Search.connection.create_view :"public.searches", sql_definition: view_definition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [89/80] |
||
stream = StringIO.new | ||
|
||
ActiveRecord::SchemaDumper.dump(Search.connection, stream) | ||
|
||
output = stream.string | ||
expect(output).to include 'create_view "searches",' | ||
expect(output).to include 'create_view "public.searches",' | ||
|
||
Search.connection.drop_view :"scenic.searches" | ||
Search.connection.drop_view :"public.searches" | ||
end | ||
end | ||
end | ||
|
||
|
@@ -123,7 +145,7 @@ class SearchInAHaystack < ActiveRecord::Base | |
it "dumps a create_view 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" | ||
"CREATE SCHEMA scenic; SET search_path TO public, scenic" | ||
) | ||
Search.connection.create_view 'scenic."search in a haystack"', | ||
sql_definition: view_definition | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [106/80]