Created
October 9, 2013 03:18
-
-
Save samnang/6895674 to your computer and use it in GitHub Desktop.
Migration RSpec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require File.expand_path('../../../db/migrate/20130910173340_decrypt_case_identifiers', __FILE__) | |
describe 'Case identifiers decryption migration' do | |
subject(:migration) { DecryptCaseIdentifiers.new } | |
describe ".up" do | |
it "decrypts identifier of each case" do | |
cases = create_list(:case, 2) | |
cases[0].update_column(:identifier, encrypt('12345')) | |
cases[1].update_column(:identifier, encrypt('abcde')) | |
migration.up | |
expect(cases[0].reload.identifier).to eq('12345') | |
expect(cases[1].reload.identifier).to eq('abcde') | |
end | |
end | |
describe ".down" do | |
it "encrypts identifier of each case" do | |
cases = create_list(:case, 2) | |
cases[0].update_column(:identifier, '12345') | |
cases[1].update_column(:identifier, 'abcde') | |
migration.down | |
expect(cases[0].reload.identifier).to eq(encrypt('12345')) | |
expect(cases[1].reload.identifier).to eq(encrypt('abcde')) | |
end | |
end | |
def encrypt(val) | |
Base64.encode64(val.encrypt) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment