Commit 2638f65f2ccb4ec2a4108b124e06c2c61e03c4e6
1 parent
3d5b4650
Exists in
master
and in
22 other branches
rails3: fix create_enterprise tests
PS: still failing due to mailer deliver problem.
Showing
2 changed files
with
9 additions
and
5 deletions
Show diff stats
app/models/create_enterprise.rb
@@ -36,14 +36,18 @@ class CreateEnterprise < Task | @@ -36,14 +36,18 @@ class CreateEnterprise < Task | ||
36 | validates_presence_of :reject_explanation, :if => (lambda { |record| record.status == Task::Status::CANCELLED } ) | 36 | validates_presence_of :reject_explanation, :if => (lambda { |record| record.status == Task::Status::CANCELLED } ) |
37 | xss_terminate :only => [ :acronym, :address, :contact_person, :contact_phone, :economic_activity, :legal_form, :management_information, :name ], :on => 'validation' | 37 | xss_terminate :only => [ :acronym, :address, :contact_person, :contact_phone, :economic_activity, :legal_form, :management_information, :name ], :on => 'validation' |
38 | 38 | ||
39 | - def validate | 39 | + validate :validator_correct_region |
40 | + validate :not_used_identifier | ||
40 | 41 | ||
42 | + def validator_correct_region | ||
41 | if self.region && self.target | 43 | if self.region && self.target |
42 | unless self.region.validators.include?(self.target) || self.target_type == "Environment" | 44 | unless self.region.validators.include?(self.target) || self.target_type == "Environment" |
43 | self.errors.add(:target, _('%{fn} is not a validator for the chosen region').fix_i18n) | 45 | self.errors.add(:target, _('%{fn} is not a validator for the chosen region').fix_i18n) |
44 | end | 46 | end |
45 | end | 47 | end |
48 | + end | ||
46 | 49 | ||
50 | + def not_used_identifier | ||
47 | if self.status != Task::Status::CANCELLED && self.identifier && Profile.exists?(:identifier => self.identifier) | 51 | if self.status != Task::Status::CANCELLED && self.identifier && Profile.exists?(:identifier => self.identifier) |
48 | self.errors.add(:identifier, _('%{fn} is already being as identifier by another enterprise, organization or person.').fix_i18n) | 52 | self.errors.add(:identifier, _('%{fn} is already being as identifier by another enterprise, organization or person.').fix_i18n) |
49 | end | 53 | end |
test/unit/create_enterprise_test.rb
@@ -232,11 +232,11 @@ class CreateEnterpriseTest < ActiveSupport::TestCase | @@ -232,11 +232,11 @@ class CreateEnterpriseTest < ActiveSupport::TestCase | ||
232 | request.stubs(:environment).returns(Environment.default) | 232 | request.stubs(:environment).returns(Environment.default) |
233 | request.identifier = 'testid' | 233 | request.identifier = 'testid' |
234 | request.valid? | 234 | request.valid? |
235 | - assert !request.errors[:identifier.to_s].present? | 235 | + assert request.errors[:identifier].blank? |
236 | 236 | ||
237 | Organization.create!(:name => 'test', :identifier => 'testid') | 237 | Organization.create!(:name => 'test', :identifier => 'testid') |
238 | request.valid? | 238 | request.valid? |
239 | - assert request.errors[:identifier.to_s].present? | 239 | + assert request.errors[:identifier].present? |
240 | end | 240 | end |
241 | 241 | ||
242 | should 'require the same fields as an enterprise does' do | 242 | should 'require the same fields as an enterprise does' do |
@@ -247,11 +247,11 @@ class CreateEnterpriseTest < ActiveSupport::TestCase | @@ -247,11 +247,11 @@ class CreateEnterpriseTest < ActiveSupport::TestCase | ||
247 | 247 | ||
248 | environment.stubs(:required_enterprise_fields).returns([]) | 248 | environment.stubs(:required_enterprise_fields).returns([]) |
249 | request.valid? | 249 | request.valid? |
250 | - assert_nil request.errors[:contact_person], 'should not require contact_person unless Enterprise requires it' | 250 | + assert request.errors[:contact_person].blank?, 'should not require contact_person unless Enterprise requires it' |
251 | 251 | ||
252 | environment.stubs(:required_enterprise_fields).returns(['contact_person']) | 252 | environment.stubs(:required_enterprise_fields).returns(['contact_person']) |
253 | request.valid? | 253 | request.valid? |
254 | - assert_not_nil request.errors[:contact_person], 'should require contact_person when Enterprise requires it' | 254 | + assert request.errors[:contact_person].present?, 'should require contact_person when Enterprise requires it' |
255 | end | 255 | end |
256 | 256 | ||
257 | should 'has permission to validate enterprise' do | 257 | should 'has permission to validate enterprise' do |