Skip to content

Commit

Permalink
Faker::Number.leading_zero_number should always start with 0 (faker-r…
Browse files Browse the repository at this point in the history
…uby#1334)

* Leading_zero_number should always start with 0

* Update changelog

* Fix leading number tests

* Update changelog
  • Loading branch information
vbrazo committed Aug 23, 2018
1 parent 268dd01 commit c4a1667
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## HEAD Unreleased

### Bug/Fixes
- [PR #1334](https://github.com/stympy/faker/pull/1334) Faker::Number.leading_zero_number should always start with 0 [@vbrazo](https://github.com/vbrazo)
- [PR #1317](https://github.com/stympy/faker/pull/1317) Change Faker::Lorem.multibyte logic [@ShabelnikM](https://github.com/ShabelnikM)
- [PR #527](https://github.com/stympy/faker/pull/527) Fix time period test that could result in a flake test within 15 days [@melonhead901](https://github.com/melonhead901)
- [PR #1310](https://github.com/stympy/faker/pull/1310) Add alias for middle_name and remove locale [@vbrazo](https://github.com/vbrazo)
Expand All @@ -11,10 +12,14 @@
- [PR #1311](https://github.com/stympy/faker/pull/1311) Target Ruby 2.3 [@tagliala](https://github.com/tagliala)
- [PR #372](https://github.com/stympy/faker/pull/372) Add test_password_could_achieve_max_length [@oleksii-ti](https://github.com/oleksii-ti)

### Deprecation
- [PR #803](https://github.com/stympy/faker/pull/803) Modify Faker::Educator, Fix #576 [@ghbooth12](https://github.com/ghbooth12)

### Documentation
- [PR #1329](https://github.com/stympy/faker/pull/1329) Update docs on behavior of price [@softwaregravy](https://github.com/softwaregravy)

### Feature Request
- [PR #1342](https://github.com/stympy/faker/pull/1342) Added Faker::CryptoCoin scope [@jacksonpires](https://github.com/jacksonpires)
- [PR #1338](https://github.com/stympy/faker/pull/1338) Add new translations to the en-ZA locale [@bradleymarques](https://github.com/bradleymarques)
- [PR #1130](https://github.com/stympy/faker/pull/1130) Faker::Vehicle API updates [@lucasqueiroz](https://github.com/lucasqueiroz)
- [PR #1324](https://github.com/stympy/faker/pull/1319) Add Faker::SouthAfrica [@bradleymarques](https://github.com/bradleymarques)
Expand All @@ -33,6 +38,8 @@
- [PR #1246](https://github.com/stympy/faker/pull/1246) Store list of generators with enabled uniqueness for faster clear [@MarcPer](https://github.com/MarcPer)

### Update/add locales
- [PR #1343](https://github.com/stympy/faker/pull/1343) Update cell phone format to be phonelib compatible for Vietnam locale [@Looooong](https://github.com/Looooong)
- [PR #1340](https://github.com/stympy/faker/pull/1340) Fix typos and additions for Faker::Esport [@Mayurifag](https://github.com/Mayurifag)
- [PR #1332](https://github.com/stympy/faker/pull/1332) Fix typo in buffy.big_bads [@tragiclifestories](https://github.com/tragiclifestories)
- [PR #1327](https://github.com/stympy/faker/pull/1327) fixed 2 quotes [@MinimumViablePerson](https://github.com/MinimumViablePerson)
- [PR #1316](https://github.com/stympy/faker/pull/1316) Add more dishes to the menu [@bjacquet](https://github.com/bjacquet)
Expand Down
7 changes: 6 additions & 1 deletion lib/faker/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ class Number < Base
class << self
def number(digits = 10)
num = ''

if digits > 1
num = non_zero_digit
digits -= 1
end

num + leading_zero_number(digits)
end

def leading_zero_number(digits = 10)
(1..digits).collect { digit }.join
'0' + (2..digits).collect { digit }.join
end

def decimal_part(digits = 10)
Expand All @@ -28,6 +30,7 @@ def decimal_part(digits = 10)
def decimal(l_digits = 5, r_digits = 2)
l_d = number(l_digits)
r_d = decimal_part(r_digits)

"#{l_d}.#{r_d}"
end

Expand Down Expand Up @@ -58,11 +61,13 @@ def between(from = 1.00, to = 5000.00)

def positive(from = 1.00, to = 5000.00)
random_number = between(from, to)

greater_than_zero(random_number)
end

def negative(from = -5000.00, to = -1.00)
random_number = between(from, to)

less_than_zero(random_number)
end

Expand Down
6 changes: 5 additions & 1 deletion test/test_faker_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def setup
@tester = Faker::Number
end

def test_leading_zero_number
assert_match(/^0[0-9]{9}/, @tester.leading_zero_number)
assert_match(/^0[0-9]{8}/, @tester.leading_zero_number(9))
end

def test_number
assert @tester.number(10).match(/[0-9]{10}/)

Expand All @@ -18,7 +23,6 @@ def test_number

assert @tester.number(10).length == 10
assert @tester.number(1).length == 1
assert @tester.number(0) == ''
end

def test_decimal
Expand Down

0 comments on commit c4a1667

Please sign in to comment.