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

Add date mutators #1

Merged
merged 9 commits into from
Apr 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/fake_pipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: fake_pipe

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
specs:
runs-on: ubuntu-latest

strategy:
matrix:
ruby: [ 2.7, 3.1, 3.2 ]

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run tests
run: bundle exec rspec --backtrace
38 changes: 0 additions & 38 deletions .github/workflows/ruby.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ anon: url # Faker::Internet.url
anon: user_name # Faker::Internet.user_name
anon: uuid # UUID
anon: zip_code # Faker::Address.zip_code
anon: birthday # Faker::Date.birthday(min_age: 18, max_age: 65)
anon: date # Faker::Date.backward(days: 365)
```

# Decisions
Expand Down Expand Up @@ -131,4 +133,3 @@ Thanks to the following contributors:

The gem is available as open source under the terms of the [MIT
License](http://opensource.org/licenses/MIT).

6 changes: 3 additions & 3 deletions fake_pipe.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'activesupport'
spec.add_dependency 'faker'
spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_dependency 'faker', '~> 3.3'
spec.add_dependency 'csv'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
end
18 changes: 14 additions & 4 deletions lib/fake_pipe/mutator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ def mutate_commerce_price(_)
end

# Faker::Number.decimal
def mutate_decimal_number(l_digits, precision=nil)
precision = l_digits unless precision.present?
Faker::Number.decimal(l_digits, precision)
def mutate_decimal_number(l_digits, r_digits=nil)
r_digits = l_digits unless r_digits.present?
Faker::Number.decimal(l_digits: l_digits, r_digits: r_digits)
end

#Faker::Number.number
def mutate_number(digits)
Faker::Number.number(digits)
Faker::Number.number(digits: digits)
end

# Faker::Number.digit
Expand Down Expand Up @@ -232,6 +232,16 @@ def mutate_zip_code(_)
Faker::Address.zip_code
end

# Faker::Date.birthday
def mutate_birthday(_)
Faker::Date.birthday(min_age: 18, max_age: 65)
end

# Faker::Date.backward
def mutate_date(_)
Faker::Date.backward(days: 365)
end

# Reopen class to define aliases on module_function
class << self
alias mutate_guid mutate_uuid
Expand Down
24 changes: 18 additions & 6 deletions spec/anonymizer/mutator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module FakePipe
it 'lists mutators' do
expect(described_class.list)
.to contain_exactly('address_city','zip_code','latitude', 'longitude','address_country', 'address_line_1', 'address_line_2', 'address_postcode', 'address_state', 'bcrypt_password', 'bcrypt_salt', 'clean_phone_number', 'company_catch_phrase', 'company_name', 'email', 'empty_curly', 'empty_bracket', 'empty_string', 'first_name', 'full_name', 'last_name', 'lorem_paragraph', 'lorem_sentence', 'lorem_word', 'md5', 'phone_ext', 'phone_number', 'url', 'user_name', 'uuid', 'guid', 'ugcid', 'bank_name',
'commerce_price', 'decimal_number', 'digit', 'domain_name', 'domain_suffix', 'ip_v4_address', 'number')
'commerce_price', 'decimal_number', 'digit', 'domain_name', 'domain_suffix', 'ip_v4_address', 'number', 'birthday', 'date')
end

context '#mutate_clean_phone_number' do
Expand Down Expand Up @@ -150,7 +150,7 @@ module FakePipe
expect(described_class.mutate('phone_ext', 'dont_care')).to match /[0-9]+/
end
end

context '#mutate_ip_v4_address' do
it 'matches proper format' do
expect((described_class.mutate('ip_v4_address', 'dont_care').split('.').map{|octet| octet.to_i}.max)).to be <= 255
Expand Down Expand Up @@ -183,17 +183,17 @@ module FakePipe

context '#mutate_digit' do
it 'matches proper format' do
expect(described_class.mutate('digit', 'dont_care')).to match /^[0-9]$/
expect(described_class.mutate('digit', 'dont_care').to_s).to match /^[0-9]$/
end
end

context '#mutate_number' do
it 'matches proper format' do
expect(described_class.mutate('number', 2)).to match /^[0-9]{2}$/
expect(described_class.mutate('number', 5)).to match /^[0-9]{5}$/
expect(described_class.mutate('number', 2).to_s).to match /^[0-9]{2}$/
expect(described_class.mutate('number', 5).to_s).to match /^[0-9]{5}$/
end
end

context '#mutate_zip_code' do
it 'matches proper format' do
expect(described_class.mutate('zip_code', 'dont_care')).to match /^[0-9]+[-]{0,1}[0-9]+$/
Expand Down Expand Up @@ -253,6 +253,18 @@ module FakePipe
expect(described_class.mutate('empty_bracket', 'dont_care')).to eq '[]'
end
end

context '#mutate_birthday' do
it 'matches proper format' do
expect(described_class.mutate('birthday', 'dont_care')).to be_a Date
end
end

context '#mutate_date' do
it 'matches proper format' do
expect(described_class.mutate('date', 'dont_care')).to be_a Date
end
end
end

context 'sad path' do
Expand Down
Loading