matthewtodd / has_digest

ActiveRecord macro that helps encrypt passwords and generate api tokens before_save.

This URL has Read+Write access

has_digest / shoulda_macros / has_digest.rb
812e36da » matthewtodd 2008-11-07 Quick shoulda macro. 1 module HasDigest
2 module Shoulda
4405ecbf » matthewtodd 2008-11-07 Finishing up initial docume... 3 # Asserts that the necessary database columns exist to support
4 # <tt>has_digest :name</tt> and that the necessary callback methods have
5 # been created.
695012b3 » matthewtodd 2008-11-07 Magic synthetic attributes. 6 def should_have_digest(name, options = {})
812e36da » matthewtodd 2008-11-07 Quick shoulda macro. 7 context "Class #{model_class.name} with digest #{name}" do
77e5f5aa » matthewtodd 2008-11-07 Beginning documentation, ig... 8 should_have_db_column name, :type => :string # TODO :limit => 40
812e36da » matthewtodd 2008-11-07 Quick shoulda macro. 9 should_have_instance_methods "digest_#{name}"
695012b3 » matthewtodd 2008-11-07 Magic synthetic attributes. 10
11 dependencies = options[:depends]
12 dependencies = [dependencies] unless dependencies.respond_to?(:each)
13 dependencies.compact!
14
15 dependencies.each do |dependency|
16 should_have_instance_methods "#{dependency}", "#{dependency}="
17 end
812e36da » matthewtodd 2008-11-07 Quick shoulda macro. 18 end
19 end
20 end
21 end
22
23 Test::Unit::TestCase.extend(HasDigest::Shoulda)