This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
has_digest / shoulda_macros / has_digest.rb
| 812e36da » | matthewtodd | 2008-11-07 | 1 | module HasDigest | |
| 2 | module Shoulda | ||||
| ef24ee9f » | matthewtodd | 2008-11-08 | 3 | # Asserts that <tt>has_digest :name</tt> has been called with the given | |
| 457e783d » | matthewtodd | 2008-11-09 | 4 | # options, and that the necessary database columns are present. +options+ | |
| 5 | # may contain two keys: | ||||
| 6 | # * +depends+: either a single attribute name or an array of attribtues | ||||
| 7 | # names. (Specifying <tt>:salt</tt> here is unnecessary.) | ||||
| 8 | # * +limit+: if your db column for the given digest doesn't have | ||||
| 9 | # <tt>:limit => 40</tt>, you may specify its size here. | ||||
| 695012b3 » | matthewtodd | 2008-11-07 | 10 | def should_have_digest(name, options = {}) | |
| 457e783d » | matthewtodd | 2008-11-09 | 11 | options.assert_valid_keys(:depends, :limit) | |
| f23993ec » | matthewtodd | 2008-11-07 | 12 | ||
| 700d10bd » | matthewtodd | 2009-09-02 | 13 | context "#{described_type.name} with has_digest :#{name}" do | |
| 457e783d » | matthewtodd | 2008-11-09 | 14 | should_have_db_column name, :type => :string, :limit => (options[:limit] || 40) | |
| 5c5d75e0 » | matthewtodd | 2008-11-08 | 15 | ||
| 16 | should "generate digest for :#{name}" do | ||||
| 700d10bd » | matthewtodd | 2009-09-02 | 17 | assert_not_nil self.class.described_type.has_digest_attributes[name] | |
| 5c5d75e0 » | matthewtodd | 2008-11-08 | 18 | end | |
| 695012b3 » | matthewtodd | 2008-11-07 | 19 | ||
| f23993ec » | matthewtodd | 2008-11-07 | 20 | if options[:depends] | |
| 21 | dependencies = options[:depends] | ||||
| 22 | dependencies = [dependencies] unless dependencies.respond_to?(:each) | ||||
| 700d10bd » | matthewtodd | 2009-09-02 | 23 | dependencies.unshift(:salt) if described_type.column_names.include?('salt') | |
| 695012b3 » | matthewtodd | 2008-11-07 | 24 | ||
| 5c5d75e0 » | matthewtodd | 2008-11-08 | 25 | should "generate digest for :#{name} from #{dependencies.to_sentence}" do | |
| 700d10bd » | matthewtodd | 2009-09-02 | 26 | attributes = self.class.described_type.has_digest_attributes[name] || {} | |
| 5c5d75e0 » | matthewtodd | 2008-11-08 | 27 | assert_equal dependencies, attributes[:dependencies] | |
| f23993ec » | matthewtodd | 2008-11-07 | 28 | end | |
| 695012b3 » | matthewtodd | 2008-11-07 | 29 | end | |
| 812e36da » | matthewtodd | 2008-11-07 | 30 | end | |
| 31 | end | ||||
| 32 | end | ||||
| 33 | end | ||||
| 34 | |||||
| 35 | Test::Unit::TestCase.extend(HasDigest::Shoulda) | ||||







