Skip to content

Commit

Permalink
Only obfuscate if the instance has the field in question.
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig McNamara committed Dec 16, 2015
1 parent f563d92 commit df84c15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/polo/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def obfuscate!(instances, fields)
next if intersection(instance.attributes.keys, fields).empty?

fields.each do |field, strategy|
value = instance.attributes[field.to_s] || ''
instance.send("#{field}=", new_field_value(field, strategy, value))
if value = instance.attributes[field.to_s]
instance.send("#{field}=", new_field_value(field, strategy, value))
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/polo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@

expect(inserts).to eq [ %q{INSERT INTO "chefs" ("id", "name", "email") VALUES (1, 'Netto', 'changeme')} ]
end

it 'only scrambles instances with the obfuscate field defined' do
Polo.configure do
obfuscate :name,
email: ->(e) { "#{e.split("@")[0]}[email protected]" },
title: ->(t) { t.chars.reverse!.join }
end

exp = Polo.explore(AR::Chef, 1, :recipes)

explore_statement = exp.join(';')
expect(explore_statement).to_not match('[email protected]')
expect(explore_statement).to_not match('Netto')
end
end

describe 'on_duplicate' do
Expand Down

0 comments on commit df84c15

Please sign in to comment.