added moderation tests for post test
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
class Post < ActiveRecord::Base
|
class Post < ActiveRecord::Base
|
||||||
attr_accessor :updater_id, :updater_ip_addr, :old_tag_string
|
attr_accessor :updater_id, :updater_ip_addr, :old_tag_string
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
belongs_to :uploader, :class_name => "User"
|
|
||||||
has_one :unapproval
|
has_one :unapproval
|
||||||
after_destroy :delete_files
|
after_destroy :delete_files
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
@@ -462,6 +461,14 @@ class Post < ActiveRecord::Base
|
|||||||
def uploader_id
|
def uploader_id
|
||||||
uploader_string[5, 100].to_i
|
uploader_string[5, 100].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uploader
|
||||||
|
User.find(uploader_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def uploader=(user)
|
||||||
|
self.uploader_id = user.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
include FileMethods
|
include FileMethods
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
Factory.define(:post) do |f|
|
Factory.define(:post) do |f|
|
||||||
f.md5 "abcd"
|
f.md5 {|x| Time.now.to_f.to_s}
|
||||||
f.uploader {|x| x.association(:user)}
|
f.uploader {|x| x.association(:user)}
|
||||||
f.uploader_ip_addr "127.0.0.1"
|
f.uploader_ip_addr "127.0.0.1"
|
||||||
|
f.updater_id {|x| x.uploader_id}
|
||||||
|
f.updater_ip_addr "127.0.0.1"
|
||||||
f.tag_string "tag1 tag2"
|
f.tag_string "tag1 tag2"
|
||||||
f.tag_count 2
|
f.tag_count 2
|
||||||
f.tag_count_general 2
|
f.tag_count_general 2
|
||||||
|
|||||||
@@ -1,5 +1,37 @@
|
|||||||
require File.dirname(__FILE__) + '/../test_helper'
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
class PostTest < ActiveSupport::TestCase
|
class PostTest < ActiveSupport::TestCase
|
||||||
|
context "During moderation a post" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
@user = Factory.create(:user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be unapproved once and only once" do
|
||||||
|
@post.unapprove!("bad", @user, "127.0.0.1")
|
||||||
|
assert(@post.is_flagged?, "Post should be flagged.")
|
||||||
|
assert_not_nil(@post.unapproval, "Post should have an unapproval record.")
|
||||||
|
assert_equal("bad", @post.unapproval.reason)
|
||||||
|
|
||||||
|
assert_raise(Unapproval::Error) {@post.unapprove!("bad", @user, "127.0.0.1")}
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not unapprove if no reason is given" do
|
||||||
|
assert_raise(Unapproval::Error) {@post.unapprove!("", @user, "127.0.0.1")}
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deleted" do
|
||||||
|
@post.delete!
|
||||||
|
assert(@post.is_deleted?, "Post should be deleted.")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be approved" do
|
||||||
|
@post.approve!
|
||||||
|
assert(!@post.is_pending?, "Post should not be pending.")
|
||||||
|
|
||||||
|
@deleted_post = Factory.create(:post, :is_deleted => true)
|
||||||
|
@deleted_post.approve!
|
||||||
|
assert(!@post.is_deleted?, "Post should not be deleted.")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user