Skip to content

Commit

Permalink
Dupe initialized fragment value
Browse files Browse the repository at this point in the history
Fix multiple calls with the same fragment string object
  • Loading branch information
teeparham committed Jul 27, 2017
1 parent 08d7edb commit 639f109
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cache_rocket/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Fragment
include Key

def initialize(value)
@value = value
@value = value.to_s.dup
end

def to_s
Expand Down
6 changes: 6 additions & 0 deletions test/fragment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def last5(object)
assert_equal "hey Tiger hey.hey Skunk hey.",
fragment.replace(replace_hash, collection).to_s
end

it "does not modify initialized value" do
value = "Hi #{Fragment.new(nil).cache_replace_key(:x)}"
assert_equal "Hi 1", Fragment.new(value).replace({ x: "1"}, nil).to_s
assert_equal "Hi 2", Fragment.new(value).replace({ x: "2"}, nil).to_s
end
end
end
end

0 comments on commit 639f109

Please sign in to comment.