diff --git a/app/models/pool.rb b/app/models/pool.rb index 668a514b0..85ff2c492 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -93,7 +93,7 @@ class Pool < ActiveRecord::Base def neighbor_posts(post) @neighbor_posts ||= begin post_ids =~ /\A#{post.id} (\d+)|(\d+) #{post.id} (\d+)|(\d+) #{post.id}\Z/ - + if $2 && $3 {:previous => $2.to_i, :next => $3.to_i} elsif $1 diff --git a/app/models/post.rb b/app/models/post.rb index 5928f0b42..69427c5ed 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -220,7 +220,7 @@ class Post < ActiveRecord::Base end def flag!(reason) - flag = create_flag(:reason => reason) + flag = flags.create(:reason => reason) if flag.errors.any? raise PostFlag::Error.new(flag.errors.full_messages.join("; ")) @@ -230,7 +230,7 @@ class Post < ActiveRecord::Base end def appeal!(reason) - appeal = create_appeal(:reason => reason) + appeal = appeals.create(:reason => reason) if appeal.errors.any? raise PostAppeal::Error.new(appeal.errors.full_messages.join("; ")) diff --git a/db/development_structure.sql b/db/development_structure.sql index 228244488..8f8abf8b3 100644 --- a/db/development_structure.sql +++ b/db/development_structure.sql @@ -1089,6 +1089,7 @@ CREATE TABLE post_flags ( creator_id integer NOT NULL, creator_ip_addr inet NOT NULL, reason text, + is_resolved boolean DEFAULT false NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone ); diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 691deb130..8bfd513e9 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -85,12 +85,9 @@ class ArtistTest < ActiveSupport::TestCase should "search on other names should return matches" do artist = Factory.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd") - assert_not_nil(Artist.find_by_any_name("name:artist")) - assert_nil(Artist.find_by_any_name("name:aaa")) - assert_nil(Artist.find_by_any_name("name:ccc_ddd")) - 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")) + assert_nil(Artist.other_names_match("artist").first) + assert_not_nil(Artist.other_names_match("aaa").first) + assert_not_nil(Artist.other_names_match("ccc_ddd").first) end 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") cat_or_fish.reload 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 should "have an associated wiki" do diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index c282d7019..f8d6460bf 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -59,7 +59,7 @@ class CommentTest < ActiveSupport::TestCase c2 = Factory.create(:comment, :body => "aaa ddd") c3 = Factory.create(:comment, :body => "eee") - matches = Comment.search_body("aaa") + matches = Comment.body_matches("aaa") assert_equal(2, matches.count) assert_equal(c2.id, matches.all[0].id) assert_equal(c1.id, matches.all[1].id) diff --git a/test/unit/pool_test.rb b/test/unit/pool_test.rb index 5cd6ab13f..72f5a7779 100644 --- a/test/unit/pool_test.rb +++ b/test/unit/pool_test.rb @@ -68,13 +68,18 @@ class PoolTest < ActiveSupport::TestCase pool.add_post!(p1) pool.add_post!(p2) pool.add_post!(p3) + pool.reload neighbors = pool.neighbor_posts(p1) assert_nil(neighbors[:previous]) assert_equal(p2.id, neighbors[:next]) + + pool.reload neighbors = pool.neighbor_posts(p2) assert_equal(p1.id, neighbors[:previous]) assert_equal(p3.id, neighbors[:next]) + + pool.reload neighbors = pool.neighbor_posts(p3) assert_equal(p2.id, neighbors[:previous]) assert_nil(neighbors[:next]) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 324e2696e..c7f116dbd 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -140,19 +140,37 @@ class PostTest < ActiveSupport::TestCase end 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 - should "be unapproved once and only once" do + should "be flagged" do 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_not_nil(post.unapproval, "Post should have an unapproval record.") - assert_equal("bad", post.unapproval.reason) - assert_raise(Unapproval::Error) {post.unapprove!("bad")} + assert_equal(1, post.flags.count) end - should "not unapprove if no reason is given" do + should "not be flagged if no reason is given" do 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 @@ -167,7 +185,7 @@ class PostTest < ActiveSupport::TestCase should "not allow person X to reapprove that post" do user = Factory.create(:janitor_user, :name => "xxx") post = Factory.create(:post, :approver_string => "approver:xxx") - post.unapprove!("bad") + post.flag!("bad") CurrentUser.scoped(user, "127.0.0.1") do assert_raises(Post::ApprovalError) do post.approve! @@ -179,20 +197,13 @@ class PostTest < ActiveSupport::TestCase context "that has been reapproved" do should "no longer be flagged or pending" do post = Factory.create(:post) - post.unapprove!("bad") + post.flag!("bad") post.approve! assert(post.errors.empty?, post.errors.full_messages.join(", ")) post.reload assert_equal(false, post.is_flagged?) assert_equal(false, post.is_pending?) 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