File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
lib/activerecord-pg-format-db-structure
spec/activerecord-pg-format-db-structure Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ def to_s
233233 end
234234
235235 def current_scope_type
236- @scopes . last . type
236+ @scopes . last & .type
237237 end
238238
239239 def current_token = ( token )
@@ -251,7 +251,7 @@ def current_padding
251251 end
252252
253253 def pop_scope
254- @scopes . pop . type
254+ @scopes . pop & .type
255255 end
256256
257257 def newline
@@ -263,8 +263,10 @@ def append_whitespace
263263 end
264264
265265 def apply_indent
266- @string << ( INDENT_STRING * @scopes . sum ( &:indent ) )
267- @string << @scopes . last . padding
266+ if @scopes . any?
267+ @string << ( INDENT_STRING * @scopes . sum ( &:indent ) )
268+ @string << @scopes . last . padding
269+ end
268270 end
269271
270272 def append_token ( rjust : 0 )
Original file line number Diff line number Diff line change 263263 );
264264 SQL
265265 end
266+
267+ it "handles filter where clauses" do
268+ formatter = described_class . new
269+
270+ source = +<<~SQL
271+ select range_agg(my_range) filter (where true) from my_table
272+ SQL
273+
274+ expect ( formatter . format ( source ) ) . to eq ( <<~SQL )
275+ SELECT range_agg(my_range) FILTER (
276+ WHERE true
277+ )
278+ FROM my_table;
279+ SQL
280+ end
266281 end
267282end
You can’t perform that action at this time.
0 commit comments