2011-06-03 00:09:33 +08:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2012-02-02 04:39:03 +08:00
|
|
|
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"
|
2013-03-26 23:19:59 +08:00
|
|
|
ContextModule.where(:id => context_module).update_all(:updated_at => 1.hour.ago)
|
2012-02-02 04:39:03 +08:00
|
|
|
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
|
|
|
|
|
2011-06-03 00:09:33 +08:00
|
|
|
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
|
2012-06-21 02:58:03 +08:00
|
|
|
@assignment = @course.assignments.create!(:title => 'talk assn', :submission_types => 'discussion_topic')
|
2011-06-03 00:09:33 +08:00
|
|
|
@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
|
2011-12-08 11:06:24 +08:00
|
|
|
|
|
|
|
describe "progressing before job is run" do
|
2012-05-10 02:57:05 +08:00
|
|
|
def progression_testing(progress_by_item_link)
|
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)
|
2013-04-26 05:38:04 +08:00
|
|
|
html.css('#test_content').length.should == (@test_content_length || 0)
|
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!
|
|
|
|
|
2012-05-10 02:57:05 +08:00
|
|
|
next_link = progress_by_item_link ?
|
|
|
|
"/courses/#{@course.id}/modules/items/#{@tag2.id}" :
|
|
|
|
"/courses/#{@course.id}/modules/#{@mod2.id}/items/first"
|
|
|
|
|
|
|
|
get next_link
|
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
|
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
|
2012-05-10 02:57:05 +08:00
|
|
|
[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
|
2011-12-08 11:06:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should progress to discussion topic" do
|
2012-05-10 02:57:05 +08:00
|
|
|
[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)
|
2013-04-26 05:38:04 +08:00
|
|
|
@test_content_length = 1
|
2012-05-10 02:57:05 +08:00
|
|
|
end
|
2011-12-08 11:06:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should progress to a quiz" do
|
2012-05-10 02:57:05 +08:00
|
|
|
[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
|
2011-12-08 11:06:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should progress to a wiki page" do
|
2012-05-10 02:57:05 +08:00
|
|
|
[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
|
2011-12-08 11:06:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should progress to an attachment" do
|
2012-05-10 02:57:05 +08:00
|
|
|
[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
|
2011-12-08 11:06:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-06-03 00:09:33 +08:00
|
|
|
end
|