Created
September 20, 2013 22:12
-
-
Save elbartostrikesagain/6644608 to your computer and use it in GitHub Desktop.
attr_encrypted rspec matcher. "it {should encrypt(:column_here) }"
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
RSpec::Matchers.define :encrypt do |attribute| | |
encrypted_attribute = ('encrypted_' + attribute.to_s) | |
match do |model| | |
model.respond_to?(attribute) && model.respond_to?(encrypted_attribute.intern) && model.class.column_names.include?(encrypted_attribute) | |
end | |
failure_message_for_should do |model| | |
unless model.class.column_names.include?(encrypted_attribute) | |
"#{encrypted_attribute} must be a column on #{model.class} for encryption to work" | |
else | |
"#{attribute} should use attr_encrypted on #{model.class}" | |
end | |
end | |
failure_message_for_should_not do |model| | |
unless model.class.column_names.include?(encrypted_attribute) | |
"#{encrypted_attribute} shouldn't be a column on #{model.class}" | |
else | |
"#{attribute} should not use attr_encrypted on #{model.class}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment