public
Description: ActiveRecord macro that helps encrypt passwords and generate api tokens before_save.
Homepage:
Clone URL: git://github.com/matthewtodd/has_digest.git
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 = {})
f23993ec » matthewtodd 2008-11-07 Working on shoulda macro. 7 options.assert_valid_keys(:depends)
8
5c5d75e0 » matthewtodd 2008-11-08 Just register the digests i... 9 context "#{model_class.name} with has_digest :#{name}" do
f23993ec » matthewtodd 2008-11-07 Working on shoulda macro. 10 should_have_db_column name, :type => :string, :limit => 40
5c5d75e0 » matthewtodd 2008-11-08 Just register the digests i... 11
12 should "generate digest for :#{name}" do
13 assert_not_nil model_class.has_digest_attributes[name]
14 end
695012b3 » matthewtodd 2008-11-07 Magic synthetic attributes. 15
f23993ec » matthewtodd 2008-11-07 Working on shoulda macro. 16 if options[:depends]
17 dependencies = options[:depends]
18 dependencies = [dependencies] unless dependencies.respond_to?(:each)
5c5d75e0 » matthewtodd 2008-11-08 Just register the digests i... 19 dependencies.unshift(:salt) if model_class.column_names.include?('salt')
695012b3 » matthewtodd 2008-11-07 Magic synthetic attributes. 20
5c5d75e0 » matthewtodd 2008-11-08 Just register the digests i... 21 should "generate digest for :#{name} from #{dependencies.to_sentence}" do
22 attributes = model_class.has_digest_attributes[name] || {}
23 assert_equal dependencies, attributes[:dependencies]
f23993ec » matthewtodd 2008-11-07 Working on shoulda macro. 24 end
695012b3 » matthewtodd 2008-11-07 Magic synthetic attributes. 25 end
812e36da » matthewtodd 2008-11-07 Quick shoulda macro. 26 end
27 end
28 end
29 end
30
31 Test::Unit::TestCase.extend(HasDigest::Shoulda)