Skip to content
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
1 change: 1 addition & 0 deletions lib/strategy/whitelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def process_record(index, record)
end
end
dest_record = dest_table.new dest_record_map
dest_record.assign_attributes(dest_record_map, without_protection: true)
@primary_keys.each do |key|
dest_record[key] = record[key]
end
Expand Down
48 changes: 47 additions & 1 deletion spec/acceptance/rdbms_whitelist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,50 @@
new_rec.longitude.should be_between( -84.044636, -64.044636)

end
end

context "when whitelisting attributes" do

# This is intended to replicate what happens when
#
# config.active_record.whitelist_attributes = true
#
# is set in your application.

default_active_authorizer = nil

before(:each) do
default_active_authorizer = ActiveRecord::Base.active_authorizers[:default]
ActiveRecord::Base.active_authorizers[:default] = ActiveModel::MassAssignmentSecurity::WhiteList.new
end

after(:each) do
ActiveRecord::Base.active_authorizers[:default] = default_active_authorizer
end

it "should copy the customer table data" do

database "Customer" do
strategy DataAnon::Strategy::Whitelist
source_db source_connection_spec
destination_db dest_connection_spec

table 'customers' do
whitelist 'cust_id', 'address', 'zipcode', 'blog_url'
anonymize('first_name').using FieldStrategy::RandomFirstName.new
anonymize('last_name').using FieldStrategy::RandomLastName.new
anonymize('state').using FieldStrategy::SelectFromList.new(['Gujrat','Karnataka'])
anonymize('phone').using FieldStrategy::RandomPhoneNumber.new
anonymize('email').using FieldStrategy::StringTemplate.new('test+#{row_number}@gmail.com')
anonymize 'terms_n_condition', 'age', 'longitude'
anonymize('latitude').using FieldStrategy::RandomFloatDelta.new(2.0)
whitelist 'created_at','updated_at'
end
end

DataAnon::Utils::DestinationDatabase.establish_connection dest_connection_spec
dest_table = DataAnon::Utils::DestinationTable.create 'customers'
new_rec = dest_table.all.first
new_rec.address.should == 'F 501 Shanti Nagar'
end
end
end