don't create the default section in search_helper

test plan:
 - Create a course via SIS import or Accounts page
   (not via front page, since this will enroll you as a teacher)
 - Go to the settings page for the created course and verify
   no sections were created

fixes CNVS-10683

Change-Id: I4ee7296cf45b44335a5fc49d701951e079800b20
Reviewed-on: https://gerrit.instructure.com/29189
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
Product-Review: Bracken Mosbacker <bracken@instructure.com>
QA-Review: Nathan Rogowski <nathan@instructure.com>
This commit is contained in:
Jeremy Stanley 2014-01-23 10:16:28 -07:00
parent d6592241a3
commit 4cb084d4b7
3 changed files with 17 additions and 2 deletions

View File

@ -44,7 +44,7 @@ module SearchHelper
:state => type == :current ? :active : (course.recently_ended? ? :recently_active : :inactive),
:available => type == :current && course.available?,
:permissions => course.grants_rights?(@current_user),
:default_section_id => course.default_section.id
:default_section_id => course.default_section(no_create: true).try(:id)
}
end
end

View File

@ -1726,7 +1726,7 @@ class Course < ActiveRecord::Base
if !section && opts[:include_xlists]
section = CourseSection.active.where(:nonxlist_course_id => self).order(:id).first
end
if !section
if !section && !opts[:no_create]
section = course_sections.build
section.default_section = true
section.course = self

View File

@ -3765,3 +3765,18 @@ describe Course, "multiple_sections?" do
@course.multiple_sections?.should be_true
end
end
describe Course, "default_section" do
it "should create the default section" do
c = Course.create!
s = c.default_section
c.course_sections.pluck(:id).should eql [s.id]
end
it "unless we ask it not to" do
c = Course.create!
s = c.default_section(no_create: true)
s.should be_nil
c.course_sections.pluck(:id).should be_empty
end
end