diff --git a/lib/liquid/forloop_drop.rb b/lib/liquid/forloop_drop.rb index 4685166..3e1fa02 100644 --- a/lib/liquid/forloop_drop.rb +++ b/lib/liquid/forloop_drop.rb @@ -9,7 +9,12 @@ module Liquid @index = 0 end - attr_reader :name, :length, :parentloop + attr_reader :length, :parentloop + + def name + Usage.increment('forloop_drop_name') + @name + end def index @index + 1 diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 320fc15..f19d630 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -447,4 +447,20 @@ HERE Template.parse('{% for item in items offset:2 %}{{item}}{% endfor %}') end end + + def test_instrument_forloop_drop_name + assigns = { 'items' => [1, 2, 3, 4, 5] } + + assert_usage_increment('forloop_drop_name', times: 5) do + Template.parse('{% for item in items %}{{forloop.name}}{% endfor %}').render!(assigns) + end + + assert_usage_increment('forloop_drop_name', times: 0) do + Template.parse('{% for item in items %}{{forloop.index}}{% endfor %}').render!(assigns) + end + + assert_usage_increment('forloop_drop_name', times: 0) do + Template.parse('{% for item in items %}{{item}}{% endfor %}').render!(assigns) + end + end end