Commit 9f32ff062320f7004cf448cea0f9b5b13e33e48c
1 parent
a3816174
Exists in
master
and in
28 other branches
ActionItem172: not calling unexisting methods
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1550 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
42 additions
and
21 deletions
Show diff stats
app/models/organization.rb
... | ... | @@ -6,6 +6,8 @@ class Organization < Profile |
6 | 6 | |
7 | 7 | has_one :validation_info |
8 | 8 | |
9 | + has_many :validations, :class_name => 'CreateEnterprise', :foreign_key => :target_id | |
10 | + | |
9 | 11 | after_create do |org| |
10 | 12 | OrganizationInfo.create!(:organization_id => org.id) |
11 | 13 | end |
... | ... | @@ -23,19 +25,19 @@ class Organization < Profile |
23 | 25 | end |
24 | 26 | |
25 | 27 | def pending_validations |
26 | - CreateEnterprise.pending_for(self) | |
28 | + validations.pending | |
27 | 29 | end |
28 | 30 | |
29 | 31 | def find_pending_validation(code) |
30 | - CreateEnterprise.pending_for(self, :code => code).first | |
32 | + validations.pending.find { |pending| pending.code == code } | |
31 | 33 | end |
32 | 34 | |
33 | 35 | def processed_validations |
34 | - CreateEnterprise.processed_for(self) | |
36 | + validations.finished | |
35 | 37 | end |
36 | 38 | |
37 | 39 | def find_processed_validation(code) |
38 | - CreateEnterprise.processed_for(self, :code => code).first | |
40 | + validations.finished.find { |pending| pending.code == code } | |
39 | 41 | end |
40 | 42 | |
41 | 43 | def is_validation_entity? | ... | ... |
test/unit/organization_test.rb
... | ... | @@ -3,6 +3,28 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class OrganizationTest < Test::Unit::TestCase |
4 | 4 | fixtures :profiles |
5 | 5 | |
6 | + def create_create_enterprise(org) | |
7 | + region = Region.create!(:name => 'some region', :environment => Environment.default) | |
8 | + region.validators << org | |
9 | + | |
10 | + requestor = create_user('testreq').person | |
11 | + | |
12 | + data = { | |
13 | + :name => 'My new enterprise', | |
14 | + :identifier => 'mynewenterprise', | |
15 | + :address => 'satan street, 666', | |
16 | + :contact_phone => '1298372198', | |
17 | + :contact_person => 'random joe', | |
18 | + :legal_form => 'cooperative', | |
19 | + :economic_activity => 'free software', | |
20 | + :region_id => region.id, | |
21 | + :requestor => requestor, | |
22 | + :target => org, | |
23 | + } | |
24 | + CreateEnterprise.create!(data) | |
25 | + end | |
26 | + | |
27 | + | |
6 | 28 | should 'reference organization info' do |
7 | 29 | org = Organization.new |
8 | 30 | assert_raise ActiveRecord::AssociationTypeMismatch do |
... | ... | @@ -62,36 +84,33 @@ class OrganizationTest < Test::Unit::TestCase |
62 | 84 | |
63 | 85 | should 'list pending enterprise validations' do |
64 | 86 | org = Organization.new |
65 | - empty = [] | |
66 | - CreateEnterprise.expects(:pending_for).with(org).returns(empty) | |
67 | - assert_same empty, org.pending_validations | |
87 | + assert_kind_of Array, org.pending_validations | |
68 | 88 | end |
69 | 89 | |
70 | 90 | should 'be able to find a pending validation by its code' do |
71 | - org = Organization.new | |
72 | - validation = mock | |
73 | - CreateEnterprise.expects(:pending_for).with(org, { :code => 'lele'}).returns([validation]) | |
74 | - assert_same validation, org.find_pending_validation('lele') | |
91 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | |
92 | + | |
93 | + validation = create_create_enterprise(org) | |
94 | + | |
95 | + ok('should find pending validation by code') { validation == org.find_pending_validation(validation.code) } | |
75 | 96 | end |
76 | 97 | |
77 | 98 | should 'return nil when finding for an unexisting pending validation' do |
78 | 99 | org = Organization.new |
79 | - CreateEnterprise.expects(:pending_for).with(org, { :code => 'lele'}).returns([]) | |
80 | - assert_nil org.find_pending_validation('lele') | |
100 | + assert_nil org.find_pending_validation('xxxxxxxxxxxxxxxxxxx') | |
81 | 101 | end |
82 | 102 | |
83 | - should 'be able to find already processed validations by target' do | |
103 | + should 'be able to find already processed validations' do | |
84 | 104 | org = Organization.new |
85 | - empty = mock | |
86 | - CreateEnterprise.expects(:processed_for).with(org).returns(empty) | |
87 | - assert_same empty, org.processed_validations | |
105 | + assert_kind_of Array, org.processed_validations | |
88 | 106 | end |
89 | 107 | |
90 | 108 | should 'be able to find an already processed validation by its code' do |
91 | - org = Organization.new | |
92 | - empty = mock | |
93 | - CreateEnterprise.expects(:processed_for).with(org, {:code => 'lalalala'}).returns([empty]) | |
94 | - assert_same empty, org.find_processed_validation('lalalala') | |
109 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg') | |
110 | + validation = create_create_enterprise(org) | |
111 | + validation.finish | |
112 | + | |
113 | + ok('should find processed validation by code') { validation == org.find_processed_validation(validation.code) } | |
95 | 114 | end |
96 | 115 | |
97 | 116 | should 'have boxes and blocks upon creation' do | ... | ... |