Skip to content

Commit

Permalink
Remove extra space from SchemaDumper.dump output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharipov Ruslan committed Jul 16, 2018
1 parent a21c476 commit 07b1580
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/scenic/view.rb
Expand Up @@ -45,7 +45,7 @@ def to_schema
materialized_option = materialized ? "materialized: true, " : ""

<<-DEFINITION
create_view #{name.inspect}, #{materialized_option} sql_definition: <<-\SQL
create_view #{name.inspect}, #{materialized_option}sql_definition: <<-\SQL
#{definition.indent(2)}
SQL
DEFINITION
Expand Down
16 changes: 15 additions & 1 deletion spec/scenic/schema_dumper_spec.rb
Expand Up @@ -15,7 +15,8 @@ class SearchInAHaystack < ActiveRecord::Base
ActiveRecord::SchemaDumper.dump(Search.connection, stream)

output = stream.string
expect(output).to include 'create_view "searches"'

expect(output).to include 'create_view "searches", sql_definition: <<-SQL'
expect(output).to include view_definition

Search.connection.drop_view :searches
Expand All @@ -25,6 +26,19 @@ class SearchInAHaystack < ActiveRecord::Base
expect(Search.first.haystack).to eq "needle"
end

it "dumps a create_view for a materialized view in the database" do
view_definition = "SELECT 'needle'::text AS haystack"
Search.connection.create_view :searches, materialized: true, sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)

output = stream.string

expect(output).to include 'create_view "searches", materialized: true, sql_definition: <<-SQL'
expect(output).to include view_definition
end

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"
Expand Down

0 comments on commit 07b1580

Please sign in to comment.