Testes para WikiController
This commit is contained in:
@@ -20,6 +20,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
include AuthenticationSystem
|
||||
|
||||
helper :all
|
||||
before_filter :startup
|
||||
before_filter :set_timezone
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# 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/>.
|
||||
|
||||
|
||||
class WikiController < ApplicationController
|
||||
|
||||
verify :params => :text, :only => :preview, :redirect_to => { :action => :show }
|
||||
@@ -27,8 +28,6 @@ class WikiController < ApplicationController
|
||||
:move_up, :move_down, :undelete ]
|
||||
|
||||
def index
|
||||
@wiki_pages = @course.wiki_pages
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to course_url(@course) }
|
||||
format.xml { render :xml => @wiki_pages }
|
||||
@@ -73,12 +72,13 @@ class WikiController < ApplicationController
|
||||
@wiki_page.attributes = params[:wiki_page]
|
||||
@wiki_page.user_id = session[:user_id]
|
||||
@wiki_page.course_id = @course.id
|
||||
dirty = @wiki_page.changed?
|
||||
changed = @wiki_page.changed?
|
||||
@wiki_page.save!
|
||||
|
||||
WikiEditLogEntry.create!(:target_id => @wiki_page.id, :user => @current_user, :course => @course, :version => @wiki_page.version) if dirty
|
||||
|
||||
flash[:notice] = "Wiki page updated"[]
|
||||
if changed
|
||||
WikiEditLogEntry.create!(:target_id => @wiki_page.id, :user => @current_user, :course => @course, :version => @wiki_page.version)
|
||||
flash[:notice] = "Wiki page updated"[]
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to course_wiki_instance_url(@course, @wiki_page) }
|
||||
@@ -113,9 +113,9 @@ class WikiController < ApplicationController
|
||||
def preview
|
||||
@text = params[:text]
|
||||
begin
|
||||
render :text => BlueCloth.new(@text).to_html
|
||||
rescue
|
||||
render :text => $!.to_s.gsub(">", ">").gsub("<", "<")
|
||||
render :text => @text.format_wiki
|
||||
rescue RuntimeError
|
||||
render :text => $!.to_s.gsub(">", ">").gsub("<", "<"), :status => :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
@@ -149,6 +149,7 @@ class WikiController < ApplicationController
|
||||
def undelete
|
||||
@wiki_page = WikiPage.find_with_deleted(params[:id])
|
||||
@wiki_page.recover!
|
||||
@wiki_page.insert_at(1)
|
||||
flash[:notice] = "Wiki page restored"[]
|
||||
|
||||
WikiRestoreLogEntry.create!(:target_id => @wiki_page.id, :user => @current_user, :course => @wiki_page.course)
|
||||
|
||||
@@ -51,10 +51,6 @@ module ApplicationHelper
|
||||
logged_in? and current_user.admin?
|
||||
end
|
||||
|
||||
def wiki(text)
|
||||
BlueCloth.new(text).to_html
|
||||
end
|
||||
|
||||
def formatted(text)
|
||||
h(text).gsub("\n", "<br/>")
|
||||
end
|
||||
@@ -75,7 +71,7 @@ module ApplicationHelper
|
||||
|
||||
def markup_help
|
||||
return "<div id='markup_help' style='display: none'>" +
|
||||
wiki(File.read("#{RAILS_ROOT}/public/static/markup_help.mkd")) +
|
||||
File.read("#{RAILS_ROOT}/public/static/markup_help.mkd").format_wiki +
|
||||
"</div>"
|
||||
end
|
||||
|
||||
@@ -91,4 +87,5 @@ module ApplicationHelper
|
||||
def format_period(period)
|
||||
return "20#{period[0..1]}.#{period[2..2]}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -14,6 +14,14 @@
|
||||
# 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/>.
|
||||
|
||||
class String
|
||||
def format_wiki
|
||||
text = BlueCloth.new(self).to_html
|
||||
text = Hpricot(text, :xhtml_strict => true).to_s
|
||||
return text.sanitize
|
||||
end
|
||||
end
|
||||
|
||||
module WikiHelper
|
||||
|
||||
def format_diff(text)
|
||||
|
||||
@@ -19,6 +19,7 @@ class Event < ActiveRecord::Base
|
||||
# Plugins
|
||||
acts_as_paranoid
|
||||
acts_as_versioned :if_changed => [ :title, :description, :time ]
|
||||
acts_as_paranoid_versioned
|
||||
self.non_versioned_columns << 'deleted_at'
|
||||
|
||||
# Associacoes
|
||||
@@ -43,4 +44,5 @@ class Event < ActiveRecord::Base
|
||||
end
|
||||
return cal.to_ical
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -20,6 +20,7 @@ class Message < ActiveRecord::Base
|
||||
acts_as_paranoid
|
||||
acts_as_versioned :if_changed => [ :title, :body ]
|
||||
self.non_versioned_columns << 'deleted_at'
|
||||
acts_as_paranoid_versioned
|
||||
|
||||
# Associacoes
|
||||
belongs_to :user,
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
require 'acts_as_versioned'
|
||||
require 'tempfile'
|
||||
|
||||
|
||||
class WikiPage < ActiveRecord::Base
|
||||
|
||||
# Plugins
|
||||
acts_as_paranoid
|
||||
acts_as_list :scope => 'course_id = #{course_id}'
|
||||
acts_as_versioned :if_changed => [ :content, :description, :title ]
|
||||
acts_as_paranoid_versioned
|
||||
self.non_versioned_columns << 'position'
|
||||
self.non_versioned_columns << 'deleted_at'
|
||||
|
||||
@@ -37,18 +39,14 @@ class WikiPage < ActiveRecord::Base
|
||||
|
||||
def validate
|
||||
begin
|
||||
to_html
|
||||
self.content.format_wiki
|
||||
rescue
|
||||
errors.add("content", "possui erro de sintaxe")
|
||||
errors.add("content", "possui erro de sintaxe: " + $!.to_s.html_escape)
|
||||
end
|
||||
end
|
||||
|
||||
def to_html(text = self.content)
|
||||
return BlueCloth.new(text).to_html
|
||||
end
|
||||
|
||||
def to_param
|
||||
self.title.match(/^[-_a-z0-9]*$/i).nil? ? self.id.to_id : self.title
|
||||
self.title.match(/^[-_a-z0-9]*$/i).nil? ? self.id.to_s : self.title
|
||||
end
|
||||
|
||||
def WikiPage.diff(from, to)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
%h4.title Disciplina
|
||||
%h1.title= h(@course.full_name)
|
||||
|
||||
%p= wiki @course.description
|
||||
%p= @course.description.format_wiki
|
||||
|
||||
.box
|
||||
.cmd
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
%meta{'http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8'}
|
||||
|
||||
%link{'href' => "#{App.base_path}/stylesheets/cache/wiki.css", 'rel' => 'Stylesheet', 'type' => %'text/css'}
|
||||
%link#css_color{'href' => "#{App.base_path}/stylesheets/cache/color.#@color.css", 'rel' => 'Stylesheet', 'type' => %'text/css'}
|
||||
%link#css_color{'href' => "#{App.base_path}/stylesheets/cache/color.#{@color}.css", 'rel' => 'Stylesheet', 'type' => %'text/css'}
|
||||
|
||||
/[if IE]
|
||||
%link{:href => "#{App.base_path}/stylesheets/ie/ie.css", :rel => "stylesheet", :type => "text/css"}
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
%p= "Última visita há {c}"[:last_seen, distance_of_time_in_words(Time.now, @user.last_seen)]
|
||||
|
||||
-# cache(user_path(@user.id)) do
|
||||
= wiki @user.description if !@user.description.blank?
|
||||
= @user.description.format_wiki if !@user.description.blank?
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
%h4.title= h(@course.full_name)
|
||||
%h1.title= h(@wiki_page.title)
|
||||
#wiki_text
|
||||
= @wiki_page.to_html
|
||||
= @wiki_page.content.format_wiki
|
||||
|
||||
Reference in New Issue
Block a user