canvas-lms/spec/controllers/wiki_pages_controller_spec.rb

164 lines
5.2 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
2011-02-01 09:57:29 +08:00
#
# 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 WikiPagesController do
Add WikiPage assignment type refs CYOE-67 Test Plan 0. `rake db:migrate` and compile assets. Enable the conditional release feature flag in course settings. 1. Create a published WikiPage, assignment-free. Ensure it is visible to errybody. 2. With the API, create an assignment with submission type 'wiki_page'. A new page will be created for the assignment. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment": {"name": "Page Asg", "published":true, \ "submission_types":["wiki_page"]}}' ``` 3. Ensure the assignment is assigned to "Everyone" and the page is visible to all. 4. Assign the assignment to a specific student or section. Ensure the page is visible only to the assigned set. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X PUT -d '{"assignment": {"only_visible_to_overrides": true }}' curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13/overrides" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment_override": {"student_ids":[126]}}' ``` 5. Ensure the DA behavior also applies to WikiPage#show and update and edit. 6. Ensure API behavior matches docs for Assignment and Page endpoints. 7. Ensure no regressions in non-page assignments, with and without CR feature flag. Ensure no regressions in discussion topics and announcements, including assigned discussions. Change-Id: Ie53c6ffa4e4533cedd54f10aee3ba0b8a27aa4d5 Reviewed-on: https://gerrit.instructure.com/75139 Reviewed-by: Matt Berns <mberns@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Christian Prescott <cprescott@instructure.com>
2016-04-08 00:37:16 +08:00
before do
course_with_teacher_logged_in(active_all: true)
@wiki = @course.wiki
end
describe "GET 'front_page'" do
it "should redirect" do
get 'front_page', :course_id => @course.id
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/pages})
2011-02-01 09:57:29 +08:00
end
it "sets up js_env for view_all_pages link" do
Add WikiPage assignment type refs CYOE-67 Test Plan 0. `rake db:migrate` and compile assets. Enable the conditional release feature flag in course settings. 1. Create a published WikiPage, assignment-free. Ensure it is visible to errybody. 2. With the API, create an assignment with submission type 'wiki_page'. A new page will be created for the assignment. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment": {"name": "Page Asg", "published":true, \ "submission_types":["wiki_page"]}}' ``` 3. Ensure the assignment is assigned to "Everyone" and the page is visible to all. 4. Assign the assignment to a specific student or section. Ensure the page is visible only to the assigned set. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X PUT -d '{"assignment": {"only_visible_to_overrides": true }}' curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13/overrides" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment_override": {"student_ids":[126]}}' ``` 5. Ensure the DA behavior also applies to WikiPage#show and update and edit. 6. Ensure API behavior matches docs for Assignment and Page endpoints. 7. Ensure no regressions in non-page assignments, with and without CR feature flag. Ensure no regressions in discussion topics and announcements, including assigned discussions. Change-Id: Ie53c6ffa4e4533cedd54f10aee3ba0b8a27aa4d5 Reviewed-on: https://gerrit.instructure.com/75139 Reviewed-by: Matt Berns <mberns@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Christian Prescott <cprescott@instructure.com>
2016-04-08 00:37:16 +08:00
front_page = @wiki.wiki_pages.create!(title: "ponies4ever")
@wiki.set_front_page_url!(front_page.url)
get 'front_page', course_id: @course.id
expect(response).to be_success
expect(assigns[:js_env][:DISPLAY_SHOW_ALL_LINK]).to be(true)
end
2011-02-01 09:57:29 +08:00
end
Add WikiPage assignment type refs CYOE-67 Test Plan 0. `rake db:migrate` and compile assets. Enable the conditional release feature flag in course settings. 1. Create a published WikiPage, assignment-free. Ensure it is visible to errybody. 2. With the API, create an assignment with submission type 'wiki_page'. A new page will be created for the assignment. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment": {"name": "Page Asg", "published":true, \ "submission_types":["wiki_page"]}}' ``` 3. Ensure the assignment is assigned to "Everyone" and the page is visible to all. 4. Assign the assignment to a specific student or section. Ensure the page is visible only to the assigned set. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X PUT -d '{"assignment": {"only_visible_to_overrides": true }}' curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13/overrides" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment_override": {"student_ids":[126]}}' ``` 5. Ensure the DA behavior also applies to WikiPage#show and update and edit. 6. Ensure API behavior matches docs for Assignment and Page endpoints. 7. Ensure no regressions in non-page assignments, with and without CR feature flag. Ensure no regressions in discussion topics and announcements, including assigned discussions. Change-Id: Ie53c6ffa4e4533cedd54f10aee3ba0b8a27aa4d5 Reviewed-on: https://gerrit.instructure.com/75139 Reviewed-by: Matt Berns <mberns@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Christian Prescott <cprescott@instructure.com>
2016-04-08 00:37:16 +08:00
context "with page" do
before do
@page = @wiki.wiki_pages.create!(title: "ponies5ever", body: "")
end
Add WikiPage assignment type refs CYOE-67 Test Plan 0. `rake db:migrate` and compile assets. Enable the conditional release feature flag in course settings. 1. Create a published WikiPage, assignment-free. Ensure it is visible to errybody. 2. With the API, create an assignment with submission type 'wiki_page'. A new page will be created for the assignment. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment": {"name": "Page Asg", "published":true, \ "submission_types":["wiki_page"]}}' ``` 3. Ensure the assignment is assigned to "Everyone" and the page is visible to all. 4. Assign the assignment to a specific student or section. Ensure the page is visible only to the assigned set. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X PUT -d '{"assignment": {"only_visible_to_overrides": true }}' curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13/overrides" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment_override": {"student_ids":[126]}}' ``` 5. Ensure the DA behavior also applies to WikiPage#show and update and edit. 6. Ensure API behavior matches docs for Assignment and Page endpoints. 7. Ensure no regressions in non-page assignments, with and without CR feature flag. Ensure no regressions in discussion topics and announcements, including assigned discussions. Change-Id: Ie53c6ffa4e4533cedd54f10aee3ba0b8a27aa4d5 Reviewed-on: https://gerrit.instructure.com/75139 Reviewed-by: Matt Berns <mberns@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Christian Prescott <cprescott@instructure.com>
2016-04-08 00:37:16 +08:00
describe "GET 'show_redirect'" do
it "should redirect" do
get 'show_redirect', :course_id => @course.id, :id => @page.url
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/pages/#{@page.url}})
end
end
describe "GET 'show'" do
it "should render" do
get 'show', course_id: @course.id, id: @page.url
expect(response).to be_successful
end
end
describe "GET 'edit'" do
it "should render" do
get 'edit', course_id: @course.id, id: @page.url
expect(response).to be_successful
end
end
describe "GET 'revisions'" do
it "should render" do
get 'revisions', course_id: @course.id, wiki_page_id: @page.url
expect(response).to be_successful
end
end
context "differentiated assignments" do
before do
assignment = @course.assignments.create!(
submission_types: 'wiki_page',
only_visible_to_overrides: true
)
@page.assignment = assignment
@page.editing_roles = "teachers,students"
@page.save!
@student_with_override, @student_without_override = create_users(2, return_type: :record)
@section = @course.course_sections.create!(name: "test section")
create_section_override_for_assignment(assignment, course_section: @section)
end
context "for unassigned students" do
before do
@course.enroll_student(@student_without_override, enrollment_state: 'active')
user_session(@student_without_override)
end
it "should allow show" do
get 'show', course_id: @course.id, id: @page.url
expect(response.code).to eq "200"
end
it "should allow edit" do
get 'edit', course_id: @course.id, id: @page.url
expect(response.code).to eq "200"
end
it "should allow revisions" do
get 'revisions', course_id: @course.id, wiki_page_id: @page.url
expect(response.code).to eq "200"
end
context "feature enabled" do
before do
ConditionalRelease::Service.stubs(:configured?).returns(true)
Add WikiPage assignment type refs CYOE-67 Test Plan 0. `rake db:migrate` and compile assets. Enable the conditional release feature flag in course settings. 1. Create a published WikiPage, assignment-free. Ensure it is visible to errybody. 2. With the API, create an assignment with submission type 'wiki_page'. A new page will be created for the assignment. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment": {"name": "Page Asg", "published":true, \ "submission_types":["wiki_page"]}}' ``` 3. Ensure the assignment is assigned to "Everyone" and the page is visible to all. 4. Assign the assignment to a specific student or section. Ensure the page is visible only to the assigned set. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X PUT -d '{"assignment": {"only_visible_to_overrides": true }}' curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13/overrides" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment_override": {"student_ids":[126]}}' ``` 5. Ensure the DA behavior also applies to WikiPage#show and update and edit. 6. Ensure API behavior matches docs for Assignment and Page endpoints. 7. Ensure no regressions in non-page assignments, with and without CR feature flag. Ensure no regressions in discussion topics and announcements, including assigned discussions. Change-Id: Ie53c6ffa4e4533cedd54f10aee3ba0b8a27aa4d5 Reviewed-on: https://gerrit.instructure.com/75139 Reviewed-by: Matt Berns <mberns@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Christian Prescott <cprescott@instructure.com>
2016-04-08 00:37:16 +08:00
@course.enable_feature!(:conditional_release)
end
it "should forbid show" do
get 'show', course_id: @course.id, id: @page.url
expect(response).to be_redirect
expect(response.location).to eq course_wiki_pages_url(@course)
end
it "should forbid edit" do
get 'edit', course_id: @course.id, id: @page.url
expect(response).to be_redirect
expect(response.location).to eq course_wiki_pages_url(@course)
end
it "should forbid revisions" do
get 'revisions', course_id: @course.id, wiki_page_id: @page.url
expect(response).to be_redirect
expect(response.location).to eq course_wiki_pages_url(@course)
end
end
end
context "for assigned students" do
before do
student_in_section(@section, user: @student_with_override)
user_session(@student_with_override)
end
it "should allow show" do
get 'show', course_id: @course.id, id: @page.url
expect(response.code).to eq "200"
end
it "should allow edit" do
get 'edit', course_id: @course.id, id: @page.url
expect(response.code).to eq "200"
expect(controller.js_env[:CONDITIONAL_RELEASE_SERVICE_ENABLED]).to eq false
Add WikiPage assignment type refs CYOE-67 Test Plan 0. `rake db:migrate` and compile assets. Enable the conditional release feature flag in course settings. 1. Create a published WikiPage, assignment-free. Ensure it is visible to errybody. 2. With the API, create an assignment with submission type 'wiki_page'. A new page will be created for the assignment. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment": {"name": "Page Asg", "published":true, \ "submission_types":["wiki_page"]}}' ``` 3. Ensure the assignment is assigned to "Everyone" and the page is visible to all. 4. Assign the assignment to a specific student or section. Ensure the page is visible only to the assigned set. ```sh curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X PUT -d '{"assignment": {"only_visible_to_overrides": true }}' curl "http://canvas.dev:3000/api/v1/courses/1/assignments/13/overrides" \ -H "Content-Type: application/json" -H "Authorization: Bearer <token>" \ -X POST -d '{"assignment_override": {"student_ids":[126]}}' ``` 5. Ensure the DA behavior also applies to WikiPage#show and update and edit. 6. Ensure API behavior matches docs for Assignment and Page endpoints. 7. Ensure no regressions in non-page assignments, with and without CR feature flag. Ensure no regressions in discussion topics and announcements, including assigned discussions. Change-Id: Ie53c6ffa4e4533cedd54f10aee3ba0b8a27aa4d5 Reviewed-on: https://gerrit.instructure.com/75139 Reviewed-by: Matt Berns <mberns@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Christian Prescott <cprescott@instructure.com>
2016-04-08 00:37:16 +08:00
end
it "should allow revisions" do
get 'revisions', course_id: @course.id, wiki_page_id: @page.url
expect(response.code).to eq "200"
end
end
end
end
2011-02-01 09:57:29 +08:00
end