From 5d49527b070d9f9215ec916bae713808b939ac6d Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 6 Jan 2009 16:21:46 -0300 Subject: [PATCH] ActionItem833: enterprise validation must ignore validation --- app/models/enterprise.rb | 2 +- app/models/profile.rb | 9 ++++++++- test/unit/enterprise_test.rb | 16 ++++++++++++++++ test/unit/profile_test.rb | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index af5fed7..3c6c338 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -74,7 +74,7 @@ class Enterprise < Organization if environment.replace_enterprise_template_when_enable apply_template(template) end - save + save_without_validation! end def question diff --git a/app/models/profile.rb b/app/models/profile.rb index d865fc8..1a84841 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -221,7 +221,14 @@ class Profile < ActiveRecord::Base def apply_template(template) copy_blocks_from(template) copy_articles_from(template) - self.update_attributes!(:layout_template => template.layout_template, :custom_footer => template[:custom_footer], :custom_header => template[:custom_header]) + + # copy interesting attributes + self.layout_template = template.layout_template + self.custom_footer = template[:custom_footer] + self.custom_header = template[:custom_header] + + # flush + self.save_without_validation! end xss_terminate :only => [ :name, :nickname, :address, :contact_phone ] diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index f50b369..73a7909 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -214,6 +214,22 @@ class EnterpriseTest < Test::Unit::TestCase end end + should 'be able to enable even if there are mandatory fields blank' do + # enterprise is created, waiting for being enabled + environment = Environment.create!(:name => 'my test environment') + enterprise = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :enabled => false, :environment => environment) + + # administrator decides now that the 'city' field is mandatory + environment.custom_enterprise_fields = { 'city' => { 'active' => 'true', 'required' => 'true' } } + environment.save! + assert_equal ['city'], environment.required_enterprise_fields + + # then we try to enable the enterprise with a required field is blank + enterprise = Enterprise.find(enterprise.id) + person = profiles(:ze) + assert enterprise.enable(person) + end + should 'list product categories full name' do full_name = mock ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 6cf5d82..657ec73 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1036,6 +1036,23 @@ class ProfileTest < Test::Unit::TestCase assert_equal 'Profile address', p.custom_footer_expanded end + should 'ignore failing validation when applying template' do + template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address', :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header') + template.save! + + p = Profile.create!(:name => 'test prof', :identifier => 'test_prof', :address => 'Profile address') + def p.validate + self.errors.add('identifier', 'is invalid') + end + + p.apply_template(template) + + p.reload + assert_equal 'leftbar', p.layout_template + assert_equal 'my custom footer', p.custom_footer + assert_equal 'my custom header', p.custom_header + end + should 'copy homepage when applying template' do template = Profile.create!(:name => 'test template', :identifier => 'test_template', :address => 'Template address') template.articles.destroy_all -- libgit2 0.21.2