Commit 9f7c80a6f9833f62782aba81d3485cf4021733cc
Committed by
Antonio Terceiro
1 parent
417935cc
Exists in
master
and in
29 other branches
CreateEnteprise task is cancelled properly
* The validation is made only after all attributes are updated and the identifier uniqueness validation runs only if the task is not being cancelled. (ActionItem1654)
Showing
3 changed files
with
16 additions
and
2 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
@@ -16,7 +16,7 @@ class TasksController < MyProfileController | @@ -16,7 +16,7 @@ class TasksController < MyProfileController | ||
16 | decision = params[:decision] | 16 | decision = params[:decision] |
17 | if request.post? && VALID_DECISIONS.include?(decision) && params[:id] | 17 | if request.post? && VALID_DECISIONS.include?(decision) && params[:id] |
18 | task = profile.find_in_all_tasks(params[:id]) | 18 | task = profile.find_in_all_tasks(params[:id]) |
19 | - task.update_attributes!(params[:task]) | 19 | + task.update_attributes(params[:task]) |
20 | begin | 20 | begin |
21 | task.send(decision) | 21 | task.send(decision) |
22 | rescue Exception => ex | 22 | rescue Exception => ex |
app/models/create_enterprise.rb
@@ -59,7 +59,7 @@ class CreateEnterprise < Task | @@ -59,7 +59,7 @@ class CreateEnterprise < Task | ||
59 | end | 59 | end |
60 | end | 60 | end |
61 | 61 | ||
62 | - if self.identifier && Profile.exists?(:identifier => self.identifier) | 62 | + if self.status != Task::Status::CANCELLED && self.identifier && Profile.exists?(:identifier => self.identifier) |
63 | self.errors.add(:identifier, '%{fn} is already being as identifier by another enterprise, organization or person.') | 63 | self.errors.add(:identifier, '%{fn} is already being as identifier by another enterprise, organization or person.') |
64 | end | 64 | end |
65 | end | 65 | end |
test/functional/tasks_controller_test.rb
@@ -223,4 +223,18 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -223,4 +223,18 @@ class TasksControllerTest < Test::Unit::TestCase | ||
223 | assert_includes c_blog2.children(true), p_article | 223 | assert_includes c_blog2.children(true), p_article |
224 | end | 224 | end |
225 | 225 | ||
226 | + should 'cancel an enterprise registration task even if there is an enterprise with the same identifier' do | ||
227 | + e = Environment.default | ||
228 | + e.add_admin(profile) | ||
229 | + task = CreateEnterprise.create!(:name => "My Enterprise", :identifier => "my-enterprise", :requestor => profile, :target => e) | ||
230 | + enterprise = fast_create(Enterprise, :name => "My Enterprise", :identifier => "my-enterprise") | ||
231 | + | ||
232 | + assert_nothing_raised do | ||
233 | + post :close, {:profile => profile.identifier, :id => task.id, :task => {:reject_explanation => "Bla bla"}, :decision => "cancel"} | ||
234 | + end | ||
235 | + | ||
236 | + task.reload | ||
237 | + assert_equal Task::Status::CANCELLED, task.status | ||
238 | + end | ||
239 | + | ||
226 | end | 240 | end |