Commit b520bd1f540df9838a68aa68bfafd2fcbd1ce75f
1 parent
de765b0f
Exists in
master
and in
22 other branches
ActionItem16: requiring a explanation for rejecting an enterprise.
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@868 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
20 additions
and
1 deletions
Show diff stats
app/models/create_enterprise.rb
... | ... | @@ -11,7 +11,7 @@ class CreateEnterprise < Task |
11 | 11 | N_('CreateEnterprise|Economic activity') |
12 | 12 | N_('CreateEnterprise|Management information') |
13 | 13 | |
14 | - DATA_FIELDS = %w[ name identifier address contact_phone contact_person acronym foundation_year legal_form economic_activity management_information region_id ] | |
14 | + DATA_FIELDS = %w[ name identifier address contact_phone contact_person acronym foundation_year legal_form economic_activity management_information region_id reject_explanation ] | |
15 | 15 | |
16 | 16 | serialize :data, Hash |
17 | 17 | attr_protected :data |
... | ... | @@ -37,6 +37,9 @@ class CreateEnterprise < Task |
37 | 37 | # checks for actual attributes |
38 | 38 | validates_presence_of :requestor_id, :target_id |
39 | 39 | |
40 | + # check for explanation when rejecting | |
41 | + validates_presence_of :reject_explanation, :if => (lambda { |record| record.status == Task::Status::CANCELLED } ) | |
42 | + | |
40 | 43 | def validate |
41 | 44 | if self.region && self.target |
42 | 45 | unless self.region.validators.include?(self.target) | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -69,6 +69,22 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
69 | 69 | task.reject |
70 | 70 | end |
71 | 71 | |
72 | + should 'require an explanation for rejecting enterprise creation' do | |
73 | + task = CreateEnterprise.new | |
74 | + task.reject_explanation = nil | |
75 | + | |
76 | + task.valid? | |
77 | + assert !task.errors.invalid?(:reject_explanation) | |
78 | + | |
79 | + task.status = Task::Status::CANCELLED | |
80 | + task.valid? | |
81 | + assert task.errors.invalid?(:reject_explanation) | |
82 | + | |
83 | + task.reject_explanation = 'bla bla bla' | |
84 | + task.valid? | |
85 | + assert !task.errors.invalid?(:reject_explanation) | |
86 | + end | |
87 | + | |
72 | 88 | should 'finish task when approved' do |
73 | 89 | task = CreateEnterprise.new |
74 | 90 | task.expects(:finish) | ... | ... |