Skip to content

Commit

Permalink
Fix explain test comparisons
Browse files Browse the repository at this point in the history
Explain now returns an object. We need to coerce it into a string for rspec comparisons.

https://blog.saeloun.com/2024/11/21/rails-7-2-adds-support-for-explain-method-to-activerecord-relation/

rails/rails@c1ea574
  • Loading branch information
andynu committed Jan 31, 2025
1 parent d673594 commit 5370814
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ class ::TestPost < ActiveRecord::Base

it "should explain query" do
explain = TestPost.where(id: 1).explain
expect(explain).to include("Cost")
expect(explain).to include("INDEX UNIQUE SCAN")
expect(explain.inspect).to include("Cost")
expect(explain.inspect).to include("INDEX UNIQUE SCAN")
end

it "should explain query with binds" do
binds = [ActiveRecord::Relation::QueryAttribute.new("id", 1, ActiveRecord::Type::OracleEnhanced::Integer.new)]
explain = TestPost.where(id: binds).explain
expect(explain).to include("Cost")
expect(explain).to include("INDEX UNIQUE SCAN").or include("TABLE ACCESS FULL")
expect(explain.inspect).to include("Cost")
expect(explain.inspect).to include("INDEX UNIQUE SCAN").or include("TABLE ACCESS FULL")
end
end

Expand Down Expand Up @@ -768,13 +768,13 @@ class ::TestPost < ActiveRecord::Base
it "should explain considers hints" do
post = TestPost.optimizer_hints("FULL (\"TEST_POSTS\")")
post = post.where(id: 1)
expect(post.explain).to include("| TABLE ACCESS FULL| TEST_POSTS |")
expect(post.explain.inspect).to include("| TABLE ACCESS FULL| TEST_POSTS |")
end

it "should explain considers hints with /*+ */" do
post = TestPost.optimizer_hints("/*+ FULL (\"TEST_POSTS\") */")
post = post.where(id: 1)
expect(post.explain).to include("| TABLE ACCESS FULL| TEST_POSTS |")
expect(post.explain.inspect).to include("| TABLE ACCESS FULL| TEST_POSTS |")
end
end

Expand Down

0 comments on commit 5370814

Please sign in to comment.