diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..d404c5ddfa --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,14 @@ +Issue# +------ + +Example: + +https://github.com/stympy/faker/issues/XXX + +OR + +`No-Story` + +Description: +------ +*Describe what this PR does in a few lines. If you are adding a new faker generator, please tell us how you're going to use this object. Use cases are important because we need to make sure that our faker generators are useful. After adding the description, please delete this line.* diff --git a/doc/default/file.md b/doc/default/file.md index d52b4cd939..23cc1742c1 100644 --- a/doc/default/file.md +++ b/doc/default/file.md @@ -11,5 +11,11 @@ Faker::File.mime_type #=> "application/pdf" Faker::File.file_name('path/to') #=> "path/to/something_random.jpg" Faker::File.file_name('foo/bar', 'baz') #=> "foo/bar/baz.zip" Faker::File.file_name('foo/bar', 'baz', 'doc') #=> "foo/bar/baz.doc" -Faker::File.file_name('foo/bar', 'baz', 'mp3', '\') #=> "foo\bar\baz.mp3" +Faker::File.file_name('foo/bar', 'baz', 'mp3', '\\') #=> "foo\bar\baz.mp3" + +# Optional arguments: segment_count, root, directory_separator +Faker::File.dir #=> "path/to/something_random" +Faker::File.dir(2) #=> "foo/bar" +Faker::File.dir(3, '/') #=> "/foo/bar/baz" +Faker::File.dir(3, nil, '\\') #=> "foo\bar\baz" ``` diff --git a/doc/unreleased/default/file.md b/doc/unreleased/default/file.md index d52b4cd939..23cc1742c1 100644 --- a/doc/unreleased/default/file.md +++ b/doc/unreleased/default/file.md @@ -11,5 +11,11 @@ Faker::File.mime_type #=> "application/pdf" Faker::File.file_name('path/to') #=> "path/to/something_random.jpg" Faker::File.file_name('foo/bar', 'baz') #=> "foo/bar/baz.zip" Faker::File.file_name('foo/bar', 'baz', 'doc') #=> "foo/bar/baz.doc" -Faker::File.file_name('foo/bar', 'baz', 'mp3', '\') #=> "foo\bar\baz.mp3" +Faker::File.file_name('foo/bar', 'baz', 'mp3', '\\') #=> "foo\bar\baz.mp3" + +# Optional arguments: segment_count, root, directory_separator +Faker::File.dir #=> "path/to/something_random" +Faker::File.dir(2) #=> "foo/bar" +Faker::File.dir(3, '/') #=> "/foo/bar/baz" +Faker::File.dir(3, nil, '\\') #=> "foo\bar\baz" ``` diff --git a/lib/faker/default/file.rb b/lib/faker/default/file.rb index fd76a99d0b..44fa8ec0d0 100644 --- a/lib/faker/default/file.rb +++ b/lib/faker/default/file.rb @@ -3,6 +3,15 @@ module Faker class File < Base class << self + def dir(segment_count = 3, root = nil, directory_separator = '/') + Array + .new(segment_count) { Faker::Internet.slug } + .unshift(root) + .compact + .join(directory_separator) + .squeeze(directory_separator) + end + def extension fetch('file.extension') end @@ -12,7 +21,7 @@ def mime_type end def file_name(dir = nil, name = nil, ext = nil, directory_separator = '/') - dir ||= Faker::Internet.slug + dir ||= dir(1) name ||= Faker::Lorem.word.downcase ext ||= extension diff --git a/lib/faker/default/number.rb b/lib/faker/default/number.rb index 6c45c856b3..6b78e16e05 100644 --- a/lib/faker/default/number.rb +++ b/lib/faker/default/number.rb @@ -3,6 +3,8 @@ module Faker class Number < Base class << self + extend Gem::Deprecate + def number(digits = 10) num = '' @@ -92,6 +94,9 @@ def should_be(number, method_to_compare) number * -1 end end + + deprecate :decimal_part, nil, 2019, 06 + deprecate :leading_zero_number, nil, 2019, 06 end end end diff --git a/test/faker/default/test_faker_file.rb b/test/faker/default/test_faker_file.rb index 9ecb75bf2a..a8975a4323 100644 --- a/test/faker/default/test_faker_file.rb +++ b/test/faker/default/test_faker_file.rb @@ -16,6 +16,18 @@ def test_mime_type_format end def test_file_name - assert @tester.file_name.match(%r{([a-z\-_]+)(\\|\/)([a-z\-_]+)\.([a-z]+)}) + assert @tester + .file_name + .match(%r{^([a-z\-_.]+)(\\|\/)([a-z\-_]+)\.([a-z]+)$}) + end + + def test_dir + assert @tester.dir.match(%r{^(([a-z\-_.]+)(\\|\/)){2}([a-z\-_.]+)$}) + end + + def test_dir_with_args + assert @tester + .dir(2, '\\root\\', '\\') + .match(%r{^\\root(\\([a-z\-_.]+)){2}$}) end end