Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 1.9.1: Arrays & Hashes now become nil #48

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/strip_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def self.strip_record(record, options = {})
attributes = narrow(record.attributes, options)

attributes.each do |attr, value|
next unless value.is_a?(String)
original_value = value
value = strip_string(value, options)
record[attr] = value if original_value != value
Expand Down
19 changes: 19 additions & 0 deletions test/strip_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ class ReplaceNewLinesAndDuplicateSpaces < Tableless
strip_attributes replace_newlines: true, collapse_spaces: true
end

class CoexistWithOtherObjects < Tableless
attr_accessor :arr, :hsh, :str
strip_attributes
def initialize
@arr, @hsh, @str = [], {}, "foo "
end
def attributes
{arr: arr, hsh: hsh, str: str}
end
end

class CoexistWithOtherValidations < Tableless
attribute :number, type: Integer

Expand Down Expand Up @@ -242,6 +253,14 @@ def test_should_strip_and_allow_empty_always
assert_equal "", record.bang
end

def test_should_allow_other_empty_objects
record = CoexistWithOtherObjects.new
record.valid?
assert_equal [], record.arr
assert_equal({}, record.hsh)
assert_equal "foo", record.str
end

def test_should_coexist_with_other_validations
record = CoexistWithOtherValidations.new
record.number = 1000.1
Expand Down