Skip to content

Commit 027db53

Browse files
committed
Add missing tests for Rails/CompactBlank when receiver is a hash
1 parent 93f9a89 commit 027db53

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

spec/rubocop/cop/rails/compact_blank_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
RUBY
2525
end
2626

27+
it 'registers and corrects an offense when using `reject { |k, v| v.blank? }`' do
28+
expect_offense(<<~RUBY)
29+
collection.reject { |k, v| v.blank? }
30+
^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead.
31+
RUBY
32+
33+
expect_correction(<<~RUBY)
34+
collection.compact_blank
35+
RUBY
36+
end
37+
2738
it 'registers and corrects an offense when using `delete_if { |e| e.blank? }`' do
2839
expect_offense(<<~RUBY)
2940
collection.delete_if { |e| e.blank? }
@@ -46,6 +57,17 @@
4657
RUBY
4758
end
4859

60+
it 'registers and corrects an offense when using `delete_if { |k, v| v.blank? }`' do
61+
expect_offense(<<~RUBY)
62+
collection.delete_if { |k, v| v.blank? }
63+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead.
64+
RUBY
65+
66+
expect_correction(<<~RUBY)
67+
collection.compact_blank!
68+
RUBY
69+
end
70+
4971
it 'does not registers an offense when using `reject! { |e| e.blank? }`' do
5072
expect_no_offenses(<<~RUBY)
5173
collection.reject! { |e| e.blank? }
@@ -91,6 +113,17 @@
91113
RUBY
92114
end
93115

116+
it 'registers and corrects an offense when using `select { |k, v| v.present? }`' do
117+
expect_offense(<<~RUBY)
118+
collection.select { |k, v| v.present? }
119+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead.
120+
RUBY
121+
122+
expect_correction(<<~RUBY)
123+
collection.compact_blank
124+
RUBY
125+
end
126+
94127
it 'registers and corrects an offense when using `keep_if { |e| e.present? }`' do
95128
expect_offense(<<~RUBY)
96129
collection.keep_if { |e| e.present? }
@@ -113,6 +146,17 @@
113146
RUBY
114147
end
115148

149+
it 'registers and corrects an offense when using `keep_if { |k, v| v.present? }`' do
150+
expect_offense(<<~RUBY)
151+
collection.keep_if { |k, v| v.present? }
152+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead.
153+
RUBY
154+
155+
expect_correction(<<~RUBY)
156+
collection.compact_blank!
157+
RUBY
158+
end
159+
116160
it 'does not register an offense when using `select! { |e| e.present? }`' do
117161
expect_no_offenses(<<~RUBY)
118162
collection.select! { |e| e.present? }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy