fixed unit tests
This commit is contained in:
@@ -93,7 +93,7 @@ class Pool < ActiveRecord::Base
|
|||||||
def neighbor_posts(post)
|
def neighbor_posts(post)
|
||||||
@neighbor_posts ||= begin
|
@neighbor_posts ||= begin
|
||||||
post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/
|
post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/
|
||||||
|
|
||||||
if $2 && $3
|
if $2 && $3
|
||||||
{:previous => $2.to_i, :next => $3.to_i}
|
{:previous => $2.to_i, :next => $3.to_i}
|
||||||
elsif $1
|
elsif $1
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def flag!(reason)
|
def flag!(reason)
|
||||||
flag = create_flag(:reason => reason)
|
flag = flags.create(:reason => reason)
|
||||||
|
|
||||||
if flag.errors.any?
|
if flag.errors.any?
|
||||||
raise PostFlag::Error.new(flag.errors.full_messages.join("; "))
|
raise PostFlag::Error.new(flag.errors.full_messages.join("; "))
|
||||||
@@ -230,7 +230,7 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def appeal!(reason)
|
def appeal!(reason)
|
||||||
appeal = create_appeal(:reason => reason)
|
appeal = appeals.create(:reason => reason)
|
||||||
|
|
||||||
if appeal.errors.any?
|
if appeal.errors.any?
|
||||||
raise PostAppeal::Error.new(appeal.errors.full_messages.join("; "))
|
raise PostAppeal::Error.new(appeal.errors.full_messages.join("; "))
|
||||||
|
|||||||
@@ -1089,6 +1089,7 @@ CREATE TABLE post_flags (
|
|||||||
creator_id integer NOT NULL,
|
creator_id integer NOT NULL,
|
||||||
creator_ip_addr inet NOT NULL,
|
creator_ip_addr inet NOT NULL,
|
||||||
reason text,
|
reason text,
|
||||||
|
is_resolved boolean DEFAULT false NOT NULL,
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone
|
updated_at timestamp without time zone
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -85,12 +85,9 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "search on other names should return matches" do
|
should "search on other names should return matches" do
|
||||||
artist = Factory.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd")
|
artist = Factory.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd")
|
||||||
assert_not_nil(Artist.find_by_any_name("name:artist"))
|
assert_nil(Artist.other_names_match("artist").first)
|
||||||
assert_nil(Artist.find_by_any_name("name:aaa"))
|
assert_not_nil(Artist.other_names_match("aaa").first)
|
||||||
assert_nil(Artist.find_by_any_name("name:ccc_ddd"))
|
assert_not_nil(Artist.other_names_match("ccc_ddd").first)
|
||||||
assert_nil(Artist.find_by_any_name("other:artist"))
|
|
||||||
assert_not_nil(Artist.find_by_any_name("other:aaa"))
|
|
||||||
assert_not_nil(Artist.find_by_any_name("other:ccc_ddd"))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "search on group name and return matches" do
|
should "search on group name and return matches" do
|
||||||
@@ -98,7 +95,7 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
yuu = Factory.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
|
yuu = Factory.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
|
||||||
cat_or_fish.reload
|
cat_or_fish.reload
|
||||||
assert_equal("yuu", cat_or_fish.member_names)
|
assert_equal("yuu", cat_or_fish.member_names)
|
||||||
assert_not_nil(Artist.find_by_any_name("group:cat_or_fish"))
|
assert_not_nil(Artist.search(:group_name_contains => "cat_or_fish").first)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have an associated wiki" do
|
should "have an associated wiki" do
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class CommentTest < ActiveSupport::TestCase
|
|||||||
c2 = Factory.create(:comment, :body => "aaa ddd")
|
c2 = Factory.create(:comment, :body => "aaa ddd")
|
||||||
c3 = Factory.create(:comment, :body => "eee")
|
c3 = Factory.create(:comment, :body => "eee")
|
||||||
|
|
||||||
matches = Comment.search_body("aaa")
|
matches = Comment.body_matches("aaa")
|
||||||
assert_equal(2, matches.count)
|
assert_equal(2, matches.count)
|
||||||
assert_equal(c2.id, matches.all[0].id)
|
assert_equal(c2.id, matches.all[0].id)
|
||||||
assert_equal(c1.id, matches.all[1].id)
|
assert_equal(c1.id, matches.all[1].id)
|
||||||
|
|||||||
@@ -68,13 +68,18 @@ class PoolTest < ActiveSupport::TestCase
|
|||||||
pool.add_post!(p1)
|
pool.add_post!(p1)
|
||||||
pool.add_post!(p2)
|
pool.add_post!(p2)
|
||||||
pool.add_post!(p3)
|
pool.add_post!(p3)
|
||||||
|
|
||||||
pool.reload
|
pool.reload
|
||||||
neighbors = pool.neighbor_posts(p1)
|
neighbors = pool.neighbor_posts(p1)
|
||||||
assert_nil(neighbors[:previous])
|
assert_nil(neighbors[:previous])
|
||||||
assert_equal(p2.id, neighbors[:next])
|
assert_equal(p2.id, neighbors[:next])
|
||||||
|
|
||||||
|
pool.reload
|
||||||
neighbors = pool.neighbor_posts(p2)
|
neighbors = pool.neighbor_posts(p2)
|
||||||
assert_equal(p1.id, neighbors[:previous])
|
assert_equal(p1.id, neighbors[:previous])
|
||||||
assert_equal(p3.id, neighbors[:next])
|
assert_equal(p3.id, neighbors[:next])
|
||||||
|
|
||||||
|
pool.reload
|
||||||
neighbors = pool.neighbor_posts(p3)
|
neighbors = pool.neighbor_posts(p3)
|
||||||
assert_equal(p2.id, neighbors[:previous])
|
assert_equal(p2.id, neighbors[:previous])
|
||||||
assert_nil(neighbors[:next])
|
assert_nil(neighbors[:next])
|
||||||
|
|||||||
@@ -140,19 +140,37 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "Moderation:" do
|
context "Moderation:" do
|
||||||
|
context "A deleted post" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post, :is_deleted => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be appealed" do
|
||||||
|
assert_difference("PostAppeal.count", 1) do
|
||||||
|
@post.appeal!("xxx")
|
||||||
|
end
|
||||||
|
assert(@post.is_deleted?, "Post should still be deleted")
|
||||||
|
assert_equal(1, @post.appeals.count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "An approved post" do
|
context "An approved post" do
|
||||||
should "be unapproved once and only once" do
|
should "be flagged" do
|
||||||
post = Factory.create(:post)
|
post = Factory.create(:post)
|
||||||
post.unapprove!("bad")
|
assert_difference("PostFlag.count", 1) do
|
||||||
|
post.flag!("bad")
|
||||||
|
end
|
||||||
assert(post.is_flagged?, "Post should be flagged.")
|
assert(post.is_flagged?, "Post should be flagged.")
|
||||||
assert_not_nil(post.unapproval, "Post should have an unapproval record.")
|
assert_equal(1, post.flags.count)
|
||||||
assert_equal("bad", post.unapproval.reason)
|
|
||||||
assert_raise(Unapproval::Error) {post.unapprove!("bad")}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not unapprove if no reason is given" do
|
should "not be flagged if no reason is given" do
|
||||||
post = Factory.create(:post)
|
post = Factory.create(:post)
|
||||||
assert_raise(Unapproval::Error) {post.unapprove!("")}
|
assert_difference("PostFlag.count", 0) do
|
||||||
|
assert_raises(PostFlag::Error) do
|
||||||
|
post.flag!("")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -167,7 +185,7 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
should "not allow person X to reapprove that post" do
|
should "not allow person X to reapprove that post" do
|
||||||
user = Factory.create(:janitor_user, :name => "xxx")
|
user = Factory.create(:janitor_user, :name => "xxx")
|
||||||
post = Factory.create(:post, :approver_string => "approver:xxx")
|
post = Factory.create(:post, :approver_string => "approver:xxx")
|
||||||
post.unapprove!("bad")
|
post.flag!("bad")
|
||||||
CurrentUser.scoped(user, "127.0.0.1") do
|
CurrentUser.scoped(user, "127.0.0.1") do
|
||||||
assert_raises(Post::ApprovalError) do
|
assert_raises(Post::ApprovalError) do
|
||||||
post.approve!
|
post.approve!
|
||||||
@@ -179,20 +197,13 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
context "that has been reapproved" do
|
context "that has been reapproved" do
|
||||||
should "no longer be flagged or pending" do
|
should "no longer be flagged or pending" do
|
||||||
post = Factory.create(:post)
|
post = Factory.create(:post)
|
||||||
post.unapprove!("bad")
|
post.flag!("bad")
|
||||||
post.approve!
|
post.approve!
|
||||||
assert(post.errors.empty?, post.errors.full_messages.join(", "))
|
assert(post.errors.empty?, post.errors.full_messages.join(", "))
|
||||||
post.reload
|
post.reload
|
||||||
assert_equal(false, post.is_flagged?)
|
assert_equal(false, post.is_flagged?)
|
||||||
assert_equal(false, post.is_pending?)
|
assert_equal(false, post.is_pending?)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "cannot be unapproved again" do
|
|
||||||
post = Factory.create(:post)
|
|
||||||
post.unapprove!("bad")
|
|
||||||
post.approve!
|
|
||||||
assert_raise(Unapproval::Error) {post.unapprove!("bad")}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user