added unapproval+upload functional test
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class PostVersionsController < ApplicationController
|
class PostVersionsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@search = PostVersion.search(params[:search])
|
@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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,13 +1,32 @@
|
|||||||
class UnapprovalsController < ApplicationController
|
class UnapprovalsController < ApplicationController
|
||||||
|
before_filter :member_only
|
||||||
|
respond_to :html, :xml, :json
|
||||||
|
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@unapproval = Unapproval.new
|
||||||
|
respond_with(@unapproval)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@search = Unapproval.search(params[:search])
|
||||||
|
@unapprovals = @search.paginate(:page => params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@unapproval = Unapproval.create(params[:unapproval])
|
||||||
|
respond_with(@unapproval)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ class UploadsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
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)
|
respond_with(@uploads)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,10 @@ class Unapproval < ActiveRecord::Base
|
|||||||
|
|
||||||
belongs_to :unapprover, :class_name => "User"
|
belongs_to :unapprover, :class_name => "User"
|
||||||
validates_presence_of :reason, :unapprover_id, :unapprover_ip_addr
|
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
|
end
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Upload < ActiveRecord::Base
|
|||||||
before_create :convert_cgi_file
|
before_create :convert_cgi_file
|
||||||
after_destroy :delete_temp_file
|
after_destroy :delete_temp_file
|
||||||
validate :uploader_is_not_limited
|
validate :uploader_is_not_limited
|
||||||
|
scope :uploaded_by, lambda {|user_id| where(["uploader_id = ?", user_id])}
|
||||||
|
|
||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def uploader_is_not_limited
|
def uploader_is_not_limited
|
||||||
@@ -70,6 +71,7 @@ class Upload < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => x
|
rescue Exception => x
|
||||||
|
raise
|
||||||
update_attribute(:status, "error: #{x} - #{x.message}")
|
update_attribute(:status, "error: #{x} - #{x.message}")
|
||||||
ensure
|
ensure
|
||||||
delete_temp_file
|
delete_temp_file
|
||||||
|
|||||||
0
app/views/unapprovals/index.html.erb
Normal file
0
app/views/unapprovals/index.html.erb
Normal file
0
app/views/unapprovals/new.html.erb
Normal file
0
app/views/unapprovals/new.html.erb
Normal file
@@ -4,7 +4,7 @@
|
|||||||
<p>Before uploading, please read the <%= link_to "how to upload guide", wiki_pages_path(:title => "howto:upload") %>.</p>
|
<p>Before uploading, please read the <%= link_to "how to upload guide", wiki_pages_path(:title => "howto:upload") %>.</p>
|
||||||
</div>
|
</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] %>
|
<% if params[:url] %>
|
||||||
<div id="image-preview">
|
<div id="image-preview">
|
||||||
<%= image_tag(params[:url], :title => "Preview") %>
|
<%= image_tag(params[:url], :title => "Preview") %>
|
||||||
|
|||||||
3
test/factories/unapproval.rb
Normal file
3
test/factories/unapproval.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Factory.define(:unapproval) do |f|
|
||||||
|
f.post {|x| x.association(:post)}
|
||||||
|
end
|
||||||
@@ -13,6 +13,7 @@ Factory.define(:source_upload, :parent => :upload) do |f|
|
|||||||
end
|
end
|
||||||
|
|
||||||
Factory.define(:jpg_upload, :parent => :upload) do |f|
|
Factory.define(:jpg_upload, :parent => :upload) do |f|
|
||||||
|
f.content_type "image/jpeg"
|
||||||
f.file_path do
|
f.file_path do
|
||||||
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
||||||
"#{Rails.root}/tmp/test.jpg"
|
"#{Rails.root}/tmp/test.jpg"
|
||||||
|
|||||||
@@ -1,8 +1,65 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class UnapprovalsControllerTest < ActionController::TestCase
|
class UnapprovalsControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "The unapprovals controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
@user = Factory.create(:user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context "new action" do
|
||||||
|
should "render" do
|
||||||
|
get :new, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
setup do
|
||||||
|
@unapproval = Factory.create(:unapproval)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
get :index, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with search parameters" do
|
||||||
|
should "render" do
|
||||||
|
get :index, {:search => {:post_id_equals => @unapproval.post_id}}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "create a new unapproval" do
|
||||||
|
assert_difference("Unapproval.count", 1) do
|
||||||
|
post :create, {:post_id => @post.id, :reason => "xxx"}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
setup do
|
||||||
|
@unapproval = Factory.create(:unapproval)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "delete an unapproval" do
|
||||||
|
assert_difference "Unapproval.count", -1 do
|
||||||
|
post :destroy, {:id => @unapproval.id}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,84 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class UploadsControllerTest < ActionController::TestCase
|
class UploadsControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "The uploads controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
@user = Factory.create(:user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context "new action" do
|
||||||
|
should "render" do
|
||||||
|
get :new, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a post that has already been uploaded" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post, :source => "aaa")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "initialize the post" do
|
||||||
|
get :new, {:url => "aaa"}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil(assigns(:post))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
setup do
|
||||||
|
@upload = Factory.create(:source_upload)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
get :index, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with search parameters" do
|
||||||
|
should "render" do
|
||||||
|
get :index, {:search => {:source_equals => @upload.source}}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "show action" do
|
||||||
|
setup do
|
||||||
|
@upload = Factory.create(:jpg_upload)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
get :show, {:id => @upload.id}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "create a new upload" do
|
||||||
|
assert_difference("Upload.count", 1) do
|
||||||
|
post :create, {:upload => {:file => upload_jpeg("#{Rails.root}/test/files/test.jpg"), :tag_string => "aaa", :rating => "q", :source => "aaa"}}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
setup do
|
||||||
|
@upload = Factory.create(:jpg_upload)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "process an unapproval" do
|
||||||
|
post :update, {:id => @upload.id}, {:user_id => @user.id}
|
||||||
|
@upload.reload
|
||||||
|
assert_equal("completed", @upload.status)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
tmp/test.jpg
BIN
tmp/test.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB |
Reference in New Issue
Block a user