Skip to content

Commit

Permalink
Merge pull request #223 from jrochkind/rails_8_sql_double_parans
Browse files Browse the repository at this point in the history
Allow double parens in SQL spec
  • Loading branch information
jrochkind authored Feb 26, 2024
2 parents 244e4ed + 7d78003 commit 4dca354
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions spec/query_scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
describe "#not_jsonb_contains" do
it 'generates a negated query' do
query = klass.not_jsonb_contains(str: 'foo')

expect(query.to_sql).to match(/WHERE \(?NOT \(products.json_attributes @> \('{"str":"foo"}'\)::jsonb\)/)
# Rails 8 has double parens for some reason, previous does not
expect(query.to_sql).to match(/WHERE \(?NOT \(?\(products.json_attributes @> \('{"str":"foo"}'\)::jsonb\)\)?/)
end
end

Expand Down
9 changes: 6 additions & 3 deletions spec/type/polymorphic_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,18 @@
describe "not_jsonb_contains" do
it "can create keypath query" do
sql = klass.not_jsonb_contains("one_poly.bool" => true).to_sql
expect(sql).to match(/WHERE \(?NOT \(products.json_attributes @> \('{\"one_poly\":{\"bool\":true}}'\)/)
# Rails 8 has double parens for some reason, previous does not
expect(sql).to match(/WHERE \(?NOT \(?\(products.json_attributes @> \('{\"one_poly\":{\"bool\":true}}'\)\)?/)
end
it "can create keypath query with type" do
sql = klass.not_jsonb_contains("one_poly" => {"bool" => true, "type" => "Model2"}).to_sql
expect(sql).to match(/WHERE \(?NOT \(products.json_attributes @> \('{\"one_poly\":{\"bool\":true,\"type\":\"Model2\"}}'\)/)
# Rails 8 has double parens for some reason, previous does not
expect(sql).to match(/WHERE \(?NOT \(?\(products.json_attributes @> \('{\"one_poly\":{\"bool\":true,\"type\":\"Model2\"}}'\)\)?/)
end
it "can create keypath query with model arg" do
sql = klass.not_jsonb_contains("one_poly" => model2.new(bool: true)).to_sql
expect(sql).to match(/WHERE \(?NOT \(products.json_attributes @> \('{\"one_poly\":{\"bool\":true,\"type\":\"Model2\"}}'\)/)
# Rails 8 has double parens for some reason, previous does not
expect(sql).to match(/WHERE \(?NOT \(?\(products.json_attributes @> \('{\"one_poly\":{\"bool\":true,\"type\":\"Model2\"}}'\)\)?/)
end
end
end

0 comments on commit 4dca354

Please sign in to comment.