Skip to content

Instantly share code, notes, and snippets.

@elbartostrikesagain
Created September 20, 2013 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbartostrikesagain/6644608 to your computer and use it in GitHub Desktop.
Save elbartostrikesagain/6644608 to your computer and use it in GitHub Desktop.
attr_encrypted rspec matcher. "it {should encrypt(:column_here) }"
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