Fix remaining tests

master
Alinson S. Xavier 10 years ago
parent 02662a0853
commit 9d63320331

@ -26,12 +26,6 @@ gem 'simplecov'
group :test do group :test do
gem 'turn' gem 'turn'
#gem 'silencer'
end end
#group :development, :production do
# gem 'brazilian-rails', '3.3.0', :path => './vendor/gems/brazilian-rails/brI18n/'
#end
#group :development do
# gem 'mongrel'
#end

@ -32,7 +32,7 @@ module WikiHelper
text << "\n" text << "\n"
style = { '+' => 'add', '-' => 'del', ' ' => 'line' } style = { '+' => 'add', '-' => 'del', ' ' => 'line' }
text.each do |line| text.each_line do |line|
# Ignora o cabecalho # Ignora o cabecalho
next if line.match(/^---/) next if line.match(/^---/)
next if line.match(/^\+\+\+/) next if line.match(/^\+\+\+/)

@ -22,6 +22,7 @@ require 'tempfile'
class WikiPage < ActiveRecord::Base class WikiPage < ActiveRecord::Base
attr_accessible :title, :front_page, :content, :description attr_accessible :title, :front_page, :content, :description
attr_writer :type
# Plugins # Plugins
acts_as_paranoid acts_as_paranoid

@ -9,7 +9,7 @@
%label{:for =>'wiki_page_content'} %label{:for =>'wiki_page_content'}
Conteúdo Conteúdo
=markup_enabled_field =markup_enabled_field
%dd= preserve(text_area('wiki_page', 'content')) %dd=text_area('wiki_page', 'content')
- unless @wiki_page.new_record? - unless @wiki_page.new_record?
%dt %dt

@ -25,7 +25,7 @@
%td.narrow %td.narrow
%input{:type => "radio", :name => "to", :value => entry.version, :onclick => %"history_to(#{entry.version})"} %input{:type => "radio", :name => "to", :value => entry.version, :onclick => %"history_to(#{entry.version})"}
%td= link_to(tz(entry.updated_at).strftime("%d/%m/%y&nbsp;%H:%M:%S"), course_wiki_instance_url(@course, @wiki_page, :version => entry.version)) %td= link_to(tz(entry.updated_at).strftime("%d/%m/%y&nbsp;%H:%M:%S"), course_wiki_instance_url(@course, @wiki_page, :version => entry.version))
%td= link_to truncate(h(User.find_with_deleted(entry.user_id).display_name), :length => 20), user_path(User.find_with_deleted(entry.user_id)) %td= link_to truncate(h(User.with_deleted.find(entry.user_id).display_name), :length => 20), user_path(User.with_deleted.find(entry.user_id))
%td %td
= entry.description = entry.description
- if (entry.version > @wiki_page.versions.minimum(:version)) - if (entry.version > @wiki_page.versions.minimum(:version))

@ -2,6 +2,7 @@
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
Rails.backtrace_cleaner.add_silencer { |line| line =~ /\.rvm/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers! # Rails.backtrace_cleaner.remove_silencers!

@ -14,53 +14,52 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'
#require 'news_controller' require 'news_controller'
#
## Re-raise errors caught by the controller. # Re-raise errors caught by the controller.
#class NewsController; def rescue_action(e) raise e end; end class NewsController; def rescue_action(e) raise e end; end
#
#class NewsControllerTest < ActionController::TestCase class NewsControllerTest < ActionController::TestCase
# def setup def setup
# @controller = NewsController.new @controller = NewsController.new
# @request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
# @response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
#
# @course = Course.find(:first) @course = Course.find(:first)
# @news = @course.news.find(:first) @news = @course.news.find(:first)
end
# REST - usuários autenticados
#context "A user" do
# setup { login_as :bob }
# should_be_restful do |resource|
# resource.klass = News
# resource.object = 'news'
# resource.parent = [ :course ]
# resource.create.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# resource.update.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# resource.destroy.redirect = "course_news_url(@course)"
# end # end
#
# # REST - usuários autenticados
# #context "A user" do
# # setup { login_as :bob }
# # should_be_restful do |resource|
# # resource.klass = News
# # resource.object = 'news'
# # resource.parent = [ :course ]
# # resource.create.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# # resource.update.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# # resource.destroy.redirect = "course_news_url(@course)"
# # end
# #end
#
# ## REST - usuários quaisquer
# #context "A stranger" do
# # setup { logout }
# # should_be_restful do |resource|
# # resource.klass = News
# # resource.object = 'news'
# # resource.parent = [ :course ]
# # resource.create.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# # resource.update.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# # resource.denied.actions = [ :new, :edit, :create, :update, :destroy ]
# # resource.denied.redirect = "'/login'"
# # resource.denied.flash = /must be logged in/i
# # end
# #end
#
# #def test_should_accept_rss_on_index
# # get :index, :format => 'rss', :course_id => 1
# # assert_formatted_response :rss
# #end
#end #end
#
## REST - usuários quaisquer
#context "A stranger" do
# setup { logout }
# should_be_restful do |resource|
# resource.klass = News
# resource.object = 'news'
# resource.parent = [ :course ]
# resource.create.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# resource.update.params = { :title => 'test', :body => 'test', :receiver_id => 1 }
# resource.denied.actions = [ :new, :edit, :create, :update, :destroy ]
# resource.denied.redirect = "'/login'"
# resource.denied.flash = /must be logged in/i
# end
#end
#def test_should_accept_rss_on_index
# get :index, :format => 'rss', :course_id => 1
# assert_formatted_response :rss
#end
end

@ -14,36 +14,35 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'
#require 'users_controller' require 'users_controller'
#
## Re-raise errors caught by the controller. # Re-raise errors caught by the controller.
#class UsersController; def rescue_action(e) raise e end; end class UsersController; def rescue_action(e) raise e end; end
#
#class UsersControllerTest < ActionController::TestCase class UsersControllerTest < ActionController::TestCase
#
# context "An authenticated user" do context "An authenticated user" do
# setup { login_as :bob } setup { login_as :bob }
#
# context "on get to :dashboard" do context "on get to :dashboard" do
# setup { get :dashboard } setup { get :dashboard }
#
# should respond_with :success should respond_with :success
# should render_template "dashboard" should render_template "dashboard"
# end end
#
# context "on post to :logout" do context "on post to :logout" do
# setup { get :logout } setup { get :logout }
#
# should respond_with :redirect should respond_with :redirect
# should redirect_to('the main page') { index_url } should redirect_to('the main page') { index_url }
#
# should "log out" do should "log out" do
# assert_nil session[:user_id] assert_nil session[:user_id]
# assert_nil cookies[:login_token] assert_nil cookies[:login_token]
# end end
# end end
#
# end end
#end end
#

@ -14,251 +14,258 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'
#require 'wiki_controller' require 'wiki_controller'
#
## Re-raise errors caught by the controller. # Re-raise errors caught by the controller.
#class WikiController; def rescue_action(e) raise e end; end class WikiController;
# def rescue_action(e)
#class WikiControllerTest < ActionController::TestCase raise e
# def setup end
# @course = Course.find(:first)
# ;
# @wiki_page = @course.wiki_pages.create(:title => 'test1', :content => 'content1', end
# :user_id => users(:bob).id, :description => 'test', :version => 1)
# @wiki_page.save! class WikiControllerTest < ActionController::TestCase
# @wiki_page.title = 'new title' def setup
# @wiki_page.save! @course = Course.first
#
# @another_wiki_page = @course.wiki_pages.create(:title => 'another', :content => 'another', @wiki_page = @course.wiki_pages.new(:title => 'test1',
# :description => 'test', :user_id => users(:bob).id, :version => 1) :content => 'content1', :description => 'test', :front_page => true)
# @another_wiki_page.move_to_bottom @wiki_page.user = users(:bob)
# @another_wiki_page.save! @wiki_page.version = 1
# @wiki_page.reload @wiki_page.save!
#
# LogEntry.delete_all @wiki_page.title = 'new title'
# end @wiki_page.save!
#
# context "An anonymous user" do @another_wiki_page = @course.wiki_pages.new(:title => 'another',
# :content => 'another', :description => 'test', :front_page => true)
# should_request_login_on_post_to(:new, {:course_id => 1}) @another_wiki_page.user = users(:bob)
# should_request_login_on_post_to(:create, {:course_id => 1}) @another_wiki_page.version = 1
# should_request_login_on_post_to(:edit, {:course_id => 1, :id => 1}) @another_wiki_page.save!
# should_request_login_on_post_to(:update, {:course_id => 1, :id => 1})
# should_request_login_on_post_to(:destroy, {:course_id => 1, :id => 1}) @another_wiki_page.move_to_bottom
# should_request_login_on_post_to(:move_up, {:course_id => 1, :id => 1}) @another_wiki_page.save!
# should_request_login_on_post_to(:move_down, {:course_id => 1, :id => 1}) @wiki_page.reload
#
# #context "on get to :index" do LogEntry.delete_all
# # setup { get :index, :course_id => @course.id } end
# # should redirect_to('the course page') { course_url(@course) }
# #end context "An anonymous user" do
#
# context "on get to :show" do should_request_login_on_post_to(:new, {:course_id => 1})
# setup { get :show, :course_id => @course.id, :id => @wiki_page.id } should_request_login_on_post_to(:create, {:course_id => 1})
# should_request_login_on_post_to(:edit, {:course_id => 1, :id => 1})
# should respond_with :success should_request_login_on_post_to(:update, {:course_id => 1, :id => 1})
# should render_template 'show' 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 "show the wiki page" do should_request_login_on_post_to(:move_down, {:course_id => 1, :id => 1})
# assert_select 'h1.title', @wiki_page.title
# end #context "on get to :index" do
# # setup { get :index, :course_id => @course.id }
# 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$} <script>foo();</script> <i onclick='foo()'>x</i>" }
#
# should respond_with :success
#
# should "display latex formulas" do
# assert_select 'img[class=tex_inline]'
# end
#
# should "strip harmful tags" do
# assert_select 'script', false
# assert_select '*[onclick]', false
# end
# end
#
# context "with invalid markup" do
# setup { get :preview, :text => "<a" }
# should respond_with :bad_request
# end
# end
#
# context "on get to :diff" do
# setup { get :diff, :course_id => @course.id, :id => @wiki_page.id, :from => 1, :to => 2 }
# should respond_with :success
# should assign_to :diff
# end
#
# end
#
# context "An authenticated user" do
# setup { login_as :bob }
#
# context "on get to :new" do
# setup { get :new, :course_id => @course.id }
# #should render_a_form
# should respond_with :success
# end
#
# context "on post to :create" do
# setup do
# assert_nil @course.wiki_pages.find_by_title('test2')
# post :create, :course_id => @course.id, :wiki_page => { :title => 'test2', :content => 'test2' }
# @wiki_page = @course.wiki_pages.find_by_title('test2')
# end
#
# should set_the_flash.to(/created/i)
# should redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
# should_create_log_entry {[ WikiCreateLogEntry, @wiki_page.id, users(:bob).id ]}
#
# should "create a new wiki page" do
# assert @wiki_page
# assert_equal @wiki_page.version, 1
# assert_equal users(:bob).id, @wiki_page.user_id
# end
# end
#
# context "on get to :edit" do
# setup { get :edit, :course_id => @course.id, :id => @wiki_page.id }
#
# #should render_a_form
# should render_template 'edit'
#
# should "render a form with the correct fields" do
# assert_select "input[name='wiki_page[title]'][value=?]", @wiki_page.title
# assert_select "input[name='wiki_page[description]'][value=?]", ""
# assert_select 'textarea', @wiki_page.content
# end
#
# should "edit the selected version" do
# @wiki_page.revert_to(1)
# get :edit, :course_id => @course.id, :id => @wiki_page.id, :version => 1
# assert_select "input[name='wiki_page[title]'][value=?]", @wiki_page.title
# assert_select 'textarea', @wiki_page.content
# end
# end
#
# context "on post to :update" do
# context "with unmodified data" do
# setup do
# post :update, :course_id => @course.id, :id => @wiki_page.id, :wiki_page => {
# :title => @wiki_page.title, :content => @wiki_page.content}
# end
#
# should_not set_the_flash
# should redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
#
# should "not create a new log entry" do
# assert_nil WikiEditLogEntry.find(:first, :conditions => { :target_id => @wiki_page.id })
# end
# end
#
# context "with new data" do
# setup do
# post :update, :course_id => @course.id, :id => @wiki_page.id, :wiki_page => {
# :user_id => 999, :course_id => 999, # not user definable
# :title => 'brand new title', :content => 'brand new content'}
# @wiki_page.reload
# end
#
# should set_the_flash.to(/updated/i)
# should redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
# should_create_log_entry {[ WikiEditLogEntry, @wiki_page.id, users(:bob).id ]}
#
# should "update the wiki page" do
# assert_equal "brand new title", @wiki_page.title
# assert_equal "brand new content", @wiki_page.content
# assert_equal users(:bob).id, @wiki_page.user_id
# assert_equal @course.id, @wiki_page.course_id
# end
# end
# end
#
# context "on post to :destroy" do
# setup { post :destroy, :course_id => @course.id, :id => @wiki_page.id }
#
# should set_the_flash.to(/removed/i)
# should redirect_to('the course page') { course_url(@course) }
# should_create_log_entry {[ WikiDeleteLogEntry, @wiki_page.id, users(:bob).id ]}
#
# should "delete the wiki page" do
# @wiki_page = WikiPage.find_with_deleted(@wiki_page.id)
# assert @wiki_page.deleted?
# end
# end
#
# context "on get to :move_up" do
# setup do
# assert_equal 1, @wiki_page.position
# assert_equal 2, @another_wiki_page.position
# get :move_up, :course_id => @course.id, :id => @another_wiki_page.id
# end
#
# should redirect_to('the course page') { course_url(@course) }
#
# should "move the page up" do
# @wiki_page.reload
# @another_wiki_page.reload
# assert_equal 2, @wiki_page.position
# assert_equal 1, @another_wiki_page.position
# end
# end
#
# context "on get to :move_down" do
# setup do
# assert_equal 1, @wiki_page.position
# assert_equal 2, @another_wiki_page.position
# get :move_down, :course_id => @course.id, :id => @wiki_page.id
# end
#
# should redirect_to('the course page') { course_url(@course) } # should redirect_to('the course page') { course_url(@course) }
#
# should "move the page up" do
# @wiki_page.reload
# @another_wiki_page.reload
# assert_equal 2, @wiki_page.position
# assert_equal 1, @another_wiki_page.position
#end #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$} <script>foo();</script> <i onclick='foo()'>x</i>" }
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 => "<a" }
should respond_with :bad_request
end
end
context "on get to :diff" do
setup { get :diff, :course_id => @course.id, :id => @wiki_page.id, :from => 1, :to => 2 }
should respond_with :success
#should assign_to :diff
end
end
context "An authenticated user" do
setup { login_as :bob }
context "on get to :new" do
setup { get :new, :course_id => @course.id }
#should render_a_form
should respond_with :success
end
context "on post to :create" do
setup do
assert_nil @course.wiki_pages.find_by_title('test2')
post :create, :course_id => @course.id, :wiki_page => {:title => 'test2', :content => 'test2'}
@wiki_page = @course.wiki_pages.find_by_title('test2')
end
should set_flash.to(/created/i)
should redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
should_create_log_entry { [WikiCreateLogEntry, @wiki_page.id, users(:bob).id] }
should "create a new wiki page" do
assert @wiki_page
assert_equal @wiki_page.version, 1
assert_equal users(:bob).id, @wiki_page.user_id
end
end
context "on get to :edit" do
setup { get :edit, :course_id => @course.id, :id => @wiki_page.id }
#should render_a_form
should render_template 'edit'
should "render a form with the correct fields" do
assert_select "input[name='wiki_page[title]'][value=?]", @wiki_page.title
assert_select "input[name='wiki_page[description]'][value=?]", ""
assert_select 'textarea', @wiki_page.content
end
should "edit the selected version" do
@wiki_page.revert_to(1)
get :edit, :course_id => @course.id, :id => @wiki_page.id, :version => 1
assert_select "input[name='wiki_page[title]'][value=?]", @wiki_page.title
assert_select 'textarea', @wiki_page.content
end
end
context "on post to :update" do
context "with unmodified data" do
setup do
post :update, :course_id => @course.id, :id => @wiki_page.id, :wiki_page => {
:title => @wiki_page.title, :content => @wiki_page.content}
end
should_not set_flash
should redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
should "not create a new log entry" do
assert_nil WikiEditLogEntry.find(:first, :conditions => {:target_id => @wiki_page.id})
end
end
context "with new data" do
setup do
post :update, :course_id => @course.id, :id => @wiki_page.id, :wiki_page => {
:title => 'brand new title', :content => 'brand new content'}
@wiki_page.reload
end
should set_flash.to(/updated/i)
should redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
should_create_log_entry { [WikiEditLogEntry, @wiki_page.id, users(:bob).id] }
should "update the wiki page" do
assert_equal "brand new title", @wiki_page.title
assert_equal "brand new content", @wiki_page.content
assert_equal users(:bob).id, @wiki_page.user_id
assert_equal @course.id, @wiki_page.course_id
end
end
end
context "on post to :destroy" do
setup { post :destroy, :course_id => @course.id, :id => @wiki_page.id }
should set_flash.to(/removed/i)
should redirect_to('the course page') { course_url(@course) }
should_create_log_entry { [WikiDeleteLogEntry, @wiki_page.id, users(:bob).id] }
should "delete the wiki page" do
@wiki_page = WikiPage.with_deleted.find(@wiki_page.id)
assert @wiki_page.deleted?
end
end
context "on get to :move_up" do
setup do
assert_equal 1, @wiki_page.position
assert_equal 2, @another_wiki_page.position
get :move_up, :course_id => @course.id, :id => @another_wiki_page.id
end
should redirect_to('the course page') { course_url(@course) }
should "move the page up" do
@wiki_page.reload
@another_wiki_page.reload
assert_equal 2, @wiki_page.position
assert_equal 1, @another_wiki_page.position
end
end
context "on get to :move_down" do
setup do
assert_equal 1, @wiki_page.position
assert_equal 2, @another_wiki_page.position
get :move_down, :course_id => @course.id, :id => @wiki_page.id
end
should redirect_to('the course page') { course_url(@course) }
should "move the page up" do
@wiki_page.reload
@another_wiki_page.reload
assert_equal 2, @wiki_page.position
assert_equal 1, @another_wiki_page.position
end
end
end
#def test_should accept_text_on_show
# get :show, :format => 'txt', :course_id => 1, :id => @wiki_page.id
# assert_formatted_response :text
#end #end
#
#def test_should accept_html_on_versions
# get :versions, :course_id => 1, :id => @wiki_page.id
# assert_response :success
#end #end
#
# #def test_should accept_text_on_show #def test_should accept_xml_on_versions
# # get :show, :format => 'txt', :course_id => 1, :id => @wiki_page.id # get :versions, :format => 'xml', :course_id => 1, :id => @wiki_page.id
# # assert_formatted_response :text # assert_formatted_response :xml, :versions
# #end
#
# #def test_should accept_html_on_versions
# # get :versions, :course_id => 1, :id => @wiki_page.id
# # assert_response :success
# #end
#
# #def test_should accept_xml_on_versions
# # get :versions, :format => 'xml', :course_id => 1, :id => @wiki_page.id
# # assert_formatted_response :xml, :versions
# #end
#end #end
# end

@ -1,4 +1,5 @@
#!/usr/bin/ruby # #!/usr/bin/ruby
# -*- encoding : utf-8 -*-
# #
# Bluecloth is a Ruby implementation of Markdown, a text-to-HTML conversion # Bluecloth is a Ruby implementation of Markdown, a text-to-HTML conversion
# tool. # tool.
@ -1032,7 +1033,7 @@ class BlueCloth < String
)? # title is optional )? # title is optional
\) \)
) )
}xs #" }x #"
# Reference-style images # Reference-style images
@ -1043,7 +1044,7 @@ class BlueCloth < String
(?:\n[ ]*)? # One optional newline + spaces (?:\n[ ]*)? # One optional newline + spaces
\[ (.*?) \] # id = $3 \[ (.*?) \] # id = $3
) )
}xs }x
### Turn image markup into image tags. ### Turn image markup into image tags.
def transform_images( str, rs ) def transform_images( str, rs )