Skip to content

Commit 0620b52

Browse files
Replace via.placeholder.com with placehold.co
Fixes #3055
1 parent 3b6efaf commit 0620b52

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

doc/default/omniauth.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Faker::Omniauth.github #=>
215215
:nickname => "jackson-keeling",
216216
:email => "jackson.keeling@example.com",
217217
:name => "Jackson Keeling",
218-
:image => "https://via.placeholder.com/300x300.png",
218+
:image => "https://placehold.co/300x300.png",
219219
:urls => {
220220
:GitHub => "https://github.com/jackson-keeling"
221221
}
@@ -228,7 +228,7 @@ Faker::Omniauth.github #=>
228228
:raw_info => {
229229
:login => "jackson-keeling",
230230
:id => "95144751",
231-
:avatar_url => "https://via.placeholder.com/300x300.png",
231+
:avatar_url => "https://placehold.co/300x300.png",
232232
:gravatar_id => "",
233233
:url => "https://api.github.com/users/jackson-keeling",
234234
:html_url => "https://github.com/jackson-keeling",
@@ -299,7 +299,7 @@ Faker::Omniauth.auth0 #=>
299299
:name => "auth0|d0584e3ab2d3816be9518a56",
300300
:nickname => "Thurman DuBuque",
301301
:email => "dubuque_thurman@example.com",
302-
:image => "https://via.placeholder.com/300x300.png"
302+
:image => "https://placehold.co/300x300.png"
303303
},
304304
:credentials=> {
305305
:expires_at => 1654345109,

doc/default/placeholdit.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
```ruby
44
# Keyword arguments: size, format, background_color, text_color, text
5-
Faker::Placeholdit.image #=> "https://via.placeholder.com/300x300.png"
6-
Faker::Placeholdit.image(size: '50x50') #=> "https://via.placeholder.com/50x50.png"
7-
Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://via.placeholder.com/50x50.jpg"
8-
Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://via.placeholder.com/50x50.gif/ffffff"
9-
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://via.placeholder.com/50x50.jpeg/39eba7"
10-
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://via.placeholder.com/50x50.jpeg/ffffff/000"
11-
Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://via.placeholder.com/50x50.jpg/ffffff/000?text=Some Custom Text"
5+
Faker::Placeholdit.image #=> "https://placehold.co/300x300.png"
6+
Faker::Placeholdit.image(size: '50x50') #=> "https://placehold.co/50x50.png"
7+
Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://placehold.co/50x50.jpg"
8+
Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://placehold.co/50x50.gif/ffffff"
9+
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://placehold.co/50x50.jpeg/39eba7"
10+
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://placehold.co/50x50.jpeg/ffffff/000"
11+
Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://placehold.co/50x50.jpg/ffffff/000?text=Some Custom Text"
1212
```
1313

1414
## Tips

lib/faker/default/placeholdit.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
module Faker
44
class Placeholdit < Base
55
class << self
6-
SUPPORTED_FORMATS = %w[png jpg gif jpeg].freeze
6+
SUPPORTED_FORMATS = %w[avif gif jpg jpeg png svg webp].freeze
77

88
##
9-
# Produces a random placeholder image from https://via.placeholder.com.
9+
# Produces a random placeholder image from https://placehold.co.
1010
#
1111
# @param size [String] Specifies the image's size, dimensions separated by 'x'.
1212
# @param format [String] Specifies the image's extension.
@@ -17,13 +17,13 @@ class << self
1717
#
1818
# @example
1919
# # Keyword arguments: size, format, background_color, text_color, text
20-
# Faker::Placeholdit.image #=> "https://via.placeholder.com/300x300.png"
21-
# Faker::Placeholdit.image(size: '50x50') #=> "https://via.placeholder.com/50x50.png"
22-
# Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://via.placeholder.com/50x50.jpg"
23-
# Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://via.placeholder.com/50x50.gif/ffffff"
24-
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://via.placeholder.com/50x50.jpeg/39eba7"
25-
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://via.placeholder.com/50x50.jpeg/ffffff/000"
26-
# Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://via.placeholder.com/50x50.jpg/ffffff/000?text=Some Custom Text"
20+
# Faker::Placeholdit.image #=> "https://placehold.co/300x300.png"
21+
# Faker::Placeholdit.image(size: '50x50') #=> "https://placehold.co/50x50.png"
22+
# Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://placehold.co/50x50.jpg"
23+
# Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://placehold.co/50x50/ffffff/000.gif"
24+
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://placehold.co/50x50/39eba7/000.jpeg"
25+
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://placehold.co/50x50/ffffff/000.jpeg"
26+
# Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://placehold.co/50x50/ffffff/000.jpg?text=Some Custom Text"
2727
#
2828
# @faker.version 1.6.0
2929
def image(size: '300x300', format: 'png', background_color: nil, text_color: nil, text: nil)
@@ -35,9 +35,11 @@ def image(size: '300x300', format: 'png', background_color: nil, text_color: nil
3535
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
3636
raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
3737

38-
image_url = "https://via.placeholder.com/#{size}.#{format}"
39-
image_url += "/#{background_color}" if background_color
40-
image_url += "/#{text_color}" if text_color
38+
image_url = "https://placehold.co/#{size}"
39+
if background_color || text_color
40+
image_url += "/#{background_color || 'fff'}/#{text_color || '000'}"
41+
end
42+
image_url += ".#{format}"
4143
image_url += "?text=#{text}" if text
4244
image_url
4345
end

test/faker/default/test_placeholdit.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def setup
88
end
99

1010
def test_placeholdit
11-
refute_nil @tester.image.match(%r{https://via\.placeholder\.com/(.+)(png?)})[1]
11+
refute_nil @tester.image.match(%r{https://placehold\.co/(.+)(png?)})[1]
1212
end
1313

1414
def test_avatar_with_custom_size
15-
assert_equal('3x3', @tester.image(size: '3x3').match(%r{https://via\.placeholder\.com/+(\d+x\d+)})[1])
15+
assert_equal('3x3', @tester.image(size: '3x3').match(%r{https://placehold\.co/+(\d+x\d+)})[1])
1616
end
1717

1818
def test_avatar_with_incorrect_size
@@ -22,7 +22,7 @@ def test_avatar_with_incorrect_size
2222
end
2323

2424
def test_avatar_with_supported_format
25-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)}, @tester.image(size: '300x300', format: 'jpg')
25+
assert_match %r{https://placehold\.co/(.+)(jpg?)}, @tester.image(size: '300x300', format: 'jpg')
2626
end
2727

2828
def test_avatar_with_incorrect_format
@@ -31,16 +31,20 @@ def test_avatar_with_incorrect_format
3131
end
3232
end
3333

34+
def test_avatar_uses_000_as_text_when_only_specifying_background
35+
assert_match %r{https://placehold\.co/(.+)/ffffff/000}, @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff')
36+
end
37+
3438
def test_avatar_background_with_correct_six_char_hex
35-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)/ffffff}, @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff')
39+
assert_match %r{https://placehold\.co/(.+)/ffffff}, @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff')
3640
end
3741

3842
def test_avatar_background_with_correct_three_char_hex
39-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)/fff}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff')
43+
assert_match %r{https://placehold\.co/(.+)/fff}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff')
4044
end
4145

4246
def test_avatar_background_with_random_color
43-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)/[a-f0-9]{6}}, @tester.image(size: '300x300', format: 'jpg', background_color: :random)
47+
assert_match %r{https://placehold\.co/(.+)/[a-f0-9]{6}/000}, @tester.image(size: '300x300', format: 'jpg', background_color: :random)
4448
end
4549

4650
def test_avatar_background_with_wrong_six_char_hex
@@ -61,16 +65,20 @@ def test_avatar_background_with_wrong_three_char_hex
6165
end
6266
end
6367

68+
def test_avatar_uses_fff_as_background_when_only_specifying_font_color
69+
assert_match %r{https://placehold\.co/(.+)/fff/000000}, @tester.image(size: '300x300', format: 'jpg', text_color: '000000')
70+
end
71+
6472
def test_avatar_font_color_with_correct_six_char_hex
65-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)/ffffff/000000}, @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff', text_color: '000000')
73+
assert_match %r{https://placehold\.co/(.+)/ffffff/000000}, @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff', text_color: '000000')
6674
end
6775

6876
def test_avatar_font_color_with_correct_three_char_hex
69-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)/fff}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000')
77+
assert_match %r{https://placehold\.co/(.+)/fff}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000')
7078
end
7179

7280
def test_avatar_font_color_with_random_color
73-
assert_match %r{https://via\.placeholder\.com/(.+)(jpg?)/fff/[a-f0-9]{6}}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: :random)
81+
assert_match %r{https://placehold\.co/(.+)/fff/[a-f0-9]{6}}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: :random)
7482
end
7583

7684
def test_avatar_font_color_with_wrong_six_char_hex
@@ -92,10 +100,10 @@ def test_avatar_font_color_with_wrong_three_char_hex
92100
end
93101

94102
def test_text_not_present
95-
assert_match %r{https://via\.placeholder\.com/[^\\?]+$}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000')
103+
assert_match %r{https://placehold\.co/[^\\?]+$}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000')
96104
end
97105

98106
def test_text_present
99-
assert_match %r{https://via\.placeholder\.com/(.+)\?text=hello}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000', text: 'hello')
107+
assert_match %r{https://placehold\.co/(.+)\?text=hello}, @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000', text: 'hello')
100108
end
101109
end

0 commit comments

Comments
 (0)