Commit 51f9397d8ad680f1b72eb2d9571f308701d11f2c

Authored by AntonioTerceiro
1 parent 60581e64

ActionItem16: changing interface to find pending validation by code



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@864 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/organization.rb
... ... @@ -24,7 +24,12 @@ class Organization < Profile
24 24 restrictions || ('<em>' + _('(not informed)') + '</em>')
25 25 end
26 26  
27   - def pending_validations(conditions = nil)
28   - CreateEnterprise.pending_for(self, conditions)
  27 + def pending_validations
  28 + CreateEnterprise.pending_for(self)
29 29 end
  30 +
  31 + def find_pending_validation(code)
  32 + CreateEnterprise.pending_for(self, :code => code).first
  33 + end
  34 +
30 35 end
... ...
test/unit/organization_test.rb
... ... @@ -62,14 +62,22 @@ class OrganizationTest &lt; Test::Unit::TestCase
62 62  
63 63 should 'list pending enterprise validations' do
64 64 org = Organization.new
65   - CreateEnterprise.expects(:pending_for).with(org, nil).returns([])
66   - assert_equal [], org.pending_validations
  65 + empty = []
  66 + CreateEnterprise.expects(:pending_for).with(org).returns(empty)
  67 + assert_same empty, org.pending_validations
67 68 end
68 69  
69   - should 'accept an optional conditions hash for pending_validations' do
  70 + should 'be able to find a pending validation by its code' do
70 71 org = Organization.new
71   - CreateEnterprise.expects(:pending_for).with(org, { :lala => 'lele'}).returns([])
72   - assert_equal [], org.pending_validations({ :lala => 'lele'})
  72 + validation = mock
  73 + CreateEnterprise.expects(:pending_for).with(org, { :code => 'lele'}).returns([validation])
  74 + assert_same validation, org.find_pending_validation('lele')
  75 + end
  76 +
  77 + should 'return nil when finding for an unexisting pending validation' do
  78 + org = Organization.new
  79 + CreateEnterprise.expects(:pending_for).with(org, { :code => 'lele'}).returns([])
  80 + assert_nil org.find_pending_validation('lele')
73 81 end
74 82  
75 83 end
... ...