Testes para AttachmentsController

This commit is contained in:
2009-08-06 10:10:37 -03:00
parent 8611d1e9e6
commit f0394466e3
13 changed files with 199 additions and 28 deletions

View File

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

View File

@@ -23,6 +23,10 @@ class AttachmentsController < ApplicationController
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
def show
respond_to do |format|
format.html
format.xml { render :xml => @attachment }
end
end
def new
@@ -31,22 +35,20 @@ class AttachmentsController < ApplicationController
def create
@attachment.course_id = @course.id
@attachment.description = params[:attachment][:description]
unless params[:attachment][:file].kind_of?(String)
@attachment.file_name = "blank"
unless params[:attachment][:file].nil?
@attachment.file = params[:attachment][:file]
@attachment.file_name = params[:attachment][:file].original_filename
@attachment.content_type = params[:attachment][:file].content_type
end
@attachment.save!
# Verifica se o arquivo ja esta associado a outro anexo
#file_path = "#{RAILS_ROOT}/public/upload/#{@course.id}/#{@attachment.file_name}"
#@attachment.errors.add("file", "already exists") if File.exists?(file_path)
AttachmentCreateLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
flash[:notice] = 'Attachment created'[]
if @attachment.save
AttachmentCreateLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
flash[:notice] = 'Attachment created'[]
redirect_to :action => 'show', :id => @attachment.id
else
render :action => 'new'
respond_to do |format|
format.html { redirect_to course_attachment_url(@course, @attachment) }
format.xml { head :created, :location => course_attachment_url(@course, @attachment, :format => :xml) }
end
end
@@ -55,19 +57,23 @@ class AttachmentsController < ApplicationController
def update
@attachment.description = params[:attachment][:description]
unless params[:attachment][:file].kind_of?(String)
unless params[:attachment][:file].nil?
@attachment.file = params[:attachment][:file]
@attachment.file_name = params[:attachment][:file].original_filename
@attachment.content_type = params[:attachment][:file].content_type
end
changed = @attachment.changed?
if @attachment.save
AttachmentEditLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
if changed
@attachment.last_modified = Time.now.utc
@attachment.save!
AttachmentEditLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
flash[:notice] = 'Attachment updated'[]
redirect_to :action => 'show', :id => @attachment.id
else
render :action => 'edit'
end
respond_to do |format|
format.html { redirect_to course_attachment_url(@course, @attachment) }
format.xml { head :created, :location => course_attachment_url(@course, @attachment, :format => :xml) }
end
end
@@ -75,8 +81,13 @@ class AttachmentsController < ApplicationController
@attachment.destroy
flash[:notice] = 'Attachment removed'[]
flash[:undo] = undelete_course_attachment_url(@course, @attachment)
AttachmentDeleteLogEntry.create!(:target_id => @attachment.id, :user => @current_user, :course => @course)
redirect_to :controller => 'courses', :action => 'show', :id => @course
respond_to do |format|
format.html { redirect_to course_url(@course) }
format.xml { head :ok }
end
end
def download

View File

@@ -73,9 +73,9 @@ class WikiController < ApplicationController
@wiki_page.user_id = session[:user_id]
@wiki_page.course_id = @course.id
changed = @wiki_page.changed?
@wiki_page.save!
if changed
@wiki_page.save!
WikiEditLogEntry.create!(:target_id => @wiki_page.id, :user => @current_user, :course => @course, :version => @wiki_page.version)
flash[:notice] = "Wiki page updated"[]
end

View File

@@ -31,6 +31,7 @@ class Attachment < ActiveRecord::Base
def file=(new_file)
@tmp_file = new_file
self.size = new_file.size
self.content_type ||= "application/octet-stream"
end
protected

View File

@@ -8,7 +8,7 @@
%p
%dl
%dt Arquivo
%dd= link_to h(@attachment.file_name), download_course_attachment_url
%dd= link_to h(@attachment.file_name), download_course_attachment_url(@course, @attachment)
%dt Descrição
%dd= h(@attachment.description)