Skip to content

Commit

Permalink
Merge pull request #1846 from Shopify/env-propgating
Browse files Browse the repository at this point in the history
propagate Environment on new Context creation
  • Loading branch information
ggmichaelgo authored Nov 4, 2024
2 parents 4bd22a2 + 3ed54bf commit 06f4422
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/liquid/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Context

# rubocop:disable Metrics/ParameterLists
def self.build(environment: Environment.default, environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: {}, &block)
new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments, &block)
new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments, environment, &block)
end

def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = {}, environment = Environment.default)
Expand Down Expand Up @@ -143,6 +143,7 @@ def new_isolated_subcontext
check_overflow

self.class.build(
environment: @environment,
resource_limits: resource_limits,
static_environments: static_environments,
registers: Registers.new(registers),
Expand Down
15 changes: 15 additions & 0 deletions test/integration/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,21 @@ def test_variable_to_liquid_returns_contextual_drop
assert_includes(result, "unscoped_products_count: 5")
end

def test_new_isolated_context_inherits_parent_environment
global_environment = Liquid::Environment.build(tags: {})
context = Context.build(environment: global_environment)

subcontext = context.new_isolated_subcontext
assert_equal(global_environment, subcontext.environment)
end

def test_newly_built_context_inherits_parent_environment
global_environment = Liquid::Environment.build(tags: {})
context = Context.build(environment: global_environment)
assert_equal(global_environment, context.environment)
assert(context.environment.tags.each.to_a.empty?)
end

private

def assert_no_object_allocations
Expand Down

0 comments on commit 06f4422

Please sign in to comment.