Skip to content

Commit

Permalink
Fix strip behavior for frozen values
Browse files Browse the repository at this point in the history
  • Loading branch information
rmm5t committed Apr 2, 2020
1 parent 315ab24 commit c87721f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/strip_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ def self.strip_record(record, options = {})

def self.strip_string(value, options = {})
return value unless value.is_a?(String)
# TODO: FUTURE CHANGE: return value if value.frozen?

allow_empty = options[:allow_empty]
collapse_spaces = options[:collapse_spaces]
replace_newlines = options[:replace_newlines]
regex = options[:regex]

value = value.dup
value.gsub!(regex, "") if regex

if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE)
Expand Down
7 changes: 7 additions & 0 deletions test/strip_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.included(base)
base.attribute :qux
base.attribute :strip_me
base.attribute :skip_me
base.attribute :frozen
end
end

Expand Down Expand Up @@ -203,6 +204,12 @@ def test_should_strip_and_allow_empty
assert_equal "", record.bang
end

def test_should_strip_frozen_values
record = StripAllMockRecord.new(frozen: " ice ".freeze)
record.valid?
assert_equal "ice", record.frozen
end

def test_should_collapse_duplicate_spaces
record = CollapseDuplicateSpaces.new(@init_params)
record.valid?
Expand Down

0 comments on commit c87721f

Please sign in to comment.