Help! I'm in a fix .. check it:
FactoryGirl.define do
factory :card do
number "1234123412341234"
exp_month 12
exp_year 2016
association :user
before(:create) do |instance|
# Start a crypto instance with this users public key and encrypt
crypt = Modules::Crypto.new(instance.user.encryption_key_id)
instance.number = crypt.encrypt("1234123412341234")
end
trait :unencrypted do
number "1234123412341234"
end
end
end
I'm trying to figure out how to:
Trigger a callback after the
:user
has been created, but before the:card
has been created (or the Model validations will fail since the card isn't encrypted)Make the
:unencrypted
trait override the callback above.