Skip to content

Commit

Permalink
Support Faker >1.4 (#12)
Browse files Browse the repository at this point in the history
[#166599401]
  • Loading branch information
adamstegman authored Jun 11, 2019
1 parent 015fe59 commit b39bdb7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/acts_as_scrubbable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.scrub_map
:middle_name => -> { Faker::Name.name },
:name => -> { Faker::Name.name },
:email => -> { Faker::Internet.email },
:name_title => -> { Faker::Name.title },
:name_title => -> { defined? Faker::Job ? Faker::Job.title : Faker::Name.title },
:company_name => -> { Faker::Company.name },
:street_address => -> { Faker::Address.street_address },
:secondary_address => -> { Faker::Address.secondary_address },
Expand Down
15 changes: 15 additions & 0 deletions spec/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

create_table "scrubbable_models", force: true do |t|
t.string "first_name"
t.string "last_name"
t.string "middle_name"
t.string "name"
t.string "email"
t.string "title"
t.string "company_name"
t.string "address1"
t.string "address2"
t.string "zip_code"
t.string "state"
t.string "state_short"
t.string "city"
t.string "lat"
t.string "lon"
t.string "username"
t.boolean "active"
t.string "school"
end

end
28 changes: 27 additions & 1 deletion spec/lib/acts_as_scrubbable/scrub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,35 @@
describe '.scrub' do

# update_columns cannot be run on a new record
subject{ ScrubbableModel.new }
subject { ScrubbableModel.new }
before(:each) { subject.save }

it 'scrubs all columns' do
subject.attributes = {
first_name: "Ted",
last_name: "Lowe",
middle_name: "Cassidy",
name: "Miss Vincenzo Smitham",
email: "trentdibbert@wiza.com",
title: "Internal Consultant",
company_name: "Greenfelder, Collier and Lesch",
address1: "86780 Watsica Flats",
address2: "Apt. 913",
zip_code: "49227",
state: "Ohio",
state_short: "OH",
city: "Port Hildegard",
lat: -79.5855309778974,
lon: 13.517352691513906,
username: "oscar.hermann",
active: false,
school: "Eastern Lebsack",
}
expect {
subject.scrub!
}.not_to raise_error
end

it 'changes the first_name attribute when scrub is run' do
subject.first_name = "Ted"
allow(Faker::Name).to receive(:first_name).and_return("John")
Expand Down
19 changes: 18 additions & 1 deletion spec/support/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@
class NonScrubbableModel < ActiveRecord::Base; end

class ScrubbableModel < ActiveRecord::Base
acts_as_scrubbable :first_name, :address1 => :street_address, :lat => :latitude
acts_as_scrubbable :first_name,
:last_name,
:middle_name,
:name,
:email,
:company_name,
:zip_code,
:state,
:city,
:username,
:school,
:title => :name_title,
:address1 => :street_address,
:address2 => :secondary_address,
:state_short => :state_abbr,
:lat => :latitude,
:lon => :longitude,
:active => :boolean
attr_accessor :scrubbing_begun, :scrubbing_finished
set_callback :scrub, :before do
self.scrubbing_begun = true
Expand Down

0 comments on commit b39bdb7

Please sign in to comment.