Commit d8c8e9cf0cfeb75c8549f966410a36e0cee671a8

Authored by Rodrigo Souto
1 parent f0f667bb

enterprise-registration: fail-safe improvement; region= can receive region or id

Showing 1 changed file with 7 additions and 1 deletions   Show diff stats
app/models/create_enterprise.rb
@@ -73,7 +73,13 @@ class CreateEnterprise < Task @@ -73,7 +73,13 @@ class CreateEnterprise < Task
73 73
74 # sets the associated region for the enterprise creation 74 # sets the associated region for the enterprise creation
75 def region=(value) 75 def region=(value)
76 - raise ArgumentError.new("Region expected, but got #{value.class}") unless value.kind_of?(Region) 76 + unless value.kind_of?(Region)
  77 + begin
  78 + value = Region.find(value)
  79 + rescue
  80 + raise ArgumentError.new("Could not find any region with the id #{value}")
  81 + end
  82 + end
77 83
78 @region = value 84 @region = value
79 self.region_id = value.id 85 self.region_id = value.id