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

fix broken link for placeholdit #2356

Merged
merged 1 commit into from Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/default/omniauth.md
Expand Up @@ -215,7 +215,7 @@ Faker::Omniauth.github #=>
:nickname => "jackson-keeling",
:email => "jackson.keeling@example.com",
:name => "Jackson Keeling",
:image => "https://placehold.it/300x300.png",
:image => "https://via.placeholder.com/300x300.png",
:urls => {
:GitHub => "https://github.com/jackson-keeling"
}
Expand All @@ -228,7 +228,7 @@ Faker::Omniauth.github #=>
:raw_info => {
:login => "jackson-keeling",
:id => "95144751",
:avatar_url => "https://placehold.it/300x300.png",
:avatar_url => "https://via.placeholder.com/300x300.png",
:gravatar_id => "",
:url => "https://api.github.com/users/jackson-keeling",
:html_url => "https://github.com/jackson-keeling",
Expand Down
14 changes: 7 additions & 7 deletions doc/default/placeholdit.md
Expand Up @@ -2,13 +2,13 @@

```ruby
# Keyword arguments: size, format, background_color, text_color, text
Faker::Placeholdit.image #=> "https://placehold.it/300x300.png"
Faker::Placeholdit.image(size: '50x50') #=> "https://placehold.it/50x50.png"
Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://placehold.it/50x50.jpg"
Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://placehold.it/50x50.gif/ffffff"
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://placehold.it/50x50.jpeg/39eba7"
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://placehold.it/50x50.jpeg/ffffff/000"
Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://placehold.it/50x50.jpg/ffffff/000?text=Some Custom Text"
Faker::Placeholdit.image #=> "https://via.placeholder.com/300x300.png"
Faker::Placeholdit.image(size: '50x50') #=> "https://via.placeholder.com/50x50.png"
Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://via.placeholder.com/50x50.jpg"
Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://via.placeholder.com/50x50.gif/ffffff"
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://via.placeholder.com/50x50.jpeg/39eba7"
Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://via.placeholder.com/50x50.jpeg/ffffff/000"
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"
```

## Tips
Expand Down
18 changes: 9 additions & 9 deletions lib/faker/default/placeholdit.rb
Expand Up @@ -8,7 +8,7 @@ class << self
# rubocop:disable Metrics/ParameterLists

##
# Produces a random placeholder image from https://placehold.it.
# Produces a random placeholder image from https://via.placeholder.com.
#
# @param size [String] Specifies the image's size, dimensions separated by 'x'.
# @param format [String] Specifies the image's extension.
Expand All @@ -19,13 +19,13 @@ class << self
#
# @example
# # Keyword arguments: size, format, background_color, text_color, text
# Faker::Placeholdit.image #=> "https://placehold.it/300x300.png"
# Faker::Placeholdit.image(size: '50x50') #=> "https://placehold.it/50x50.png"
# Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://placehold.it/50x50.jpg"
# Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://placehold.it/50x50.gif/ffffff"
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://placehold.it/50x50.jpeg/39eba7"
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://placehold.it/50x50.jpeg/ffffff/000"
# Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> "https://placehold.it/50x50.jpg/ffffff/000?text=Some Custom Text"
# Faker::Placeholdit.image #=> "https://via.placeholder.com/300x300.png"
# Faker::Placeholdit.image(size: '50x50') #=> "https://via.placeholder.com/50x50.png"
# Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://via.placeholder.com/50x50.jpg"
# Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://via.placeholder.com/50x50.gif/ffffff"
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://via.placeholder.com/50x50.jpeg/39eba7"
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://via.placeholder.com/50x50.jpeg/ffffff/000"
# 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"
#
# @faker.version 1.6.0
def image(legacy_size = NOT_GIVEN, legacy_format = NOT_GIVEN, legacy_background_color = NOT_GIVEN, legacy_text_color = NOT_GIVEN, legacy_text = NOT_GIVEN, size: '300x300', format: 'png', background_color: nil, text_color: nil, text: nil)
Expand All @@ -45,7 +45,7 @@ def image(legacy_size = NOT_GIVEN, legacy_format = NOT_GIVEN, legacy_background_
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/

image_url = "https://placehold.it/#{size}.#{format}"
image_url = "https://via.placeholder.com/#{size}.#{format}"
image_url += "/#{background_color}" if background_color
image_url += "/#{text_color}" if text_color
image_url += "?text=#{text}" if text
Expand Down
22 changes: 11 additions & 11 deletions test/faker/default/test_placeholdit.rb
Expand Up @@ -8,11 +8,11 @@ def setup
end

def test_placeholdit
assert !@tester.image.match(%r{https://placehold\.it/(.+)(png?)})[1].nil?
assert !@tester.image.match(%r{https://via\.placeholder\.com/(.+)(png?)})[1].nil?
end

def test_avatar_with_custom_size
assert @tester.image(size: '3x3').match(%r{https://placehold\.it/+(\d+x\d+)})[1] == '3x3'
assert @tester.image(size: '3x3').match(%r{https://via\.placeholder\.com/+(\d+x\d+)})[1] == '3x3'
end

def test_avatar_with_incorrect_size
Expand All @@ -22,7 +22,7 @@ def test_avatar_with_incorrect_size
end

def test_avatar_with_supported_format
assert @tester.image(size: '300x300', format: 'jpg').match(%r{https://placehold\.it/(.+)(jpg?)})
assert @tester.image(size: '300x300', format: 'jpg').match(%r{https://via\.placeholder\.com/(.+)(jpg?)})
end

def test_avatar_with_incorrect_format
Expand All @@ -32,15 +32,15 @@ def test_avatar_with_incorrect_format
end

def test_avatar_background_with_correct_six_char_hex
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff').match(%r{https://placehold\.it/(.+)(jpg?)/ffffff})
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff').match(%r{https://via\.placeholder\.com/(.+)(jpg?)/ffffff})
end

def test_avatar_background_with_correct_three_char_hex
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff').match(%r{https://placehold\.it/(.+)(jpg?)/fff})
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff').match(%r{https://via\.placeholder\.com/(.+)(jpg?)/fff})
end

def test_avatar_background_with_random_color
assert @tester.image(size: '300x300', format: 'jpg', background_color: :random).match(%r{https://placehold\.it/(.+)(jpg?)/[a-f0-9]{6}})
assert @tester.image(size: '300x300', format: 'jpg', background_color: :random).match(%r{https://via\.placeholder\.com/(.+)(jpg?)/[a-f0-9]{6}})
end

def test_avatar_background_with_wrong_six_char_hex
Expand All @@ -62,15 +62,15 @@ def test_avatar_background_with_wrong_three_char_hex
end

def test_avatar_font_color_with_correct_six_char_hex
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff', text_color: '000000').match(%r{https://placehold\.it/(.+)(jpg?)/ffffff/000000})
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'ffffff', text_color: '000000').match(%r{https://via\.placeholder\.com/(.+)(jpg?)/ffffff/000000})
end

def test_avatar_font_color_with_correct_three_char_hex
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https://placehold\.it/(.+)(jpg?)/fff})
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https://via\.placeholder\.com/(.+)(jpg?)/fff})
end

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

def test_avatar_font_color_with_wrong_six_char_hex
Expand All @@ -92,10 +92,10 @@ def test_avatar_font_color_with_wrong_three_char_hex
end

def test_text_not_present
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https://placehold\.it/[^\\?]+$})
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000').match(%r{https://via\.placeholder\.com/[^\\?]+$})
end

def test_text_present
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000', text: 'hello').match(%r{https://placehold\.it/(.+)\?text=hello})
assert @tester.image(size: '300x300', format: 'jpg', background_color: 'fff', text_color: '000', text: 'hello').match(%r{https://via\.placeholder\.com/(.+)\?text=hello})
end
end