Skip to content

Commit

Permalink
Added fillmurray
Browse files Browse the repository at this point in the history
Closes #673
  • Loading branch information
Jedeu authored and stympy committed Dec 24, 2016
1 parent 91f1fac commit 1b43609
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,19 @@ Faker::Placeholdit.image("50x50", 'jpg', 'ffffff', '000', 'Some Custom Text') #=

```

###FAKER::Fillmurray
-------------------

```ruby

Faker::Fillmurray.image #=> "http://fillmurray.com/300/300"

Faker::Fillmurray.image(true) #=> "http://fillmurray.com/g/300/300"

Faker::Fillmurray.image(false, 200, 400) #=> "http://fillmurray.com/200/400"

```

###Faker::Hipster
----------------
Adapted from [Hipster Ipsum](http://hipsum.co/)
Expand Down
1 change: 1 addition & 0 deletions lib/faker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def unique(max_retries = 10_000)
require 'faker/twin_peaks'
require 'faker/lord_of_the_rings'
require 'faker/rock_band'
require 'faker/fillmurray'

require 'extensions/array'
require 'extensions/symbol'
Expand Down
18 changes: 18 additions & 0 deletions lib/faker/fillmurray.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


module Faker
class Fillmurray < Base
class << self

def image(grayscale = false, width = 200, height = 200)
raise ArgumentError, "Width should be a number in string format" unless width.match(/^[0-9]+$/)
raise ArgumentError, "Height should be a number in string format" unless height.match(/^[0-9]+$/)
raise ArgumentError, "Grayscale should be a boolean" unless [true, false].include?(grayscale)

fillmurray_url = grayscale == true ? "https://fillmurray.com/g/#{width}/#{height}" : "https://fillmurray.com/#{width}/#{height}"

fillmurray_url
end
end
end
end
34 changes: 34 additions & 0 deletions test/test_faker_fillmurray.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')

class TestFakerFillmurray < Test::Unit::TestCase
def setup
@tester = Faker::Fillmurray
end

def test_fillmurray
assert @tester.image(false, '300', '300').match(/https:\/\/fillmurray\.com\/(\d+)\/(\d+)/) != nil
end

def test_fillmurray_with_grayscale
assert @tester.image(true, '300', '300').match(/https:\/\/fillmurray\.com\/(g?\/?)(\d+)\/(\d+)/)[1] == 'g/'
end

def test_fillmurray_with_incorrect_height_format
assert_raise ArgumentError do
@tester.image(false, '300', 'nine-thousand')
end

end

def test_fillmurray_with_incorrect_width_format
assert_raise ArgumentError do
@tester.image(false, 'three-hundred')
end
end

def test_fillmurray_with_incorrect_grayscale
assert_raise ArgumentError do
@tester.image('gray', '300', '400')
end
end
end

0 comments on commit 1b43609

Please sign in to comment.