added unapproval+upload functional test

This commit is contained in:
albert
2011-01-31 18:01:48 -05:00
parent 28b42e791c
commit df20d9233b
13 changed files with 174 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
class PostVersionsController < ApplicationController
def index
@search = PostVersion.search(params[:search])
@post_versions = @search.paginate(:page => params[:page], :per_page => 20, :order => "updated_at DESC")
@post_versions = @search.paginate(:page => params[:page], :order => "updated_at DESC")
end
end

View File

@@ -1,13 +1,32 @@
class UnapprovalsController < ApplicationController
before_filter :member_only
respond_to :html, :xml, :json
rescue_from User::PrivilegeError, :with => "static/access_denied"
def new
@unapproval = Unapproval.new
respond_with(@unapproval)
end
def index
@search = Unapproval.search(params[:search])
@unapprovals = @search.paginate(:page => params[:page])
end
def create
@unapproval = Unapproval.create(params[:unapproval])
respond_with(@unapproval)
end
def destroy
@unapproval = Unapproval.find(params[:id])
check_privilege(@unapproval)
@unapproval.destroy
respond_with(@unapproval)
end
private
def check_privilege(unapproval)
raise User::PrivilegeError unless (unapproval.unapprover_id == CurrentUser.id || CurrentUser.is_moderator?)
end
end

View File

@@ -11,7 +11,8 @@ class UploadsController < ApplicationController
end
def index
@uploads = Upload.where("uploader_id = ?", CurrentUser.user.id).includes(:uploader).order("uploads.id desc").limit(10)
@search = Upload.search(params[:search])
@uploads = @search.paginate(:page => params[:page])
respond_with(@uploads)
end

View File

@@ -3,4 +3,10 @@ class Unapproval < ActiveRecord::Base
belongs_to :unapprover, :class_name => "User"
validates_presence_of :reason, :unapprover_id, :unapprover_ip_addr
before_validation :initialize_unapprover, :on => :create
def initialize_unapprover
self.unapprover_id = CurrentUser.id
self.unapprover_ip_addr = CurrentUser.ip_addr
end
end

View File

@@ -12,6 +12,7 @@ class Upload < ActiveRecord::Base
before_create :convert_cgi_file
after_destroy :delete_temp_file
validate :uploader_is_not_limited
scope :uploaded_by, lambda {|user_id| where(["uploader_id = ?", user_id])}
module ValidationMethods
def uploader_is_not_limited
@@ -70,6 +71,7 @@ class Upload < ActiveRecord::Base
end
end
rescue Exception => x
raise
update_attribute(:status, "error: #{x} - #{x.message}")
ensure
delete_temp_file

View File

View File

View File

@@ -4,7 +4,7 @@
<p>Before uploading, please read the <%= link_to "how to upload guide", wiki_pages_path(:title => "howto:upload") %>.</p>
</div>
<% form_for(@upload, :html => {:multipart => true, :class => "simple_form"}) do |f| %>
<%= form_for(@upload, :html => {:multipart => true, :class => "simple_form"}) do |f| %>
<% if params[:url] %>
<div id="image-preview">
<%= image_tag(params[:url], :title => "Preview") %>