Skip to content

Commit

Permalink
Propagate :retryable on composite collector to children
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianna-chang-shopify committed Mar 20, 2024
1 parent 110ee85 commit 07a824c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activerecord/lib/arel/collectors/bind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Arel # :nodoc: all
module Collectors
class Bind
attr_accessor :retryable

def initialize
@binds = []
end
Expand Down
9 changes: 8 additions & 1 deletion activerecord/lib/arel/collectors/composite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
module Arel # :nodoc: all
module Collectors
class Composite
attr_accessor :preparable, :retryable
attr_accessor :preparable
attr_reader :retryable

def initialize(left, right)
@left = left
@right = right
end

def retryable=(retryable)
left.retryable = retryable
right.retryable = retryable
@retryable = retryable
end

def <<(str)
left << str
right << str
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/arel/collectors/composite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def test_composite_collector_performs_multiple_collections_at_once
assert_equal 'SELECT FROM "users" WHERE "users"."age" = ? AND "users"."name" = ?', sql
assert_equal ["hello2", "world3"], binds
end

def test_retryable_on_composite_collector_propagates
sql_collector = Collectors::SQLString.new
bind_collector = Collectors::Bind.new
collector = Collectors::Composite.new(sql_collector, bind_collector)
collector.retryable = true

assert sql_collector.retryable
assert bind_collector.retryable
end
end
end
end

0 comments on commit 07a824c

Please sign in to comment.