diff --git a/spec/selenium/grading_periods_spec.rb b/spec/selenium/grading_periods_spec.rb index 43583d9f877..9704ec98c9a 100644 --- a/spec/selenium/grading_periods_spec.rb +++ b/spec/selenium/grading_periods_spec.rb @@ -10,8 +10,7 @@ describe "grading periods" do context "with Multiple Grading Periods feature on" do before(:each) do - @course.root_account.allow_feature!(:multiple_grading_periods) - @course.account.enable_feature!(:multiple_grading_periods) + @course.root_account.enable_feature!(:multiple_grading_periods) end it "should contain a tab for grading periods" do @@ -19,35 +18,25 @@ describe "grading periods" do expect(f(".grading_periods_tab")).to be_displayed end - it "should show grading periods created at the Course-level" do - grading_period_group = @course.grading_period_groups.create! - grading_period = grading_period_group.grading_periods.create!(title: "Course-level grading period", - start_date: Time.zone.now, - end_date: 30.days.from_now) + it "should show grading periods created at the course-level" do + course_grading_period = create_grading_periods_for(@course).first get "/courses/#{@course.id}/grading_standards" - expect(f("#period_title_#{grading_period.id}").attribute("value")).to eq("Course-level grading period") + expect(f("#period_title_#{course_grading_period.id}").attribute("value")).to eq(course_grading_period.title) end - it "should show grading periods created by an associated Account" do + it "should show grading periods created by an associated account" do pending("this test marked as pending until the grading periods API - is changed to return grading periods created at the Account + is changed to return grading periods created at the account level for a given course (in addition to returning grading periods - created at the Course level") - grading_period_group = @course.root_account.grading_period_groups.create! - grading_period = grading_period_group.grading_periods.create!(title: "Account-level grading period", - start_date: Time.zone.now, - end_date: 30.days.from_now) + created at the course level") + account_grading_period = create_grading_periods_for(@course.root_account).first get "/courses/#{@course.id}/grading_standards" - expect(f("#period_title_#{grading_period.id}").attribute("value")).to eq("Account-level grading period") + expect(f("#period_title_#{account_grading_period.id}").attribute("value")).to eq(account_grading_period.title) end it "should allow grading periods to be deleted" do grading_period_selector = '.grading-period' - grading_period_group = @course.grading_period_groups.create! - grading_period = grading_period_group.grading_periods.create!(title: "Delete me, please!", - start_date: Time.zone.now, - end_date: 30.days.from_now, - weight: 1) + create_grading_periods_for(@course) get "/courses/#{@course.id}/grading_standards" expect(ff(grading_period_selector).length).to be 1 @@ -74,8 +63,7 @@ describe "grading periods" do context "with Multiple Grading Periods feature on" do before(:each) do - @account.allow_feature!(:multiple_grading_periods) - @course.account.enable_feature!(:multiple_grading_periods) + @account.enable_feature!(:multiple_grading_periods) end it "should contain a tab for grading periods" do @@ -83,22 +71,16 @@ describe "grading periods" do expect(f(".grading_periods_tab")).to be_displayed end - it "should show grading periods created at the Account-level" do - grading_period_group = @account.grading_period_groups.create! - grading_period = grading_period_group.grading_periods.create!(title: "Account-level grading period", - start_date: Time.zone.now, - end_date: 30.days.from_now) + it "should show grading periods created at the account-level" do + account_grading_period = create_grading_periods_for(@account).first get "/accounts/#{@account.id}/grading_standards" - expect(f("#period_title_#{grading_period.id}").attribute("value")).to eq("Account-level grading period") + expect(f("#period_title_#{account_grading_period.id}").attribute("value")).to eq(account_grading_period.title) end - it "should NOT show grading periods created by Courses under this account" do - grading_period_group = @course.grading_period_groups.create! - grading_period = grading_period_group.grading_periods.create!(title: "Course-level grading period", - start_date: Time.zone.now, - end_date: 30.days.from_now) + it "should NOT show grading periods created by courses under this account" do + course_grading_period = create_grading_periods_for(@course).first get "/accounts/#{@account.id}/grading_standards" - expect(f("#period_title_#{grading_period.id}")).to be_nil + expect(f("#period_title_#{course_grading_period.id}")).to be_nil end end diff --git a/spec/selenium/helpers/gradebook2_common.rb b/spec/selenium/helpers/gradebook2_common.rb index 041de07819a..fa69a1468c4 100644 --- a/spec/selenium/helpers/gradebook2_common.rb +++ b/spec/selenium/helpers/gradebook2_common.rb @@ -102,9 +102,9 @@ def conclude_and_unconclude_course @course.reload end -def gradebook_data_setup +def gradebook_data_setup(opts={}) assignment_setup_defaults - assignment_setup + assignment_setup(opts) end def data_setup_as_observer @@ -135,8 +135,8 @@ def assignment_setup_defaults @default_password = "qwerty" end -def assignment_setup - course_with_teacher_logged_in +def assignment_setup(opts={}) + course_with_teacher_logged_in(opts) @course.grading_standard_enabled = true @course.save! @course.reload diff --git a/spec/selenium/multiple_grading_periods_spec.rb b/spec/selenium/multiple_grading_periods_spec.rb index cc6b291103e..ce15f1c5402 100644 --- a/spec/selenium/multiple_grading_periods_spec.rb +++ b/spec/selenium/multiple_grading_periods_spec.rb @@ -4,41 +4,31 @@ require File.expand_path(File.dirname(__FILE__) + '/helpers/gradebook2_common') describe "interaction with multiple grading periods" do include_examples "in-process server selenium tests" - def set_up_multiple_grading_periods - @course.account.enable_feature!(:multiple_grading_periods) - @group1 = @course.assignment_groups.create!(name: 'group1', postion: 10, group_weight: 40) - @group2 = @course.assignment_groups.create!(name: 'group2', postion: 7, group_weight: 60) - @course.assignments.create!(assignment_group: @group1, due_at: Time.now) - @course.assignments.create!(assignment_group: @group1, due_at: 3.months.from_now) - @course.assignments.create!(assignment_group: @group2, due_at: Time.now) - gpg = @course.grading_period_groups.create! - @gp1 = gpg.grading_periods.create!(title: "Today", workflow_state: "active", start_date: 1.month.ago, end_date: 1.month.from_now) - @gp2 = gpg.grading_periods.create!(title: "Future", workflow_state: "active", start_date: 2.months.from_now, end_date: 4.months.from_now) - end - - context "gradebook" do - before :each do - gradebook_data_setup - set_up_multiple_grading_periods + gradebook_data_setup(grading_periods: [:future, :current]) end it "should display the correct grading period based on the GET param" do - get "/courses/#{@course.id}/gradebook?grading_period_id=#{@gp2.id}" - expect(f('.grading-period-select-button')).to include_text(@gp2.title) + future_grading_period = @course.grading_periods.first + get "/courses/#{@course.id}/gradebook?grading_period_id=#{future_grading_period.id}" + expect(f('.grading-period-select-button')).to include_text(future_grading_period.title) end - it "should display All Grading Periods with a 0 GET param" do + it "should not display All Grading Periods when a grading period id is provided" do + get "/courses/#{@course.id}/gradebook?grading_period_id=2" + expect(f('.grading-period-select-button')).to_not be_present + end + + it "should display All Grading Periods when grading period id is set to 0" do get "/courses/#{@course.id}/gradebook?grading_period_id=0" expect(f('.grading-period-select-button')).to include_text("All Grading Periods") end it "should display the current grading period without a GET param" do + current_grading_period = @course.grading_periods.second get "/courses/#{@course.id}/gradebook" - expect(f('.grading-period-select-button')).to include_text(@gp1.title) + expect(f('.grading-period-select-button')).to include_text(current_grading_period.title) end end - - -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 559af7b9f75..3e1d9c9a642 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -477,10 +477,35 @@ RSpec.configure do |config| account.allow_feature!(:differentiated_assignments) @course.enable_feature!(:differentiated_assignments) end + create_grading_periods_for(@course, opts) if opts[:grading_periods] end @course end + def create_grading_periods_for(context, opts={}) + opts = { mgp_flag_enabled: true }.merge(opts) + context.root_account = Account.default if !context.root_account + context.root_account.enable_feature!(:multiple_grading_periods) if opts[:mgp_flag_enabled] + gp_group = context.grading_period_groups.create! + class_name = context.class.name.demodulize + periods = opts[:grading_periods] || [:current] + periods.each.with_index(1) do |timeframe, index| + cutoff_dates = { + current: { start_date: index.months.ago, + end_date: index.months.from_now }, + old: { start_date: (index + 1).months.ago, + end_date: index.months.ago }, + future: { start_date: index.months.from_now, + end_date: (index + 1).months.from_now } + } + period_params = cutoff_dates[timeframe].merge(title: "#{class_name} Period #{index}: #{timeframe} period") + new_period = gp_group.grading_periods.create!(period_params) + new_period[:workflow_state] = 'active' + new_period.save! + end + gp_group.grading_periods + end + def account_with_role_changes(opts={}) account = opts[:account] || Account.default if opts[:role_changes] @@ -501,8 +526,10 @@ RSpec.configure do |config| account_admin_user(opts) end - def account_admin_user(opts={:active_user => true}) + def account_admin_user(opts={}) + opts = { active_user: true }.merge(opts) account = opts[:account] || Account.default + create_grading_periods_for(account, opts) if opts[:grading_periods] @user = opts[:user] || account.shard.activate { user(opts) } @admin = @user