From 3ee7f0770f036fc5a51d082e41256313c4101f62 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 00:44:22 -0600 Subject: [PATCH 1/6] Fix posts controller api test. 1) Failure: PostsControllerTest#test_: The posts controller for api calls passing the api limit should work. [/home/danbooru/src/danbooru/test/functional/posts_controller_test.rb:34]: Expected response to be a <429>, but was <200>. Expected: 429 Actual: 200 --- test/functional/posts_controller_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index fb0995f59..51ac1445f 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -22,6 +22,7 @@ class PostsControllerTest < ActionController::TestCase @post = FactoryGirl.create(:post) @bucket = TokenBucket.create(user_id: @user.id, token_count: 5, last_touched_at: Time.now) User.any_instance.stubs(:api_burst_limit).returns(5) + User.any_instance.stubs(:api_regen_multiplier).returns(0) end should "work" do @@ -30,7 +31,7 @@ class PostsControllerTest < ActionController::TestCase assert_response :success end - post :update, {:format => "json", :id => @post.id, :post => {:rating => "q"}, :login => @user.name, :api_key => @user.api_key.key} + post :update, {:format => "json", :id => @post.id, :post => {:rating => "q"}, :login => @user.name, :api_key => @user.api_key.key} assert_response 429 end end From 72502dbe2f8f33fb31549ec2ed5a81dcb0610408 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 01:19:03 -0600 Subject: [PATCH 2/6] Fix comment voting tests. 2) Error: CommentTest#test_: A comment created by an unlimited user should not allow duplicate votes. : ActiveRecord::RecordInvalid: Validation failed: You have already voted for this comment app/models/comment.rb:142:in `vote!' test/unit/comment_test.rb:164:in `block (3 levels) in ' 3) Error: CommentTest#test_: A comment created by an unlimited user should not allow upvotes by the creator. : ActiveRecord::RecordInvalid: Validation failed: You cannot upvote your own comments app/models/comment.rb:142:in `vote!' test/unit/comment_test.rb:179:in `block (3 levels) in ' --- test/unit/comment_test.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index b133a1cdc..b62f2fb5e 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -159,16 +159,15 @@ class CommentTest < ActiveSupport::TestCase user = FactoryGirl.create(:user) post = FactoryGirl.create(:post) c1 = FactoryGirl.create(:comment, :post => post) - comment_vote = c1.vote!("down") - assert_equal([], comment_vote.errors.full_messages) - comment_vote = c1.vote!("down") - assert_equal(["You have already voted for this comment"], comment_vote.errors.full_messages) + + assert_nothing_raised { c1.vote!("down") } + exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("down") } + assert_equal("Validation failed: You have already voted for this comment", exception.message) assert_equal(1, CommentVote.count) assert_equal(-1, CommentVote.last.score) c2 = FactoryGirl.create(:comment, :post => post) - comment_vote = c2.vote!("down") - assert_equal([], comment_vote.errors.full_messages) + assert_nothing_raised { c2.vote!("down") } assert_equal(2, CommentVote.count) end @@ -176,9 +175,9 @@ class CommentTest < ActiveSupport::TestCase user = FactoryGirl.create(:user) post = FactoryGirl.create(:post) c1 = FactoryGirl.create(:comment, :post => post) - comment_vote = c1.vote!("up") - assert_equal(["You cannot upvote your own comments"], comment_vote.errors.full_messages) + exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("up") } + assert_equal("Validation failed: You cannot upvote your own comments", exception.message) end should "allow undoing of votes" do From ace7d0c12d906094b83fba1c74abf899c3db03e5 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 01:28:10 -0600 Subject: [PATCH 3/6] Fix moving saved searches tests. 4) Failure: TagAliasTest#test_: A tag alias should move saved searches. [/home/danbooru/src/danbooru/test/unit/tag_alias_test.rb:80]: Expected: "123 bbb 456" Actual: "123 ... 456" 36) Failure: Moderator::TagBatchChangeTest#test_: a tag batch change should move saved searches. [/home/danbooru/src/danbooru/test/unit/moderator/tag_batch_change_test.rb:40]: Expected: "123 456 bbb" Actual: "123 ... 456" --- test/helpers/saved_search_test_helper.rb | 3 +++ test/unit/moderator/tag_batch_change_test.rb | 2 -- test/unit/tag_alias_test.rb | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/helpers/saved_search_test_helper.rb b/test/helpers/saved_search_test_helper.rb index 569d0e7d3..2b2a9071b 100644 --- a/test/helpers/saved_search_test_helper.rb +++ b/test/helpers/saved_search_test_helper.rb @@ -16,5 +16,8 @@ module SavedSearchTestHelper service = mock_sqs_service.new SavedSearch.stubs(:sqs_service).returns(service) + Danbooru.config.stubs(:aws_sqs_saved_search_url).returns("http://localhost:3002") + Danbooru.config.stubs(:listbooru_auth_key).returns("blahblahblah") + Danbooru.config.stubs(:listbooru_server).returns("http://localhost:3001") end end diff --git a/test/unit/moderator/tag_batch_change_test.rb b/test/unit/moderator/tag_batch_change_test.rb index 80641501f..436c5602e 100644 --- a/test/unit/moderator/tag_batch_change_test.rb +++ b/test/unit/moderator/tag_batch_change_test.rb @@ -8,8 +8,6 @@ module Moderator def setup super mock_saved_search_service! - Danbooru.config.stubs(:listbooru_auth_key).returns("blahblahblah") - Danbooru.config.stubs(:listbooru_server).returns("http://localhost:3001") end context "a tag batch change" do diff --git a/test/unit/tag_alias_test.rb b/test/unit/tag_alias_test.rb index a8ff2abf4..8b5322718 100644 --- a/test/unit/tag_alias_test.rb +++ b/test/unit/tag_alias_test.rb @@ -1,6 +1,9 @@ require 'test_helper' +require 'helpers/saved_search_test_helper' class TagAliasTest < ActiveSupport::TestCase + include SavedSearchTestHelper + context "A tag alias" do setup do Timecop.travel(1.month.ago) do @@ -10,6 +13,7 @@ class TagAliasTest < ActiveSupport::TestCase CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all Delayed::Worker.delay_jobs = false + mock_saved_search_service! end teardown do From 27817cffcfd988ac9cb2f6d64d56d8f4ec4cbf9f Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 02:19:20 -0600 Subject: [PATCH 4/6] Fix saved search test. 16) Failure: SavedSearchTest#test_: Fetching the post ids for a search with a name should return a list of ids. [/home/danbooru/src/danbooru/test/unit/saved_search_test.rb:31]: Expected: [1, 2, 3, 4] Actual: [] --- test/unit/saved_search_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unit/saved_search_test.rb b/test/unit/saved_search_test.rb index 0c5f33482..826466d86 100644 --- a/test/unit/saved_search_test.rb +++ b/test/unit/saved_search_test.rb @@ -8,8 +8,6 @@ class SavedSearchTest < ActiveSupport::TestCase def setup super mock_saved_search_service! - Danbooru.config.stubs(:listbooru_auth_key).returns("blahblahblah") - Danbooru.config.stubs(:listbooru_server).returns("http://localhost:3001") end context "Fetching the post ids for a search" do @@ -34,7 +32,7 @@ class SavedSearchTest < ActiveSupport::TestCase context "without a name" do setup do - FakeWeb.register_uri(:get, "http://localhost:3001/users?key=blahblahblah&user_id=1&name", :body => [1,2,3,4].to_json) + FakeWeb.register_uri(:get, "http://localhost:3001/users?key=blahblahblah&user_id=1", :body => [1,2,3,4].to_json) end should "return a list of ids" do From e98e7f1ea7bf3600175834ca0a8f8bb01a9e38a6 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 01:49:30 -0600 Subject: [PATCH 5/6] Fix note_update_count increment test. 5) Failure: NoteTest#test_: In all cases updating a note should increment the updater's note_update_count. [/home/danbooru/src/danbooru/test/unit/note_test.rb:113]: "CurrentUser.note_update_count" didn't change by 1. Expected: 1 Actual: 0 --- app/models/note.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/note.rb b/app/models/note.rb index d6d6e15c4..54468aa40 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -148,6 +148,7 @@ class Note < ActiveRecord::Base def create_version User.where(id: CurrentUser.id).update_all("note_update_count = note_update_count + 1") + CurrentUser.reload if merge_version? merge_version From a3278540175d52ae0a893ba9ddca3235b92f4727 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Feb 2017 01:56:11 -0600 Subject: [PATCH 6/6] Fix post_update_count increment test. 7) Failure: PostTest#test_: Tagging: A post that has been updated should increment the updater's post_update_count. [/home/danbooru/src/danbooru/test/unit/post_test.rb:1010]: "CurrentUser.post_update_count" didn't change by 1. Expected: 1 Actual: 3 --- app/models/post.rb | 2 ++ test/unit/post_test.rb | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 45f20ee49..1b9bda9cd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1436,6 +1436,8 @@ class Post < ActiveRecord::Base def create_new_version User.where(id: CurrentUser.id).update_all("post_update_count = post_update_count + 1") + CurrentUser.reload + versions.create( :rating => rating, :source => source, diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 85442dc84..354b2d333 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -1,8 +1,10 @@ require 'test_helper' require 'helpers/pool_archive_test_helper' +require 'helpers/saved_search_test_helper' class PostTest < ActiveSupport::TestCase include PoolArchiveTestHelper + include SavedSearchTestHelper setup do Timecop.travel(2.weeks.ago) do @@ -12,6 +14,7 @@ class PostTest < ActiveSupport::TestCase CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all Delayed::Worker.delay_jobs = false + mock_saved_search_service! end teardown do @@ -767,7 +770,7 @@ class PostTest < ActiveSupport::TestCase context "of" do setup do - @builder = FactoryGirl.build(:builder_user) + @builder = FactoryGirl.create(:builder_user) end context "locked:notes" do @@ -822,7 +825,7 @@ class PostTest < ActiveSupport::TestCase context "by an admin" do should "lock/unlock the status" do - CurrentUser.scoped(FactoryGirl.build(:admin_user)) do + CurrentUser.scoped(FactoryGirl.create(:admin_user)) do @post.update(:tag_string => "locked:status") assert_equal(true, @post.is_status_locked) @@ -836,7 +839,7 @@ class PostTest < ActiveSupport::TestCase context "of" do setup do - @gold = FactoryGirl.build(:gold_user) + @gold = FactoryGirl.create(:gold_user) end context "upvote:self or downvote:self" do