diff --git a/app/models/account.rb b/app/models/account.rb index db4092733f0..ea5bceda76f 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -72,6 +72,7 @@ class Account < ActiveRecord::Base before_save :ensure_defaults before_save :set_update_account_associations_if_changed after_save :update_account_associations_if_changed + after_create :default_enrollment_term serialize :settings, Hash @@ -474,7 +475,9 @@ class Account < ActiveRecord::Base end def default_enrollment_term - self.enrollment_terms.active.find_or_create_by_name("Default Term") + unless self.root_account_id + self.enrollment_terms.active.find_or_create_by_name("Default Term") + end end def add_admin(args) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index fcbc8d828e5..5a262a62f4d 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -109,5 +109,15 @@ describe Account do a.turnitin_shared_secret.should eql("2t87aot72gho8a37gh4g[awg'waegawe-,v-3o7fya23oya2o3") end end - + + it "should make a default enrollment term if necessary" do + a = Account.create!(:name => "nada") + a.enrollment_terms.size.should == 1 + a.enrollment_terms.first.name.should == "Default Term" + + # don't create a new default term for sub-accounts + a2 = a.all_accounts.create!(:name => "sub") + a2.enrollment_terms.size.should == 0 + end + end