Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@samnang
Created October 9, 2013 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samnang/6895674 to your computer and use it in GitHub Desktop.
Save samnang/6895674 to your computer and use it in GitHub Desktop.
Migration RSpec
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