diff options
author | Rafael Mendonça França <rafael@franca.dev> | 2019-07-25 16:18:18 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafael@franca.dev> | 2019-07-25 16:18:18 -0400 |
commit | c9b7b9ff8adb3f01db0f9af90359030028a33b5b (patch) | |
tree | 02cf4d079caaa6f5553067f049950657714ad44f /activesupport/test | |
parent | 706ee3eb490781387e9a7e00ab9cfdb3d3dbf264 (diff) | |
parent | 459657a9f86f2ff951608e21b4b217e1057c50af (diff) | |
download | rails-c9b7b9ff8adb3f01db0f9af90359030028a33b5b.tar.gz rails-c9b7b9ff8adb3f01db0f9af90359030028a33b5b.tar.bz2 rails-c9b7b9ff8adb3f01db0f9af90359030028a33b5b.zip |
Merge pull request #36412 from robotdana/compact_blank
Add compact_blank shortcut for reject(&:blank?)
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/enumerable_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 381b5a1f32..a9bf4b82f4 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -242,4 +242,28 @@ class EnumerableTests < ActiveSupport::TestCase ]) assert_equal [[5, 99], [15, 0], [10, 50]], payments.pluck(:dollars, :cents) end + + def test_compact_blank + values = GenericEnumerable.new([1, "", nil, 2, " ", [], {}, false, true]) + + assert_equal [1, 2, true], values.compact_blank + end + + def test_array_compact_blank! + values = [1, "", nil, 2, " ", [], {}, false, true] + values.compact_blank! + + assert_equal [1, 2, true], values + end + + def test_hash_compact_blank + values = { a: "", b: 1, c: nil, d: [], e: false, f: true } + assert_equal({ b: 1, f: true }, values.compact_blank) + end + + def test_hash_compact_blank! + values = { a: "", b: 1, c: nil, d: [], e: false, f: true } + values.compact_blank! + assert_equal({ b: 1, f: true }, values) + end end |