added unapproval+upload functional test
This commit is contained in:
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
|
||||
|
||||
Factory.define(:jpg_upload, :parent => :upload) do |f|
|
||||
f.content_type "image/jpeg"
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.jpg"
|
||||
|
||||
@@ -1,8 +1,65 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UnapprovalsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The unapprovals controller" do
|
||||
setup do
|
||||
@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
|
||||
|
||||
@@ -1,8 +1,84 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UploadsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The uploads controller" do
|
||||
setup do
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user