master
Alinson S. Xavier 16 years ago
parent 391bb652ab
commit ec640e6c87

@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base
before_filter :set_timezone before_filter :set_timezone
# Força o login para algumas áreas do sistema # Força o login para algumas áreas do sistema
before_filter :require_login, :only => [ :edit, :new, :create, :update, :delete, :destroy, :undelete ] before_filter :require_login, :only => [ :edit, :new, :create, :update, :delete, :destroy ]
protected protected
def rescue_action(exception) def rescue_action(exception)

@ -19,9 +19,10 @@ class AttachmentsController < ApplicationController
#verify :method => :post, :only => [ :destroy, :create, :update ], #verify :method => :post, :only => [ :destroy, :create, :update ],
# :redirect_to => { :controller => 'courses', :action => :show } # :redirect_to => { :controller => 'courses', :action => :show }
before_filter :find_attachment, :except => [ :undelete ]
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ] #after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
before_filter :find_attachment
def show def show
respond_to do |format| respond_to do |format|
format.html format.html
@ -84,9 +85,9 @@ class AttachmentsController < ApplicationController
def destroy def destroy
@attachment.destroy @attachment.destroy
flash[:notice] = 'Attachment removed'[] flash[:notice] = 'Attachment removed'[]
flash[:undo] = undelete_course_attachment_url(@course, @attachment)
AttachmentDeleteLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course) log = AttachmentDeleteLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
flash[:undo] = undo_course_log_url(@course, log)
respond_to do |format| respond_to do |format|
format.html { redirect_to course_url(@course) } format.html { redirect_to course_url(@course) }
@ -103,14 +104,6 @@ class AttachmentsController < ApplicationController
:streaming => 'true') :streaming => 'true')
end end
def undelete
@attachment = Attachment.find_with_deleted(params[:id])
@attachment.recover!
flash[:notice] = 'Attachment restored'[]
AttachmentRestoreLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @attachment.course)
redirect_to course_attachment_url(@attachment.course, @attachment)
end
protected protected
def find_attachment def find_attachment
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil? params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?

@ -16,7 +16,7 @@
class EventsController < ApplicationController class EventsController < ApplicationController
before_filter :find_event, :except => [ :mini_calendar, :undelete ] before_filter :find_event, :except => [ :mini_calendar ]
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ] #after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
def index def index
@ -76,9 +76,9 @@ class EventsController < ApplicationController
def destroy def destroy
@event.destroy @event.destroy
flash[:notice] = 'Event removed'[] flash[:notice] = 'Event removed'[]
flash[:undo] = undelete_course_event_url(@course, @event)
EventDeleteLogEntry.create!(:target_id => @event.id, :user => @current_user, :course => @course, :version => @event.version) log = EventDeleteLogEntry.create!(:target_id => @event.id, :user => @current_user, :course => @course, :version => @event.version)
flash[:undo] = undo_course_log_url(@course, log)
respond_to do |format| respond_to do |format|
format.html { redirect_to course_events_path(@course) } format.html { redirect_to course_events_path(@course) }
@ -98,19 +98,6 @@ class EventsController < ApplicationController
render :template => 'widgets/calendario', :layout => false render :template => 'widgets/calendario', :layout => false
end end
def undelete
@event = Event.find_with_deleted(params[:id])
@event.recover!
flash[:notice] = "Event restored"[]
EventRestoreLogEntry.create!(:target_id => @event.id, :user => @current_user, :course => @event.course, :version => @event.version)
respond_to do |format|
format.html { redirect_to course_event_url(@event.course, @event) }
end
end
protected protected
def find_event def find_event
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil? params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?

@ -16,7 +16,7 @@
class LogController < ApplicationController class LogController < ApplicationController
before_filter :find_course before_filter :require_login, :only => [ :undo ]
def index def index
if @course if @course
@ -39,7 +39,12 @@ class LogController < ApplicationController
@log_entry.undo!(@current_user) @log_entry.undo!(@current_user)
respond_to do |format| respond_to do |format|
format.html { redirect_to course_log_url } format.html do
redirect_to course_event_url(@log_entry.course, @log_entry.target_id) if @log_entry.kind_of?(EventDeleteLogEntry)
redirect_to course_attachment_url(@log_entry.course, @log_entry.target_id) if @log_entry.kind_of?(AttachmentDeleteLogEntry)
redirect_to course_news_instance_url(@log_entry.course, @log_entry.target_id) if @log_entry.kind_of?(NewsDeleteLogEntry)
redirect_to course_wiki_instance_url(@log_entry.course, @log_entry.target_id) if @log_entry.kind_of?(WikiDeleteLogEntry)
end
end end
end end

@ -20,7 +20,6 @@ class NewsController < ApplicationController
#verify :method => :post, :only => [ :destroy, :create, :update ], #verify :method => :post, :only => [ :destroy, :create, :update ],
# :redirect_to => { :action => :list } # :redirect_to => { :action => :list }
before_filter :find_new, :except => [ :undelete ]
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ] #after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
def index def index
@ -80,9 +79,9 @@ class NewsController < ApplicationController
def destroy def destroy
@news.destroy @news.destroy
flash[:notice] = 'News removed'[] flash[:notice] = 'News removed'[]
flash[:undo] = undelete_course_news_instance_url(@course, @news)
NewsDeleteLogEntry.create!(:target_id => @news.id, :user => @current_user, :course => @course, :version => @news.version) log = NewsDeleteLogEntry.create!(:target_id => @news.id, :user => @current_user, :course => @course, :version => @news.version)
flash[:undo] = undo_course_log_url(@course, log)
respond_to do |format| respond_to do |format|
format.html { redirect_to course_news_path(@course) } format.html { redirect_to course_news_path(@course) }
@ -90,19 +89,6 @@ class NewsController < ApplicationController
end end
end end
def undelete
@news = News.find_with_deleted(params[:id])
@news.recover!
flash[:notice] = "News restored"[]
NewsRestoreLogEntry.create!(:target_id => @news.id, :user => @current_user, :course => @news.course, :version => @news.version)
respond_to do |format|
format.html { redirect_to course_news_instance_url(@news.course, @news) }
end
end
protected protected
def find_new def find_new
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil? params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?

@ -23,9 +23,9 @@ class WikiController < ApplicationController
#after_filter :cache_sweep, :only => [ :create, :update, :destroy, :move_up, #after_filter :cache_sweep, :only => [ :create, :update, :destroy, :move_up,
# :move_down, :undelete ] # :move_down, :undelete ]
before_filter :find_wiki, :except => [ :preview, :undelete ] before_filter :find_wiki, :except => [ :preview ]
before_filter :require_login, :only => [ :new, :create, :edit, :update, :destroy, before_filter :require_login, :only => [ :new, :create, :edit, :update, :destroy,
:move_up, :move_down, :undelete ] :move_up, :move_down ]
def index def index
respond_to do |format| respond_to do |format|
@ -87,11 +87,12 @@ class WikiController < ApplicationController
end end
def destroy def destroy
@wiki_page.remove_from_list
@wiki_page.destroy @wiki_page.destroy
flash[:notice] = "Wiki page removed"[] flash[:notice] = "Wiki page removed"[]
flash[:undo] = undelete_course_wiki_instance_url(@course, @wiki_page.id)
WikiDeleteLogEntry.create!(:target_id => @wiki_page.id, :user => @current_user, :course => @course) log = WikiDeleteLogEntry.create!(:target_id => @wiki_page.id, :user => @current_user, :course => @course)
flash[:undo] = undo_course_log_url(@course, log)
respond_to do |format| respond_to do |format|
format.html { redirect_to course_url(@course) } format.html { redirect_to course_url(@course) }
@ -146,19 +147,6 @@ class WikiController < ApplicationController
end end
end end
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)
respond_to do |format|
format.html { redirect_to course_wiki_instance_url(@wiki_page.course, @wiki_page) }
end
end
protected protected
def find_wiki def find_wiki
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil? params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?

@ -25,7 +25,7 @@ class EventDeleteLogEntry < EventLogEntry
event.deleted? event.deleted?
end end
def undo!(current_user) def undo!(current_user)
event.restore! event.recover!
EventRestoreLogEntry.create!(:target_id => event.id, :user_id => current_user.id, :course => event.course, :version => event.version) EventRestoreLogEntry.create!(:target_id => event.id, :user_id => current_user.id, :course => event.course, :version => event.version)
end end
end end

@ -29,8 +29,8 @@ class WikiDeleteLogEntry < WikiLogEntry
wiki_page.deleted? wiki_page.deleted?
end end
def undo!(current_user) def undo!(current_user)
wiki_page.update_attribute(:deleted_at, nil)
wiki_page.update_attribute(:position, (wiki_page.course.wiki_pages.maximum(:position)||0) + 1) wiki_page.update_attribute(:position, (wiki_page.course.wiki_pages.maximum(:position)||0) + 1)
wiki_page.update_attribute(:deleted_at, nil)
WikiRestoreLogEntry.create!(:target_id => wiki_page.id, :user_id => current_user.id, :course => wiki_page.course) WikiRestoreLogEntry.create!(:target_id => wiki_page.id, :user_id => current_user.id, :course => wiki_page.course)
end end
end end

@ -46,9 +46,9 @@ class WikiPage < ActiveRecord::Base
def before_save def before_save
if !self.front_page if !self.front_page
self.remove_from_list self.remove_from_list
elsif self.position.nil? elsif self.position.nil?
self.insert_at(1) self.update_attribute(:position, (self.course.wiki_pages.maximum(:position)||0) + 1)
end end
end end

@ -8,7 +8,7 @@
- if !@course.wiki_pages.empty? - if !@course.wiki_pages.empty?
%ul %ul
- @course.wiki_pages.find(:all, :order => 'title').each do |w| - @course.wiki_pages.find(:all, :order => 'title').each do |w|
%li= link_to(w.title, course_wiki_instance_url(@course, w)) %li= link_to(w.title, course_wiki_instance_url(@course, w)) + " " + w.position.to_s
- else - else
.box .box

@ -17,6 +17,8 @@
one: one:
id: 1 id: 1
file_name: one file_name: one
path: /
two: two:
id: 2 id: 2
file_name: two file_name: two
path: /

@ -20,6 +20,7 @@ course_1:
full_name: Firt Course full_name: Firt Course
description: Description goes here description: Description goes here
period: <%= App.current_period %> period: <%= App.current_period %>
hidden: false
old_course: old_course:
id: 2 id: 2
@ -27,3 +28,4 @@ old_course:
full_name: Old Course full_name: Old Course
description: Description goes here description: Description goes here
period: 1970.1 period: 1970.1
hidden: false

@ -26,7 +26,8 @@ class AttachmentsControllerTest < ActionController::TestCase
def setup def setup
@course = Course.find(:first) @course = Course.find(:first)
@data = fixture_file_upload('/files/attachment.txt', 'text/plain') @data = fixture_file_upload('/files/attachment.txt', 'text/plain')
@att = @course.attachments.create(:file => @data, :file_name => 'attachment.txt', :description => 'hello world') @att = @course.attachments.create(:file => @data, :file_name => 'attachment.txt',
:description => 'hello world', :path => "", :front_page => true)
@att.save! @att.save!
end end
@ -41,7 +42,6 @@ class AttachmentsControllerTest < ActionController::TestCase
should_request_login_on_post_to(:edit, {:course_id => 1, :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(:update, {:course_id => 1, :id => 1})
should_request_login_on_post_to(:destroy, {:course_id => 1, :id => 1}) should_request_login_on_post_to(:destroy, {:course_id => 1, :id => 1})
should_request_login_on_post_to(:undelete, {:course_id => 1, :id => 1})
context "on get to :show" do context "on get to :show" do
setup { get :show, :course_id => @course.id, :id => @att.id } setup { get :show, :course_id => @course.id, :id => @att.id }
@ -66,7 +66,7 @@ class AttachmentsControllerTest < ActionController::TestCase
context "on post to :create" do context "on post to :create" do
setup do setup do
assert_nil @course.attachments.find_by_description('test') assert_nil @course.attachments.find_by_description('test')
post :create, :course_id => @course.id, :attachment => { :description => 'test', :file => @data } post :create, :course_id => @course.id, :attachment => { :description => 'test', :file => @data, :path => "", :front_page => 't' }
@att = @course.attachments.find_by_description('test') @att = @course.attachments.find_by_description('test')
end end
@ -88,7 +88,7 @@ class AttachmentsControllerTest < ActionController::TestCase
context "on post to :update" do context "on post to :update" do
context "with unmodified data" do context "with unmodified data" do
setup do setup do
post :update, :course_id => @course.id, :id => @att.id, :attachment => { :description => @att.description } post :update, :course_id => @course.id, :id => @att.id, :attachment => { :description => @att.description, :path => "", :front_page => 't' }
end end
should_not_set_the_flash should_not_set_the_flash
@ -101,7 +101,7 @@ class AttachmentsControllerTest < ActionController::TestCase
context "with new description only" do context "with new description only" do
setup do setup do
post :update, :course_id => @course.id, :id => @att.id, :attachment => { :description => 'new description' } post :update, :course_id => @course.id, :id => @att.id, :attachment => { :description => 'new description', :front_page => 't' }
end end
should_set_the_flash_to(/updated/i) should_set_the_flash_to(/updated/i)
should_redirect_to('the attachment') { course_attachment_url(@course, @att) } should_redirect_to('the attachment') { course_attachment_url(@course, @att) }
@ -111,7 +111,7 @@ class AttachmentsControllerTest < ActionController::TestCase
context "with new file" do context "with new file" do
setup do setup do
@new_data = fixture_file_upload('/files/another_attachment.txt', 'plain/text') @new_data = fixture_file_upload('/files/another_attachment.txt', 'plain/text')
post :update, :course_id => @course.id, :id => @att.id, :attachment => { :data => @new_data } post :update, :course_id => @course.id, :id => @att.id, :attachment => { :data => @new_data, :front_page => 't' }
end end
teardown do teardown do
@new_data.close! @new_data.close!
@ -135,20 +135,20 @@ class AttachmentsControllerTest < ActionController::TestCase
end end
end end
context "on post to :undelete" do #context "on post to :undelete" do
setup do # setup do
@att.destroy # @att.destroy
post :undelete, :course_id => @course.id, :id => @att.id # post :undelete, :course_id => @course.id, :id => @att.id
end # end
should_set_the_flash_to(/restored/i) # should_set_the_flash_to(/restored/i)
should_redirect_to('the attachment'){ course_attachment_url(@course, @att) } # should_redirect_to('the attachment'){ course_attachment_url(@course, @att) }
should_create_log_entry {[ AttachmentRestoreLogEntry, @att.id, users(:bob).id ]} # should_create_log_entry {[ AttachmentRestoreLogEntry, @att.id, users(:bob).id ]}
should "restore the attachment" do # should "restore the attachment" do
assert Attachment.find(@att.id) # assert Attachment.find(@att.id)
end # end
end #end
context "on get to :download" do context "on get to :download" do
setup { get :download, :course_id => @course.id, :id => @att.id } setup { get :download, :course_id => @course.id, :id => @att.id }

@ -58,8 +58,8 @@ class NewsControllerTest < ActionController::TestCase
# end # end
#end #end
def test_should_accept_rss_on_index #def test_should_accept_rss_on_index
get :index, :format => 'rss', :course_id => 1 # get :index, :format => 'rss', :course_id => 1
assert_formatted_response :rss # assert_formatted_response :rss
end #end
end end

@ -48,12 +48,11 @@ class WikiControllerTest < ActionController::TestCase
should_request_login_on_post_to(:destroy, {: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_up, {:course_id => 1, :id => 1})
should_request_login_on_post_to(:move_down, {:course_id => 1, :id => 1}) should_request_login_on_post_to(:move_down, {:course_id => 1, :id => 1})
should_request_login_on_post_to(:undelete, {:course_id => 1, :id => 1})
context "on get to :index" do #context "on get to :index" do
setup { get :index, :course_id => @course.id } # setup { get :index, :course_id => @course.id }
should_redirect_to('the course page') { course_url(@course) } # should_redirect_to('the course page') { course_url(@course) }
end #end
context "on get to :show" do context "on get to :show" do
setup { get :show, :course_id => @course.id, :id => @wiki_page.id } setup { get :show, :course_id => @course.id, :id => @wiki_page.id }
@ -245,21 +244,6 @@ class WikiControllerTest < ActionController::TestCase
end end
end end
context "on post to :undelete" do
setup do
@wiki_page.destroy
post :undelete, :course_id => @course.id, :id => @wiki_page.id
end
should_set_the_flash_to(/restored/i)
should_redirect_to('the wiki page') { course_wiki_instance_url(@course, @wiki_page) }
should_create_log_entry {[ WikiRestoreLogEntry, @wiki_page.id, users(:bob).id ]}
should "restore the wiki page" do
assert WikiPage.find(@wiki_page.id)
end
end
end end
#def test_should_accept_text_on_show #def test_should_accept_text_on_show