# This file is part of Wiki UFC. # Copyright (C) 2007-2015 by Álinson Xavier # Copyright (C) 2007-2008 by Adriano Freitas # Copyright (C) 2007-2008 by André Castro # Copyright (C) 2007-2008 by Rafael Barbosa <86.rafael@gmail.com> # Copyright (C) 2007-2008 by Henrique Bustamante # # This program 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, either version 3 of the # License, or (at your option) any later version. # # This program 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 . require File.dirname(__FILE__) + '/../test_helper' require 'wiki_controller' # Re-raise errors caught by the controller. class WikiController def rescue_action(e) fail e end end class WikiControllerTest < ActionController::TestCase def setup @course = Course.first @wiki_page = @course.wiki_pages.new(title: 'test1', content: 'content1', description: 'test', front_page: true) @wiki_page.user = users(:bob) @wiki_page.version = 1 @wiki_page.save! @wiki_page.title = 'new title' @wiki_page.save! @another_wiki_page = @course.wiki_pages.new(title: 'another', content: 'another', description: 'test', front_page: true) @another_wiki_page.user = users(:bob) @another_wiki_page.version = 1 @another_wiki_page.save! @another_wiki_page.move_to_bottom @another_wiki_page.save! @wiki_page.reload LogEntry.delete_all end context "An anonymous user" do should_request_login_on_post_to(:new, { course_id: 1 }) should_request_login_on_post_to(:create, { course_id: 1 }) should_request_login_on_post_to(:edit, { course_id: 1, id: 1 }) should_request_login_on_post_to(:update, { course_id: 1, id: 1 }) should_request_login_on_post_to(:destroy, { course_id: 1, id: 1 }) should_request_login_on_post_to(:move_up, { course_id: 1, id: 1 }) should_request_login_on_post_to(:move_down, { course_id: 1, id: 1 }) context "on get to :index" do setup { get :index, course_id: @course.id } should respond_with :success should render_template 'index' end context "on get to :show" do setup { get :show, course_id: @course.id, id: @wiki_page.id } should respond_with :success should render_template 'show' should "show the wiki page" do assert_select 'h1.title', @wiki_page.title end should "show the selected version" do @wiki_page.revert_to(1) get :show, course_id: @course.id, id: @wiki_page.id, version: 1 assert_select 'h1.title', @wiki_page.title end end context "on get to :versions" do setup { get :versions, course_id: @course.id, id: @wiki_page.id } should respond_with :success should render_template 'versions' should "show the wiki page versions" do @wiki_page.versions.each do |v| assert_select 'a[href=?]', course_wiki_instance_url(@course, @wiki_page, version: v.version) end end end context "on get to :preview" do context "with valid markup" do setup { get :preview, text: "hello {$x$} x" } should respond_with :success should "strip harmful tags" do assert_select 'script', false assert_select '*[onclick]', false end end context "with invalid markup" do setup { get :preview, text: "