Skip to content

Commit

Permalink
Add test for frozen_string_literal and inline components
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellhenke committed Oct 26, 2023
1 parent 65d3817 commit b15f939
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class MutatedStringInlineComponent < ViewComponent::Base
erb_template <<~ERB
<%= "a" << "b" %>
ERB
end
24 changes: 24 additions & 0 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1118,4 +1118,28 @@ def test_frozen_string_literal_enabled
ensure
ViewComponent::Base.config.frozen_string_literal = old_value
end

def test_inline_frozen_string_literal_disabled
old_value = ViewComponent::Base.config.frozen_string_literal
ViewComponent::Base.config.frozen_string_literal = false

with_new_cache do
render_inline(MutatedStringInlineComponent.new)
assert_includes rendered_content, "ab"
end
ensure
ViewComponent::Base.config.frozen_string_literal = old_value
end

def test_inline_frozen_string_literal_enabled
old_value = ViewComponent::Base.config.frozen_string_literal
ViewComponent::Base.config.frozen_string_literal = true
with_new_cache do
assert_raises FrozenError do
render_inline(MutatedStringInlineComponent.new)
end
end
ensure
ViewComponent::Base.config.frozen_string_literal = old_value
end
end

0 comments on commit b15f939

Please sign in to comment.