canvas-lms/spec/integration/context_module_spec.rb

201 lines
7.8 KiB
Ruby
Raw Normal View History

#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe ContextModule do
def course_module
course_with_student_logged_in
@module = @course.context_modules.create!(:name => "some module")
end
it "should clear the page cache on individual tag change" do
enable_cache do
course_with_teacher_logged_in(:active_all => true)
context_module = @course.context_modules.create!
content_tag = context_module.add_item :type => 'context_module_sub_header', :title => "My Sub Header Title"
ContextModule.where(:id => context_module).update_all(:updated_at => 1.hour.ago)
get "/courses/#{@course.id}/modules"
response.body.should match(/My Sub Header Title/)
content_tag.update_attributes(:title => "My New Title")
get "/courses/#{@course.id}/modules"
response.body.should match(/My New Title/)
end
end
describe "must_contribute" do
before do
course_module
@module.require_sequential_progress = true
@module.save!
end
def before_after
@module.completion_requirements = { @tag.id => { :type => 'must_contribute' } }
@module.save!
@progression = @module.evaluate_for(@user, true, true)
@progression.should_not be_nil
@progression.should_not be_completed
@progression.should be_unlocked
@progression.current_position.should eql(@tag.position)
yield
@progression = @module.evaluate_for(@user, true, true)
@progression.should be_completed
@progression.current_position.should eql(@tag.position)
end
it "should progress for discussions" do
@discussion = @course.discussion_topics.create!(:title => "talk")
@tag = @module.add_item(:type => 'discussion_topic', :id => @discussion.id)
before_after do
post "/courses/#{@course.id}/discussion_entries", :discussion_entry => { :message => 'ohai', :discussion_topic_id => @discussion.id }
response.should be_redirect
end
end
it "should progress for wiki pages" do
@page = @course.wiki.wiki_pages.create!(:title => "talk page", :body => 'ohai', :editing_roles => 'teachers,students')
@tag = @module.add_item(:type => 'wiki_page', :id => @page.id)
before_after do
put "/courses/#{@course.id}/wiki/#{@page.url}", :wiki_page => { :body => 'i agree', :title => 'talk page' }
response.should be_redirect
end
end
it "should progress for assignment discussions" do
@assignment = @course.assignments.create!(:title => 'talk assn', :submission_types => 'discussion_topic')
@tag = @module.add_item(:type => 'assignment', :id => @assignment.id)
before_after do
post "/courses/#{@course.id}/discussion_entries", :discussion_entry => { :message => 'ohai', :discussion_topic_id => @assignment.discussion_topic.id }
response.should be_redirect
end
end
end
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
describe "progressing before job is run" do
def progression_testing(progress_by_item_link)
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
enable_cache do
@is_attachment = false
course_with_student_logged_in(:active_all => true)
@quiz = @course.quizzes.create!(:title => "new quiz", :shuffle_answers => true)
@mod1 = @course.context_modules.create!(:name => "some module")
@mod1.require_sequential_progress = true
@mod1.save!
@tag1 = @mod1.add_item(:type => 'quiz', :id => @quiz.id)
@mod1.completion_requirements = {@tag1.id => {:type => 'min_score', :min_score => 1}}
@mod1.save!
@mod2 = @course.context_modules.create!(:name => "dependant module")
@mod2.prerequisites = "module_#{@mod1.id}"
@mod2.save!
yield '<div id="test_content">yay!</div>'
get @test_url
response.should be_success
html = Nokogiri::HTML(response.body)
html.css('#test_content').length.should == (@test_content_length || 0)
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
p1 = @mod1.evaluate_for(@user, true, true)
@quiz_submission = @quiz.generate_submission(@user)
@quiz_submission.grade_submission
@quiz_submission.workflow_state = 'completed'
@quiz_submission.kept_score = 1
@quiz_submission.save!
#emulate settings on progression if the user took the quiz but background jobs haven't run yet
p1.requirements_met = [{:type=>"min_score", :min_score=>"1", :max_score=>nil, :id=>@quiz.id}]
p1.save!
next_link = progress_by_item_link ?
"/courses/#{@course.id}/modules/items/#{@tag2.id}" :
"/courses/#{@course.id}/modules/#{@mod2.id}/items/first"
get next_link
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
response.should be_redirect
allow using an item in modules more than once closes #8769 An item can be added to multiple modules, or even the same module more than once. This is especially useful for attachment items, but is also useful for allowing multiple paths through a course, with say an assignment in two different modules and the user only has to complete one of the two modules. test plan: For an item in only one module, verify that the module navigation still appears if you go straight to that item's page, without going through the modules page. Add an item to more than one module. If you visit that item from the modules page, you'll see the right nav depending on which instance of the item you clicked on. If you visit the item directly without going through the modules page, you'll see no nav. Lock one instance of the item by adding a prerequisite, but leave the other unlocked. You can still see the item as a student. Lock all instances of the item with prerequisites. The item will now be locked and you can't see it as a student. Add completion requirements to the item, such as a minimum score on a quiz. Make the requirements different -- 3 points in one instance and 5 in the other, for instance. Verify that if you get 3 points on the quiz, one item is marked as completed but the other isn't, as expected. Rename the item. Verify that all instances of it in modules get renamed. Change-Id: I4f1b2f6f033062ec47ac34fe5eb973a950c17b0c Reviewed-on: https://gerrit.instructure.com/11671 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
2012-06-19 06:18:43 +08:00
response.location.ends_with?(@test_url + "?module_item_id=#{@tag2.id}").should be_true
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
get @test_url
response.should be_success
html = Nokogiri::HTML(response.body)
if @is_attachment
html.at_css('#file_content')['src'].should =~ %r{#{@test_url}}
else
html.css('#test_content').length.should == 1
end
end
end
it "should progress to assignment" do
[true, false].each do |progress_type|
progression_testing(progress_type) do |content|
asmnt = @course.assignments.create!(:title => 'assignment', :description => content)
@test_url = "/courses/#{@course.id}/assignments/#{asmnt.id}"
@tag2 = @mod2.add_item(:type => 'assignment', :id => asmnt.id)
end
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
end
end
it "should progress to discussion topic" do
[true, false].each do |progress_type|
progression_testing(progress_type) do |content|
discussion = @course.discussion_topics.create!(:title => "topic", :message => content)
@test_url = "/courses/#{@course.id}/discussion_topics/#{discussion.id}"
@tag2 = @mod2.add_item(:type => 'discussion_topic', :id => discussion.id)
@test_content_length = 1
end
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
end
end
it "should progress to a quiz" do
[true, false].each do |progress_type|
progression_testing(progress_type) do |content|
quiz = @course.quizzes.create!(:title => "quiz", :description => content)
@test_url = "/courses/#{@course.id}/quizzes/#{quiz.id}"
@tag2 = @mod2.add_item(:type => 'quiz', :id => quiz.id)
end
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
end
end
it "should progress to a wiki page" do
[true, false].each do |progress_type|
progression_testing(progress_type) do |content|
page = @course.wiki.wiki_pages.create!(:title => "wiki", :body => content)
@test_url = "/courses/#{@course.id}/wiki/#{page.url}"
@tag2 = @mod2.add_item(:type => 'wiki_page', :id => page.id)
end
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
end
end
it "should progress to an attachment" do
[true, false].each do |progress_type|
progression_testing(progress_type) do |content|
@is_attachment = true
att = Attachment.create!(:filename => 'test.html', :display_name => "test.html", :uploaded_data => StringIO.new(content), :folder => Folder.unfiled_folder(@course), :context => @course)
@test_url = "/courses/#{@course.id}/files/#{att.id}"
@tag2 = @mod2.add_item(:type => 'attachment', :id => att.id)
end
allow module progression when background job hasn't finished If a user just completed a module and hasn't gone to the modules page and clicks the next module item button that goes into the next module (not another item within the same module), the next module will still be locked. (If they click before the delayed job is run) This commit makes it so that clicking on a module item link that goes to a locked item will cause the module progressions to be recalculated in-request before the user is redirected to the destination resource. This should happen fairly infrequently since the user will only be able to access a locked module item link under the circumstances mentioned in the first paragraph. (locked items are disabled while on the modules page) Test Plan: * Run canvas in production with caching on and Delayed Jobs not running * Create a module with a quiz as the last item * Make it so that the module isn't complete unless the student has scored at least 1 * Create a second module with an assignment as the first item * Make it so that module isn't unlocked until the first module is complete * Add a student and publish the course * Log in as student * Go to the quiz in the first module * Observe that clicking the next module item button takes you to the assignment but that it is locked. * Take the quiz and score at least 1, _do not_ go to the modules page after this is done. * Click the next module item button and make sure the assignment is unlocked closes #6254 Change-Id: I0719ecdc75af2d5c61bf78fbe2f07c4f21f2e24d Reviewed-on: https://gerrit.instructure.com/7362 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
2011-12-08 11:06:24 +08:00
end
end
end
end